Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add WooCommerce demo blueprint with custom flat rate shipping and pro… #62

Open
wants to merge 4 commits into
base: trunk
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 52 additions & 0 deletions blueprints/woo-shipping/blueprint.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
{
"$schema": "https://playground.wordpress.net/blueprint-schema.json",
"meta": {
"title": "Minimal WooCommerce Setup with Sample Products, Shipping, and Payment Method",
"description": "To create a WordPress Playground instance that installs WooCommerce, adds a custom flat rate shipping method via a plugin, imports WooCommerce sample products XML to demonstrate the shipping method on the cart/checkout pages, and enables the Direct Bank Transfer payment method.",
"author": "calvinrodrigues500",
"categories": [
"woocommerce",
"shipping",
"flat_rate"
]
},
"steps": [
{
"step": "setSiteOptions",
"options": {
"blogName": "Woo Shipping Method"
}
},
{
"step": "installPlugin",
"pluginZipFile": {
"resource": "wordpress.org/plugins",
"slug": "woocommerce"
}
},
{
"step": "importWxr",
"file": {
"resource": "url",
"url": "https://github.com/woocommerce/woocommerce/blob/trunk/plugins/woocommerce/sample-data/sample_products.xml"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's include this file in this PR, the idea is to avoid referencing external resources. See https://github.com/WordPress/blueprints/blob/trunk/CONTRIBUTING.md

}
},
{
"step": "mkdir",
"path": "/wordpress/wp-content/plugins/woo-shipping-method"
},
{
"step": "writeFile",
"path": "/wordpress/wp-content/plugins/woo-shipping-method/woo-shipping-method.php",
"data": {
"resource": "url",
"url": "https://raw.githubusercontent.com/calvinrodrigues500/blueprints/woo-shipping/blueprints/woo-shipping/woo-shipping-method/woo-shipping-method.php"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's include this file in this PR, the idea is to avoid referencing external resources. See https://github.com/WordPress/blueprints/blob/trunk/CONTRIBUTING.md

}
},
{
"step": "activatePlugin",
"pluginName": "woo-shipping-method",
"pluginPath": "woo-shipping-method/woo-shipping-method.php"
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
<?php

/**
* Plugin Name: Woo Shipping Method
* Plugin URI: https://calvinrodrigues.in
* Description: Creates a Flat Rate Shipping Method & enables Direct Bank Transfer payment gateway.
* Version: 1.0.0
* Author: Calvin Rodrigues
* Author URI: https://calvinrodrigues.in
* Text Domain: woo-shipping-method
*/

/**
* Add Flat Rate Shipping Method.
*/
function add_flat_rate_shipping_method() {

$zone = new WC_Shipping_Zone(0);

$shipping_methods = $zone->get_shipping_methods();
$method_exists = false;

foreach ($shipping_methods as $method) {
if ('flat_rate' == $method->id) {
$method_exists = true;
break;
}
}

if ($method_exists) {
return;
}

$instance_id = $zone->add_shipping_method('flat_rate');

if (!$instance_id) {
return;
}

$settings = array(
'title' => __('My Custom Flat Rate', 'woo-shippinqg-method'),
'cost' => 10,
'tax_status' => 'none',
);

update_option('woocommerce_flat_rate_' . $instance_id . '_settings', $settings);
}

add_action('init', 'add_flat_rate_shipping_method');

/**
* Enable Direct Bank Transfer Payment Gateway.
*/
function enable_bacs_payment_gateway() {

if (!class_exists('WC_Payment_Gateway')) {
return;
}

$bacs_settings = get_option('woocommerce_bacs_settings', array());

if (!isset($bacs_settings['enabled']) || 'yes' !== $bacs_settings['enabled']) {
$bacs_settings['enabled'] = 'yes';
update_option('woocommerce_bacs_settings', $bacs_settings);
}
}

add_action('woocommerce_init', 'enable_bacs_payment_gateway');
Loading