From 9c31d597c8b7f13dc4017297bb9db06ff797e47e Mon Sep 17 00:00:00 2001 From: calvinrodrigues500 Date: Tue, 6 Aug 2024 23:50:57 +0530 Subject: [PATCH 1/4] Add WooCommerce demo blueprint with custom flat rate shipping and product import --- blueprints/woo-shipping/blueprint.json | 52 ++++++ blueprints/woo-shipping/woo-product.wxr | 165 ++++++++++++++++++ .../woo-shipping-method.php | 46 +++++ 3 files changed, 263 insertions(+) create mode 100644 blueprints/woo-shipping/blueprint.json create mode 100644 blueprints/woo-shipping/woo-product.wxr create mode 100644 blueprints/woo-shipping/woo-shipping-method/woo-shipping-method.php diff --git a/blueprints/woo-shipping/blueprint.json b/blueprints/woo-shipping/blueprint.json new file mode 100644 index 0000000..0b695cc --- /dev/null +++ b/blueprints/woo-shipping/blueprint.json @@ -0,0 +1,52 @@ +{ + "$schema": "https://playground.wordpress.net/blueprint-schema.json", + "meta": { + "title": "WooCommerce Custom Flat Rate Shipping Demo", + "description": "A WordPress Playground instance that installs WooCommerce, adds a custom flat rate shipping method via a plugin, and imports a product to demonstrate the shipping method on the cart/checkout pages.", + "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://raw.githubusercontent.com/calvinrodrigues500/blueprints/woo-shipping/blueprints/woo-shipping/woo-product.wxr" + } + }, + { + "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" + } + }, + { + "step": "activatePlugin", + "pluginName": "woo-shipping-method", + "pluginPath": "woo-shipping-method/woo-shipping-method.php" + } + ] +} \ No newline at end of file diff --git a/blueprints/woo-shipping/woo-product.wxr b/blueprints/woo-shipping/woo-product.wxr new file mode 100644 index 0000000..4c20bfa --- /dev/null +++ b/blueprints/woo-shipping/woo-product.wxr @@ -0,0 +1,165 @@ + + + + + + + + + + + + + + + + + + + + + + + Woo Demo + http://wpone.com + + Mon, 05 Aug 2024 18:06:39 +0000 + en-US + 1.2 + http://wpone.com + http://wpone.com + + + 1 + + + + + + + + + https://wordpress.org/?v=6.6 + + + <![CDATA[Test Product]]> + http://wpone.com/product/test-product/ + Mon, 05 Aug 2024 18:06:13 +0000 + + http://wpone.com/?post_type=product&p=45 + + + + 45 + + + + + + + + + 0 + 0 + + + 0 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/blueprints/woo-shipping/woo-shipping-method/woo-shipping-method.php b/blueprints/woo-shipping/woo-shipping-method/woo-shipping-method.php new file mode 100644 index 0000000..9cd7293 --- /dev/null +++ b/blueprints/woo-shipping/woo-shipping-method/woo-shipping-method.php @@ -0,0 +1,46 @@ +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'); From c930c925a53235c53bee235ce6c225b76d07f0c1 Mon Sep 17 00:00:00 2001 From: calvinrodrigues500 Date: Thu, 8 Aug 2024 08:32:55 +0530 Subject: [PATCH 2/4] Update Enable Direct Bank Transfer payment gateway --- blueprints/woo-shipping/blueprint.json | 2 +- .../woo-shipping-method.php | 24 ++++++++++++++++++- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/blueprints/woo-shipping/blueprint.json b/blueprints/woo-shipping/blueprint.json index 0b695cc..a6cc76a 100644 --- a/blueprints/woo-shipping/blueprint.json +++ b/blueprints/woo-shipping/blueprint.json @@ -2,7 +2,7 @@ "$schema": "https://playground.wordpress.net/blueprint-schema.json", "meta": { "title": "WooCommerce Custom Flat Rate Shipping Demo", - "description": "A WordPress Playground instance that installs WooCommerce, adds a custom flat rate shipping method via a plugin, and imports a product to demonstrate the shipping method on the cart/checkout pages.", + "description": "To create a WordPress Playground instance that installs WooCommerce, adds a custom flat rate shipping method via a plugin, imports a product to demonstrate the shipping method on the cart/checkout pages, and enables the Direct Bank Transfer payment method.", "author": "calvinrodrigues500", "categories": [ "woocommerce", diff --git a/blueprints/woo-shipping/woo-shipping-method/woo-shipping-method.php b/blueprints/woo-shipping/woo-shipping-method/woo-shipping-method.php index 9cd7293..723de2c 100644 --- a/blueprints/woo-shipping/woo-shipping-method/woo-shipping-method.php +++ b/blueprints/woo-shipping/woo-shipping-method/woo-shipping-method.php @@ -3,13 +3,16 @@ /** * Plugin Name: Woo Shipping Method * Plugin URI: https://calvinrodrigues.in - * Description: Creates a Flat Rate Shipping Method + * 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); @@ -44,3 +47,22 @@ function add_flat_rate_shipping_method() { } 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'); From 54b253478c185790d8ca6ce8eca8f88cb9b108b3 Mon Sep 17 00:00:00 2001 From: Calvin Rodrigues Date: Fri, 9 Aug 2024 00:10:08 +0530 Subject: [PATCH 3/4] Update Blueprint meta title Co-authored-by: Bero --- blueprints/woo-shipping/blueprint.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/blueprints/woo-shipping/blueprint.json b/blueprints/woo-shipping/blueprint.json index a6cc76a..e91f8e3 100644 --- a/blueprints/woo-shipping/blueprint.json +++ b/blueprints/woo-shipping/blueprint.json @@ -1,7 +1,7 @@ { "$schema": "https://playground.wordpress.net/blueprint-schema.json", "meta": { - "title": "WooCommerce Custom Flat Rate Shipping Demo", + "title": "WooCommerce with shipping and payment methods", "description": "To create a WordPress Playground instance that installs WooCommerce, adds a custom flat rate shipping method via a plugin, imports a product to demonstrate the shipping method on the cart/checkout pages, and enables the Direct Bank Transfer payment method.", "author": "calvinrodrigues500", "categories": [ From c302e5fdacadd2b356094b4bb07e274de95600bd Mon Sep 17 00:00:00 2001 From: calvinrodrigues500 Date: Sun, 11 Aug 2024 11:05:03 +0530 Subject: [PATCH 4/4] Update Switch to WooCommerce sample products XML for import --- blueprints/woo-shipping/blueprint.json | 6 +- blueprints/woo-shipping/woo-product.wxr | 165 ------------------------ 2 files changed, 3 insertions(+), 168 deletions(-) delete mode 100644 blueprints/woo-shipping/woo-product.wxr diff --git a/blueprints/woo-shipping/blueprint.json b/blueprints/woo-shipping/blueprint.json index e91f8e3..ba47a6f 100644 --- a/blueprints/woo-shipping/blueprint.json +++ b/blueprints/woo-shipping/blueprint.json @@ -1,8 +1,8 @@ { "$schema": "https://playground.wordpress.net/blueprint-schema.json", "meta": { - "title": "WooCommerce with shipping and payment methods", - "description": "To create a WordPress Playground instance that installs WooCommerce, adds a custom flat rate shipping method via a plugin, imports a product to demonstrate the shipping method on the cart/checkout pages, and enables the Direct Bank Transfer payment method.", + "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", @@ -28,7 +28,7 @@ "step": "importWxr", "file": { "resource": "url", - "url": "https://raw.githubusercontent.com/calvinrodrigues500/blueprints/woo-shipping/blueprints/woo-shipping/woo-product.wxr" + "url": "https://github.com/woocommerce/woocommerce/blob/trunk/plugins/woocommerce/sample-data/sample_products.xml" } }, { diff --git a/blueprints/woo-shipping/woo-product.wxr b/blueprints/woo-shipping/woo-product.wxr deleted file mode 100644 index 4c20bfa..0000000 --- a/blueprints/woo-shipping/woo-product.wxr +++ /dev/null @@ -1,165 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - Woo Demo - http://wpone.com - - Mon, 05 Aug 2024 18:06:39 +0000 - en-US - 1.2 - http://wpone.com - http://wpone.com - - - 1 - - - - - - - - - https://wordpress.org/?v=6.6 - - - <![CDATA[Test Product]]> - http://wpone.com/product/test-product/ - Mon, 05 Aug 2024 18:06:13 +0000 - - http://wpone.com/?post_type=product&p=45 - - - - 45 - - - - - - - - - 0 - 0 - - - 0 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file