Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * @snippet Hide free shipping method and set shipping costs of other methods to 0 and show message when reach free shipping amount for cart
- * @author Dexter
- * @testedwith WooCommerce 3.5.5
- */
- add_filter( 'woocommerce_package_rates', 'dexter_apply_free_shipping_to_all_methods', 10, 2 );
- function dexter_apply_free_shipping_to_all_methods( $rates, $package ) {
- //jeżeli klient ma darmową dostawę to…
- if( isset( $rates['free_shipping:21'] ) ) {
- //ukrywamy darmową dostawę. Ma to sens bo…
- unset( $rates['free_shipping:21'] );
- unset( $rates['flat_rate:17']);
- //wszystkie dostawy stają się za kwotę 0zł
- foreach( $rates as $rate_key => $rate ) {
- // Append rate label titles (free)
- $rates[$rate_key]->label .= ': ' . __('0,00 zł', 'woocommerce');
- // Set rate cost
- $rates[$rate_key]->cost = 0;
- // Set taxes rate cost (if enabled)
- $taxes = array();
- foreach ($rates[$rate_key]->taxes as $key => $tax){
- if( $rates[$rate_key]->taxes[$key] > 0 )
- $taxes[$key] = 0;
- }
- $rates[$rate_key]->taxes = $taxes;
- }
- }
- return $rates;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement