Advertisement
Guest User

Untitled

a guest
Aug 19th, 2019
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.28 KB | None | 0 0
  1. /**
  2.  * @snippet       Hide free shipping method and set shipping costs of other methods to 0 and show message when reach free shipping amount for cart
  3.  * @author        Dexter
  4.  * @testedwith    WooCommerce 3.5.5
  5.  */
  6. add_filter( 'woocommerce_package_rates', 'dexter_apply_free_shipping_to_all_methods', 10, 2 );
  7. function dexter_apply_free_shipping_to_all_methods( $rates, $package ) {
  8.  
  9.   //jeżeli klient ma darmową dostawę to…
  10.   if( isset( $rates['free_shipping:21'] ) ) {
  11.     //ukrywamy darmową dostawę. Ma to sens bo…
  12.     unset( $rates['free_shipping:21'] );
  13.     unset( $rates['flat_rate:17']);
  14.     //wszystkie dostawy stają się za kwotę 0zł
  15.     foreach( $rates as $rate_key => $rate ) {
  16.                 // Append rate label titles (free)
  17.                 $rates[$rate_key]->label .= ': ' . __('0,00 zł', 'woocommerce');
  18.  
  19.                 // Set rate cost
  20.                 $rates[$rate_key]->cost = 0;
  21.  
  22.                 // Set taxes rate cost (if enabled)
  23.                 $taxes = array();
  24.                 foreach ($rates[$rate_key]->taxes as $key => $tax){
  25.                     if( $rates[$rate_key]->taxes[$key] > 0 )
  26.                         $taxes[$key] = 0;
  27.                 }
  28.                 $rates[$rate_key]->taxes = $taxes;
  29.     }  
  30.   }
  31.   return $rates;
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement