Advertisement
Guest User

Untitled

a guest
Jan 23rd, 2017
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.58 KB | None | 0 0
  1. <?php
  2. function wcs_my_free_shipping( $is_available ) {
  3.     global $woocommerce;
  4.  
  5.     // set the product ids that are eligible
  6.     $eligible = array( '2241' );
  7.  
  8.     // get cart contents
  9.     $cart_items = $woocommerce->cart->get_cart();
  10.     // loop through the items looking for one in the eligible array
  11.     foreach ( $cart_items as $key => $item ) {
  12.         if( in_array( $item['product_id'], $eligible ) ) {
  13.             return true;
  14.         }
  15.     }
  16.  
  17.     // nothing found return the default value
  18.     return $is_available;
  19. }
  20. add_filter( 'woocommerce_shipping_free_shipping_is_available', 'wcs_my_free_shipping', 20 );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement