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 2 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": "WooCommerce Custom Flat Rate Shipping Demo",
calvinrodrigues500 marked this conversation as resolved.
Show resolved Hide resolved
"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",
"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"
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"
}
]
}
165 changes: 165 additions & 0 deletions blueprints/woo-shipping/woo-product.wxr
Original file line number Diff line number Diff line change
@@ -0,0 +1,165 @@
<?xml version="1.0" encoding="UTF-8" ?>
Copy link
Contributor

Choose a reason for hiding this comment

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

Would the default WooCommerce product import be a better fit for this?

It has more products with all standard types (simple, variable) and would make testing of WooCommerce easier.

Copy link
Contributor

Choose a reason for hiding this comment

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

@calvinrodrigues500 what do you think about using the default WooCommerce product import here?

<!-- This is a WordPress eXtended RSS file generated by WordPress as an export of your site. -->
<!-- It contains information about your site's posts, pages, comments, categories, and other content. -->
<!-- You may use this file to transfer that content from one site to another. -->
<!-- This file is not intended to serve as a complete backup of your site. -->

<!-- To import this information into a WordPress site follow these steps: -->
<!-- 1. Log in to that site as an administrator. -->
<!-- 2. Go to Tools: Import in the WordPress admin panel. -->
<!-- 3. Install the "WordPress" importer from the list. -->
<!-- 4. Activate & Run Importer. -->
<!-- 5. Upload this file using the form provided on that page. -->
<!-- 6. You will first be asked to map the authors in this export file to users -->
<!-- on the site. For each author, you may choose to map to an -->
<!-- existing user on the site or to create a new user. -->
<!-- 7. WordPress will then import each of the posts, pages, comments, categories, etc. -->
<!-- contained in this file into your site. -->

<!-- generator="WordPress/6.6" created="2024-08-05 18:06" -->
<rss version="2.0"
xmlns:excerpt="http://wordpress.org/export/1.2/excerpt/"
xmlns:content="http://purl.org/rss/1.0/modules/content/"
xmlns:wfw="http://wellformedweb.org/CommentAPI/"
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:wp="http://wordpress.org/export/1.2/">

<channel>
<title>Woo Demo</title>
<link>http://wpone.com</link>
<description></description>
<pubDate>Mon, 05 Aug 2024 18:06:39 +0000</pubDate>
<language>en-US</language>
<wp:wxr_version>1.2</wp:wxr_version>
<wp:base_site_url>http://wpone.com</wp:base_site_url>
<wp:base_blog_url>http://wpone.com</wp:base_blog_url>

<wp:author>
<wp:author_id>1</wp:author_id>
<wp:author_login><![CDATA[admin]]></wp:author_login>
<wp:author_email><![CDATA[admin@wp]]></wp:author_email>
<wp:author_display_name><![CDATA[admin]]></wp:author_display_name>
<wp:author_first_name><![CDATA[]]></wp:author_first_name>
<wp:author_last_name><![CDATA[]]></wp:author_last_name>
</wp:author>


<generator>https://wordpress.org/?v=6.6</generator>

