Advertisement
nshelper

Untitled

Feb 21st, 2023
200
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.99 KB | None | 0 0
  1.     public function was_match_condition_contains_shipping_class( $match, $operator, $value, $package ) {
  2.  
  3.         // True until proven false
  4.         if ( $operator == '!=' ) :
  5.             $match = true;
  6.         endif;
  7.  
  8.         foreach ( $package['contents'] as $key => $product ) {
  9.             do_action( 'woocommerce/cart_loop/start', $product  );
  10.             $id      = ! empty( $product['variation_id'] ) ? $product['variation_id'] : $product['product_id'];
  11.             $product = wc_get_product( $id );
  12.  
  13.             if ( $operator == '==' ) {
  14.                 if ( $product->get_shipping_class() == $value ) {
  15.                     do_action( 'woocommerce/cart_loop/end', $product  );
  16.                     return true;
  17.                     }              
  18.             }
  19.             elseif ( $operator == '!=' ) {
  20.                 if ( $product->get_shipping_class() == $value ) {
  21.                     do_action( 'woocommerce/cart_loop/end', $product  );
  22.                     return false;
  23.                 }
  24.            
  25.             }
  26.             do_action( 'woocommerce/cart_loop/end', $product  );
  27.         }
  28.  
  29.         return $match;
  30.  
  31.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement