Code Snippet for Adding surcharge to your cart / checkout * Add this snippet to theme's functions.php or any other relevent place. Code Snippet for Adding surcharge to your cart / checkout filtered by Country * Add this snippet to theme’s functions.php or any other relevent place.
WooCommerce gets billing and shipping fields from the countries class class-wc-countries.php and get_address_fields function. This gives flexibility enable/disable fields based on the user’s location. With minimal development effort, these fields are highly customizable using actions and filters. If you are looking for a plugin to do this job, this article should help. Filter Hooks to add and update checkout fields includes Billing and Shipping Address Fields These actions and filters (refer the function get_address_fields ) give you complete control over checkout [...]
Given below is the code snippet to Disable Checkout Options based on User Roles and Country. We can check the user role based on the unique capabilities it has. Below snippet will enable the Payment Option "CC Avenue" only if the customer country is "IN" (India). Also, the snippet will enable PayPal as Payment Option if the customer is from any other countries. Check out this WordPress article for More information on Roles and Capabilities.
Below code snippet will change the default country and state when a new customer lands on checkout page. If you are looking for a plugin to do this job, this article should help. Screenshot: Set the default country as US and state as CA Set the default country and state as empty
Below code snippet helps to filter shipping methods based on States. In this particular example, the USPS rates will show up only when the user enters state from AK, HI, PR, GU, AS, VI, or UM ( convert it to appropriate state names please ) on cart/checkout page. Also, please note that below code is written for the product WooForce USPS Shipping Plugin for WooCommerce. You can change the elements of the array eligible_services_for_states_list to the appropriate one to make it [...]
Below code will help to convert mandatory address fields to optional on checkout page. You can place this code in function.php file located in your active child theme or theme.
Below snippet will hide shipping methods if none of the items in the cart belongs to the specific Shipping Class. Use the array variable $shipping_classes to define the shipping classes. Define the services to hide using the array variable $shipping_services_to_hide. If you are looking for a plugin to do this job, visit ELEX Hide Shipping Methods Plugin. Using this plugin, You can easily hide shipping methods based on various conditions. If you want to hide all the shipping methods, you can refer [...]
WooCommerce 2.6 brings major changes in the shipping module including the introduction of Shipping Zone. These changes break the number of existing snippets including the snippet to Hide shipping methods when FREE SHIPPING is available. This is because of minor changes in the way $rates array is formed for the shipping method "Free Shipping". Prior to WooCommerce 2.6, the details of shipping method "Free Shipping" is stored under array element $rates['free_shipping']. Now it is stored as $rates['free_shipping:shipping_zone_instance_id'] where shipping_zone_instance_id is the [...]
What is WooCommerce Shipping Zone? Shipping zones are introduced in WooCommerce 2.6 to bring more flexibility while configuring your shipping methods. Legacy shipping methods (Flat Rate, International Flat Rate, Local Pickup and Delivery, and Free Shipping) are deprecated. So, it's highly recommended to disable these and setting up new rates within shipping zones as soon as possible. A shipping zone is a geographic region where a certain set of shipping methods and rates apply. You can add as many zones as you [...]
By default, when a customer reaches cart page during checkout process, WooCommerce will auto-select one of the shipping methods available. This could lead customer to ignore the rest of the shipping options presented on cart page. Same scenario is applicable for payment options presented on checkout page. Screenshot - Default Shipping Option Code Snippet to clear the shipping and payment option while first time checkout. Below code snippet will help you to prevent WooCommerce from auto-choosing a default Shipping / Payment option [...]