
Implementing Shipping Offers in WooCommerce
- August 31, 2016
- Leave a comment
Shipping offers are being displayed on many e-commerce websites. For example, shipping will be free on purchasing products of worth $100. In this article, you will learn to implement shipping offers in the WooCommerce plug-in.
To add this functionality, woocommerce_package_rates filter is used to control the rates of shipping methods.
Let’s say, in pt_process_shipping_offer function, you have set all the shipping methods of WooCommerce as “free shipping”. You can have an option to set specific shipping methods as free by accessing the array of rates $rates and using shipping method ID.
You just need to add the following code in your Theme‘s functions.php file and you can also utilize it in your plug-in:
1 2 3 4 5 6 7 8 9 10 11 12 13 |
<?php add_filter( 'woocommerce_package_rates', 'pt_process_shipping_offer', 10, 2 ); function pt_process_shipping_offer( $rates, $package ){ $shipping_offer_amount = 100; if( $package['contents_cost'] > $shipping_offer_amount ){ foreach( $rates as $ind => $rate ){ $rate->cost = 0; $rates[$ind] = $rate; } } return $rates; } ?> |
User Comments