Support

Account

Home Forums Add-ons Repeater Field Add multiple products programmatically in WooCommerce from ACF repeater Reply To: Add multiple products programmatically in WooCommerce from ACF repeater

  • Solved by placing everything inside the loop.

    
    $current_date = strtotime(date('Y-m-d H:i:s'));
        if(have_rows('theme_free_products', 'options')){
            while(have_rows('theme_free_products', 'options')){
                the_row();
                $start_date = get_sub_field('start_date');
                $end_date = get_sub_field('end_date');
                if(strtotime($start_date) <= $current_date && strtotime($end_date) > $current_date){
                    $product_id = get_sub_field('product', false);
    				$productextra    = wc_get_product( $product_id );
    				$new_product_price = 0;
    				$productextra->set_price( $new_product_price );   
    				$item_id    = $order->add_product( $productextra );             
                    
                }
            }
        }