<item>
<title><![CDATA[Test Product]]></title>
<link>http://wpone.com/product/test-product/</link>
<pubDate>Mon, 05 Aug 2024 18:06:13 +0000</pubDate>
<dc:creator><![CDATA[admin]]></dc:creator>
<guid isPermaLink="false">http://wpone.com/?post_type=product&#038;p=45</guid>
<description></description>
<content:encoded><![CDATA[]]></content:encoded>
<excerpt:encoded><![CDATA[]]></excerpt:encoded>
<wp:post_id>45</wp:post_id>
<wp:post_date><![CDATA[2024-08-05 18:06:13]]></wp:post_date>
<wp:post_date_gmt><![CDATA[2024-08-05 18:06:13]]></wp:post_date_gmt>
<wp:post_modified><![CDATA[2024-08-05 18:06:13]]></wp:post_modified>
<wp:post_modified_gmt><![CDATA[2024-08-05 18:06:13]]></wp:post_modified_gmt>
<wp:comment_status><![CDATA[open]]></wp:comment_status>
<wp:ping_status><![CDATA[closed]]></wp:ping_status>
<wp:post_name><![CDATA[test-product]]></wp:post_name>
<wp:status><![CDATA[publish]]></wp:status>
<wp:post_parent>0</wp:post_parent>
<wp:menu_order>0</wp:menu_order>
<wp:post_type><![CDATA[product]]></wp:post_type>
<wp:post_password><![CDATA[]]></wp:post_password>
<wp:is_sticky>0</wp:is_sticky>
<category domain="product_type" nicename="simple"><![CDATA[simple]]></category>
<category domain="product_cat" nicename="uncategorized"><![CDATA[Uncategorized]]></category>
<wp:postmeta>
<wp:meta_key><![CDATA[_edit_last]]></wp:meta_key>
<wp:meta_value><![CDATA[1]]></wp:meta_value>
</wp:postmeta>
<wp:postmeta>
<wp:meta_key><![CDATA[_regular_price]]></wp:meta_key>
<wp:meta_value><![CDATA[50]]></wp:meta_value>
</wp:postmeta>
<wp:postmeta>
<wp:meta_key><![CDATA[total_sales]]></wp:meta_key>
<wp:meta_value><![CDATA[0]]></wp:meta_value>
</wp:postmeta>
<wp:postmeta>
<wp:meta_key><![CDATA[_tax_status]]></wp:meta_key>
<wp:meta_value><![CDATA[taxable]]></wp:meta_value>
</wp:postmeta>
<wp:postmeta>
<wp:meta_key><![CDATA[_tax_class]]></wp:meta_key>
<wp:meta_value><![CDATA[]]></wp:meta_value>
</wp:postmeta>
<wp:postmeta>
<wp:meta_key><![CDATA[_manage_stock]]></wp:meta_key>
<wp:meta_value><![CDATA[no]]></wp:meta_value>
</wp:postmeta>
<wp:postmeta>
<wp:meta_key><![CDATA[_backorders]]></wp:meta_key>
<wp:meta_value><![CDATA[no]]></wp:meta_value>
</wp:postmeta>
<wp:postmeta>
<wp:meta_key><![CDATA[_sold_individually]]></wp:meta_key>
<wp:meta_value><![CDATA[no]]></wp:meta_value>
</wp:postmeta>
<wp:postmeta>
<wp:meta_key><![CDATA[_weight]]></wp:meta_key>
<wp:meta_value><![CDATA[5]]></wp:meta_value>
</wp:postmeta>
<wp:postmeta>
<wp:meta_key><![CDATA[_length]]></wp:meta_key>
<wp:meta_value><![CDATA[2]]></wp:meta_value>
</wp:postmeta>
<wp:postmeta>
<wp:meta_key><![CDATA[_width]]></wp:meta_key>
<wp:meta_value><![CDATA[2]]></wp:meta_value>
</wp:postmeta>
<wp:postmeta>
<wp:meta_key><![CDATA[_height]]></wp:meta_key>
<wp:meta_value><![CDATA[2]]></wp:meta_value>
</wp:postmeta>
<wp:postmeta>
<wp:meta_key><![CDATA[_virtual]]></wp:meta_key>
<wp:meta_value><![CDATA[no]]></wp:meta_value>
</wp:postmeta>
<wp:postmeta>
<wp:meta_key><![CDATA[_downloadable]]></wp:meta_key>
<wp:meta_value><![CDATA[no]]></wp:meta_value>
</wp:postmeta>
<wp:postmeta>
<wp:meta_key><![CDATA[_download_limit]]></wp:meta_key>
<wp:meta_value><![CDATA[-1]]></wp:meta_value>
</wp:postmeta>
<wp:postmeta>
<wp:meta_key><![CDATA[_download_expiry]]></wp:meta_key>
<wp:meta_value><![CDATA[-1]]></wp:meta_value>
</wp:postmeta>
<wp:postmeta>
<wp:meta_key><![CDATA[_stock]]></wp:meta_key>
<wp:meta_value><![CDATA[]]></wp:meta_value>
</wp:postmeta>
<wp:postmeta>
<wp:meta_key><![CDATA[_stock_status]]></wp:meta_key>
<wp:meta_value><![CDATA[instock]]></wp:meta_value>
</wp:postmeta>
<wp:postmeta>
<wp:meta_key><![CDATA[_wc_average_rating]]></wp:meta_key>
<wp:meta_value><![CDATA[0]]></wp:meta_value>
</wp:postmeta>
<wp:postmeta>
<wp:meta_key><![CDATA[_wc_review_count]]></wp:meta_key>
<wp:meta_value><![CDATA[0]]></wp:meta_value>
</wp:postmeta>
<wp:postmeta>
<wp:meta_key><![CDATA[_product_version]]></wp:meta_key>
<wp:meta_value><![CDATA[9.0.2]]></wp:meta_value>
</wp:postmeta>
<wp:postmeta>
<wp:meta_key><![CDATA[_price]]></wp:meta_key>
<wp:meta_value><![CDATA[50]]></wp:meta_value>
</wp:postmeta>
</item>
</channel>
</rss>

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