Webinane Commerce – a top-end, open source, developer-friendly eCommerce plugin for WordPress – contains the following key features and functionalities, which you can use for themes, plugins, extensions, and add-ons.
With this core function, you can retrieve an instance of Arrayy\Arrayy which has a list of countries with the following information.
You can get the data using:
$countries->get(‘languages.nld’);
The above code will return the languages array of that country.
"ABW": {
"abbrev": "Aruba",
"abbrev_len": "5",
"adm0_a3": "ABW",
"adm0_a3_is": "ABW",
"adm0_a3_un": "-99",
"adm0_a3_us": "ABW",
…
ry"
}
Webinane_currencies returns an associative array of ISO code as key and multi-dimensional array of currency data.
Webinane_currencies()
It returns an instance of Arrayy\Arrayy.
webinane_array($data=array())
It accepts one parameter of the file path relative to the plugin directory, and returns an instance of Arrayy\Arrayy after reading json file if the path is found.
webinane_json($file)
Webinane_set is used to find a specific key from an object or an array. The function accepts three parameters, where the third parameter is optional. The first parameter should be either an array or an object. And the second parameter should be a string, which we need to find the index from the given array or object.
Webinane_set($var, $key, $default = null)
wpcm_currency_assos_data function returns an associative array of currency ISO code as a key and the name of currency with symbol.
Wpcm_currency_assos_data()
This function is used to retrieve an associative array of specific post data. It returns post ID as key and post title as value.
Wpcm_posts_data($args)
Use this function to retrieve the data of registered sidebars.
wpcm_sidebar_data()
With this function, you can add an item to cart.
$args – array : (required) – An array with item_id, price, and quantity. The item ID is actually the product ID.
wpcm_add_to_cart($args=array())
Use it to retrieve the content of the user cart. It returns an array with items in cart, user profile data, and subtotal of the cart.
wpcm_get_cart_content()
This function is used to retrieve the list of active payment gateways. It returns an array with gateway_id as key and gateway class object as value.
wpcm_get_active_gateways()
With this function, you can retrieve the settings. It returns either an associative array of settings data or an instance of Arrayy\Arrayy.
$collect – boolean : (optional) – If true, it will return an instance of Arrayy\Arrayy. If false, it’ll return an associative array.
$set_def – boolean : (optional) – If true, it will automatically set the default values in case the values are not saved in the database.
wpcm_get_settings($collect=true, $set_def=false)
It returns either true or false. This function is used to check whether the current page is a checkout page, which we set from the display settings.
wpcm_is_checkout_page()
This function is used to retrieve the URL of the Order Success page, which we set from the display settings.
$args – array : (required) – An associative array to add Query args to the URL.
wpcm_get_success_page_url($args)
You can hook up this function when checkout form is finally submitted.
$gateway – string : (required) – An ID of the gateway
$payment_data – array : (required) – An array of items, user profile data, and cart hash.
wpcm_send_to_gateway($gateway, $payment_data)
This function is used to redirect the user back to Checkout page if the page is set from the settings.
wpcm_redirect_back_checkout()
You can use this Webinane Commerce function to delete/remove all data (items) from the user cart.
wpcm_empty_cart()
With this function, you can add a metabox to a specific post type.
$args – array : (required) – An array of metabox data.
webinane_commerce_set_metabox($args)
Use it to retrieve the formatted price. This function takes only integers by the parameters and attaches a currency symbol as per the settings.
$price – integers : (required) – Price of an item.
webinane_cm_price_with_symbol($price)
Using this function, you can get the symbol of the currency pre-set from the settings.
webinane_currency_symbol
It is used to load the template. It checks whether a specific template is available in child theme or a parent theme in a Webinane-commerce directory. If that template is not available in the theme, the template is loaded from the plugin.
$template – string : (required) – Relative path to Webinane-commerce directory.
$args – array : (optional) – An array of variables you want to pass on to the template.
Webinane_template($template, $args=array())
Here is the list of the classes in Webinane Commerce.
“WPCommerce” is the main class in Webinane Commerce. It controls the main functions of the plugin. It also stores all the variables and handles the success/error messages.
“WebinaneCommerce\Commerce” is the main class in Webinane Commerce. It controls the main functions of the plugin. It also stores all the variables and handles the success/error messages.
When constructed, the “WebinaneCommerce\Commerce” class loads the following classes.
Final class WebinaneCommerce\Commerce{}
It controls the admin settings of Webinane Commerce Plugin. It has a number of developer hooks to extend functionality and UI (user interface).
class WebinaneCommerce\Admin\Settings{}
“WebinaneCommerce\Checkout” class is used to handle checkout functionalities on frontend.
class WebinaneCommerce\Checkout{}.
With “WebinanceCommerce\Customers” class, you can store, update, retrieve or delete customer data.
class WebinaneCommerce\Customers{}
This class is used to register metaboxes for posts, pages, and custom post types. It provides a user interface for metaboxes and handles data storage and retrieval.
class WebinaneCommerce\Metaboxes{}
You can use this class to handle the functions like sign up, login, user profile, and purchase history, etc.
class WebinaneCommerce\My_Account{}
This Webinane Commerce class is used to register a custom post type, “Orders”, and to manager customer orders from the admin. It handles the creation, retrieval, updates, and deletion of orders.
class WebinaneCommerce\Orders{}
This class is used to register the required shortcodes and render their output.
class WebinaneCommerce\Shortcodes{}
”…\Session” class is used to handle the sections of user cart and various user data. It stores the current user’s data in database using the unique key.
class WebinaneCommerce\Common\Session{}
This class is being used to register all the required styles and scripts, so you can enqueue them by using their handlers.
class WebinaneCommerce\Common\Enqueue{}
Webinane Commerce comes with an offline gateway. If it is enabled from the settings, the users will be able to make payments offline.
class WebinaneCommerce\Gateways\Gateway_Offline_Payment{}
Webinane Commerce has a built-in PayPal Standard gateway. Though this API is outdated by PayPal, it is still available for use. Users are requested to use PayPal REST API as an updated payment tool.
You can purchase our extension “PayPal Pro” which has been built using the REST API.
class WebinaneCommerce\Gateways\Gateway_Paypal_Payment{}
Webinane Commerce Settings API comes with three basic tabs, i.e. General Settings, Payment Settings, and Display Settings. However, it gives you full freedom/flexibility to modify existing tabs/options or create new ones. Use the following code to create, show, and load tabs/options in the Webinane Commerce Settings API.
$
As an open-source, developer-friendly WordPress plugin, Webinane Commerce allows the developers to create extensions and add-ons to extend its potential and functionality. Several built-in developer hooks make the job far easier than it would be otherwise.
This guidebook lists the best practices for the developers to follow while creating extensions.
To begin with:
Before you start developing a plugin/extension, make sure Webinane Commerce plugin is installed and active.
Use the following format to check if Webinane Commerce is installed and active.
/*** Check if WP Commerce is active **/
if (class_exists(‘WPCommerce’)) {
// Put your plugin code here
}
As you start working on the plugin, create a directory to neatly organize the file. The directory name should be the name of the plugin .
Also make sure that the main plugin/extension file is named the same as the name of the plugin/extension. For example, if the plugin directory name is ‘plugin-name’, the main file should be named as ‘plugin-name.php’.
Just like the main plugin file, the text domain should be named after the directory name. For example, if the directory name is “plugin-name”, the text domain should be named as “plugin-name”. Also avoid using underscores.
A header comment should be included in the main PHP file of your Webinane Commerce plugin/extension. The header comment should tell that the given file is a plugin and give basic information about it.
This information includes the plugin/extension name, URI (a unique URL), short plugin description, author name, and author URI, etc. For details, you can visit WordPress Header Requirements page.
/**
* Plugin Name: Webinane Commerce
* Plugin URI: https://webinane.com/wp-commerce
* Description: WordPress plugin for eCommerce, payment gateways and online stores
* Author: Webinane
* Author URI: https://webinane.com
* Text Domain: wp-commerce
* Domain Path: /languages
* Version: 0.1.0
* License: GPLv2 or later
* License URI: https://www.gnu.org/licenses/gpl-2.0.html *
* @package Wp_Commerce */
It is an expensive and complex process to make changes to database. So, you should minimize the amount of customization you do to the database.
For example, instead of creating new custom tables, you can use the existing database tables. You should prefer using WordPress post types, taxonomies, and options over creating custom datable tables.
Post Types: There are lots of different WordPress post types such as posts, pages, attachments, revisions, custom CSS, and navigation menus, etc.
Taxonomies: If you need to sort a data entity into, for example, tags and categories, a ‘taxonomy’ can be helpful.
English is the default WordPress language, so all the strings within your plugin/extension code should be in this language. In the case, your plugin is intended for a non-English community, you will need to internationalize (localize) it.
Code the strings in your Webinane Commerce plugin in such a way that they can be easily translated into other languages. You should include relevant translation files for the given language/s in the plugin package.
Each WordPress based plugin/extension should be provided with a readme file. It should be created following the WordPress Readme file standards.
It may look like:
=== Plugin Name ===
Contributors: (this should be a list of wordpress.org userid's)
Tags: comments, spam
Requires at least: 4.0.1
Tested up to: 4.3
Requires PHP: 5.6
Stable tag: 4.3
License: GPLv3 or later License
URI: http://www.gnu.org/licenses/gpl-3.0.html
Use WordPress tools to generate and validate Readme file.
Making the code work is not enough on your part. You must make sure that your extension will protect users’ data in case of hacking. You can make the data safe by using WordPress plugin security standards.
The Webinane Commerce plugin/extension developers should allow the users to customize/modify the product without having to touch the core code base. A plugin can be made extendable by adding hooks.
“Actions” and “Filters” are the two types of . “Actions” allow the developers to add or change functionality while “Filters” allow changing the content.
Moreover, a templating mechanism should be in place for the plugins/extensions that involve a frontend output. It will allow the users to overwrite the template files of the plugin by creating custom template files in the extension specified folder of their theme.
It would be annoying for the users to scroll through or read the unused or commented-out code. It should be removed. You can add it later, if needed.
To make your plugin/extension easy for the users to modify, make all the functions in your code well commented.
In programming, the objects that know too much or do too much are called the God Objects. Such objects make it hard to fix bugs.
So, break down the massive functions into smaller pieces. An object should only know about itself and be able to solve its own problems.
You should find out and fix all the errors or warnings in your plugin functionality. Continue debugging until all the errors have been removed. You can read more about debugging in WordPress.
You should test and validate the coding of your Webinane Commerce plugin with standard tools, such as Theme Unit Test , Theme Check , and PHP Unit Automated Testing.
Using the WordPress Transients API , you can store data in the WordPress database for a certain period. It will lessen the load on your server via an API and would be able to quickly handle any future queries.
You need to give your data a custom name and define a timeframe. After its expiry, the data will be automatically deleted.
Try to separate the presentation logic (how the plugin/extension looks) and the business logic (how it works) from each other. For example, you can use one class for the admin settings page and another for displaying the end results. It is easy to maintain and swap, if necessary, the two pieces of logic.
Preventing direct access data leakage is necessary. You can safeguard the data against its unauthorized transmission by using the following line of code at the top of each PHP file.
defined( 'ABSPATH' ) or die( 'No script kiddies please!' );
You can read more about ‘Security Note’ in the WordPress ‘Writing a Plugin’ guidelines.
Using this action, you can hook up a task for scheduling database upgradation. If some database upgradation is needed, this hook will run that task in the given time interval.
do_action(“webinane_commerce_run_database_upgrade”);
If you are developing an extension, you must use this hook in the ‘root’ file for loading any code. This will help in throwing any exception or a fatal error.
do_action(“webinane_commerce_loaded”);
This hook is fired when user finally submits a checkout form to process a specific payment gateway and for creating a new order.
do_action(“wpcm_process_checkout”);
This action hook immediately fires after the user submits Checkout form and before processing any checkout data.
do_action(“wpcm_pre_process_purchase”);
This action hook is used to validate user submitted data in Checkout form. It accepts two parameters – the first one is validated user data (which comes validated by Webinane Commerce) and the second one is the original data submitted by the user.
Parameters:
do_action(“wpcm_checkout_error_checks”, $valid_data, $_post);
This action hook fires when there is any validation error in Checkout form.
do_action(“wpcm_ajax_checkout_errors”);
Using this hook, developer can hook up a functionality midway between the payment gateway starts processing and delivers the final results.
It accepts three parameters:
do_action(“wpcm_checkout_before_gateway”, $_post, $user_info, $valid_data);
This action hook fires after a user saves a post containing our metabox.
It accepts three parameters:
do_action(“wpcommerce_metabox_after_save”, $post_id, $meta_key, $meta_data);
This action hook fires after a user saves a post containing our metabox, but it is for a specific post type.
It accepts three parameters:
do_action(“wpcommerce_metabox_after_save_{$post_type}”, $post_id, $meta_key, $meta_data);
This Webinane Commerce action hook fires after a user has successfully made the payment and a new ‘order’ has been created.
It accepts three parameters:
do_action(“wpcm_new_order_process”, $data, $payment_data, $id);
This action hook fires when a new order has been created and starts updating order data.
It accepts two parameters:
do_action(“wpcm_new_order_process_meta”, $data, $id);
This action hook fires after saving order items in ‘order_items’ database table.
It accepts two parameters:
do_action(“wpcm_new_order_after_new_order_items” , $data, $id);
This action hook fires when Admin edits the order and chooses some action. Currently, it has two actions – “new order notification” and “send invoice via email”.
When the action is “new order notification”, your hook will be “wpcommerce_order_action_notification”. And when the action is “invoice”, the hook will be “wpcommerce_order_action_email_invoice”.
It accepts two parameters:
do_action(“wpcommerce_order_action_{$order_action}”, $order, $customer_id);
This action hook fires after a user is redirected to the ‘Order Success’ page, containing some URL parameters. It only fires when order is successful.
It accepts two parameters:
do_action(“wpcm_order_successful_{$gateway}”, $order, $key);
This action hook fires after a user is redirected to the ‘Order Success’ page, containing some URL parameters. It only fires when it is an Instant Payment Notification (IPN).
do_action(“wpcommerce_order_action_notification”);
This action hook fires after a user is redirected to the ‘Order Success’ page, containing some URL parameters. It only fires when it is an Instant Payment Notification (IPN). But it is for a specific gateway.
do_action(“wpcm_order_webhooks_notification_{$gateway}”);
Developers can hook up when a checkout form is successfully processed and is finally sent to the (payment) gateway.
It accepts one parameter:
do_action(“wpcm_send_to_gateway_{$gateway}”, $payment_data);
This action hook is fired when upgradation process starts.
do_action(“webinane_commerce_do_db_upgrade”);
Developers can hook up their custom data to show on the Checkout page right after the order details.
do_action(“wpcm_checkout_order_detail”);
Developers can hook up their custom data to show on the checkout page right after the payment gateways.
do_action(“wpcm_checkout_page_gateways”);
Developers can hook up their custom data to show on the checkout page right before placing “Order” button.
do_action(“wpcm_checkout_form_button”);
Only developers developing gateways can use this action hook to add their custom content for users if they choose that specific gateway.
do_action(“webinane_checkout_payment_gateway_data”);
Extension developers can modify the fields of user’s account profile. It is basically an array of fields which, after having been constructed, gives a final (HTML) output in the form of a newly added field.
It accepts one parameter:
apply_filters(“webinane_frontend_my_account_profile”, $fields)
This filter allows the developers to modify the title of a tab “My Orders” in user’s account profile.
It accepts one parameter:
$title (string): The title of a tab.
apply_filters(“webinane_commerce_orders_title”, $title)
Developers can add, edit, or remove any field in General Settings section of the admin panel.It accepts one parameter:
apply_filters(“webinane_settings_general_settings”, $fields)
This filter allows the developers to add a new tab/s in Admin Payment Gateways Settings. This filter is useful in case the developers need to collect some API credentials.
It accepts one parameter:
apply_filters(“wpcommerce_payment_gateways_setting_tabs”, $tabs)
Using this filter, the developers can completely modify Webinane Settings array. It provides a complete data for “Settings”.
It accepts one parameter:
apply_filters(“wpcommerce_settings”, $settings)
Developers can hook up scheduled events regarding database upgradations or anything else.
It accepts one parameter:
apply_filters(“webinane_commerce_db_update_status”, $status)
This filter is used to add, edit, or remove gateway IDs to modify the output on ‘Checkout’ page.
It accepts one parameter:
apply_filters(“wpcm_gateways_names”, $IDs)
This filter is used to add or modify validation rules for Checkout Form.
It accepts one parameter:
apply_filters(“webinane_commerce_checkout_form_validation_rules”, $rules)
Developers can modify the title of dashboard ‘Stats’ widget in the Admin.
It accepts one parameter:
apply_filters(“wpcommerce_dashboard_widget_stats_title”, $title)
Developers can hook up their own custom email template which Webinane Commerce shots when an order is successfully received. This is specifically for the customer who places an order. So, the information given here should relate to the customer.
It accepts three parameters:
apply_filters(“wpcm_new_order_customer_email_template”, $template, $order, $customer_id)
This filter works when an order is successfully received, and an email is to be sent to the customer. Using it, you can change the subject of the email being sent to the customer.
It accepts one parameter:
apply_filters(“wpcm_new_order_customer_email_subject”, $subject)
Developers can hook up their own custom email template which Webinane Commerce shots when an order is successfully received. This is specifically for the store/shop owner who receives an order. So, the information given here should relate to the store/shop owner.
It accepts three parameters:
apply_filters(“wpcm_new_order_owner_email_template”, $template, $order, $customer_id)
This filter works when the store/shop owner edits an order and sends an invoice to the customer. The developers can modify the subject of the email using this filter.
It accepts two parameters:
apply_filters(“webinane_commerce_customer_invoice_email_subject”, $subject, $order)
This filter is used to set the custom store logo instead of using the global logo from theme. It is fired when you send a PDF invoice to the customers.
It accepts one parameter:
apply_filters(“webinane_commerce_store_logo”, $logo)
You can use this filter to modify existing metaboxes or add a new metabox. This filter provides metabox configuration array to modify the settings.
It accepts two parameters:
apply_filters(“webinane_commerce_register_metabox_{$id}”, $id, $config)
Developers can hook up a custom post type that Webinane Commerce would use to accept orders.
It accepts one parameter:
apply_filters(“wpcommerce_metabox_fields_supported_post_types”, $post_types)
This filter is used to change the metabox title for the orders in Admin.
It accepts one parameter:
apply_filters(“wpcommerce_admin_orders_metabox_title”, $title)
Developers can use this filter to modify labels and post type configuration like rewrite rules, support, or capability type.
It accepts one parameter:
apply_filters(“wpcm_post_type_orders_args”, $args)
This filter is used to modify the data for creating new order. It is fired when a user is submitting an order.
It accepts two parameters:
apply_filters(“wpcm_new_order_data”, $data, $payment_data)
This filter is used to change the list of active payment gateways.
It accepts one parameter:
apply_filters(“wpcommerce_payment_gateways”, $gateways)
This filter is used to change the “Sales” text of Admin Dashboard widget.
It accepts one parameter:
apply_filters(“wpcommerce_dashboard_stats_widget_sales_text”, $text)
This filter is used to change the “Pending” text of Admin Dashboard widget.
It accepts one parameter:
apply_filters(“wpcommerce_dashboard_stats_widget_pending_text”, $text)
This filter is used to change the “Hold” text of Admin Dashboard widget.
It accepts one parameter:
apply_filters(“wpcommerce_dashboard_stats_widget_hold_text”, $text)
Using this filter, the developers can change the “Add to Cart” button text programmatically.
It accepts one parameter:
apply_filters(“wpcm_checkout_form_button_text”, $text)
Using the following hooks (action and filters), you can develop a payment gateway for Webinane Commerce plugin.
…Custom code…
Developers can use its own pre-built (ready-to-use) libraries available for that specific payment gateway.
…Custom code…
© 2016 Developers, All rights reserved