Advertisement
nshelper

Untitled

Jun 21st, 2022
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.64 KB | None | 0 0
  1. foreach ( $order->get_items() as $product_info ) {             
  2.                
  3.                 do_action( 'woocommerce/cart_loop/start', $product_info );
  4.  
  5.                 $product_id = ( int ) apply_filters ( 'woocommerce_add_to_cart_product_id', $product_info ['product_id'] );
  6.                 $qty = ( int ) $product_info ['qty'];
  7.                 $all_variations = array ();
  8.                 $variation_id = ( int ) $product_info[ 'variation_id' ];
  9.            
  10.                 $cart_product_data = apply_filters ( 'woocommerce_order_again_cart_item_data', array (), $product_info, $order );
  11.                 foreach ( $product_info ['item_meta'] as $product_meta_name => $product_meta_value ) {
  12.  
  13.  
  14.                     if ( taxonomy_is_product_attribute( $product_meta_name ) ) {                       
  15.                         $all_variations [$product_meta_name] =  ucfirst($product_meta_value);                              
  16.                                              
  17.                     } else {
  18.                         if ( meta_is_product_attribute( $product_meta_name,  $product_meta_value, $product_id ) ) {
  19.                             $all_variations[ $product_meta_name ] = ucfirst($product_meta_value);                      
  20.                         }
  21.                     }
  22.                 }
  23.            
  24.               // print_r($all_variations);
  25.               // die();
  26.                 // Add to cart validation
  27.                 if (! apply_filters ( 'woocommerce_add_to_cart_validation', true, $product_id, $qty, $variation_id, $all_variations, $cart_product_data )) {
  28.                     do_action( 'woocommerce/cart_loop/end', $product_info );
  29.                     continue;
  30.                 }
  31.            
  32.                 // Checks availability of products
  33.                 $array = wc_get_product( $product_id );
  34.            
  35.                 // Add to cart order products
  36.                 $add_to_cart = WC()->cart->add_to_cart ( $product_id, $qty, $variation_id, $all_variations );
  37.                
  38.                 do_action( 'woocommerce/cart_loop/end', $product_info );
  39.             }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement