Last active
November 9, 2018 14:18
-
-
Save varun-pluginhive/ddba44d01e406891540263eb9264dd0d to your computer and use it in GitHub Desktop.
Snippet to adjust WooCommerce Shipping Rates to shipping method by specified amount of percent. PluginHive Plugins : https://www.pluginhive.com/plugins/
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * Snippet to adjust WooCommerce Shipping Rates to shipping method by specified amount of percent. | |
| * Created at : 09 Nov 2018 | |
| * Updated at : 09 Nov 2018 | |
| * PluginHive Plugins : https://www.pluginhive.com/plugins/ | |
| * Gist Link : https://gist.github.com/varun-pluginhive/ddba44d01e406891540263eb9264dd0d | |
| */ | |
| add_filter( 'woocommerce_package_rates', function( $package_rates ){ | |
| $cost_adjustment = 15; // Cost adjustment in percent | |
| $shipping_method = array( 'wf_multi_carrier_shipping' ); // Shipping method on which adjustment need to be done | |
| foreach( $package_rates as $package_rate ) { | |
| if( in_array( $package_rate->get_method_id(), $shipping_method ) ) { | |
| $cost = (double) $package_rate->get_cost(); | |
| $cost = $cost + ( $cost * $cost_adjustment / 100 ); | |
| $package_rate->set_cost($cost); | |
| } | |
| } | |
| return $package_rates; | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment