Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/wordpress/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 根据订单中的产品变化更改订单的自定义字段值_Php_Wordpress_Woocommerce_Advanced Custom Fields_Product - Fatal编程技术网

Php 根据订单中的产品变化更改订单的自定义字段值

Php 根据订单中的产品变化更改订单的自定义字段值,php,wordpress,woocommerce,advanced-custom-fields,product,Php,Wordpress,Woocommerce,Advanced Custom Fields,Product,在WooCommerce with plugin中,我创建了一个函数,用于更新WooCommerce商店中销售印刷杂志的订阅订单的自定义字段。此功能将根据用户是否选择从杂志的上一期、当前期或下一期开始订阅(选择作为三种不同类型订阅产品的产品变体),使用单期产品的名称更新订阅订单的“开始发行”字段 我已按如下方式对函数进行了编码,但在我正在完成的任何测试订单上,如果尝试更改以下代码,则该函数无法按要求工作-不更新订单的“开始发布”元字段 我以前构建过类似的函数,可以根据设置的条件自动完成订单。我很

在WooCommerce with plugin中,我创建了一个函数,用于更新WooCommerce商店中销售印刷杂志的订阅订单的自定义字段。此功能将根据用户是否选择从杂志的上一期、当前期或下一期开始订阅(选择作为三种不同类型订阅产品的产品变体),使用单期产品的名称更新订阅订单的“开始发行”字段

我已按如下方式对函数进行了编码,但在我正在完成的任何测试订单上,如果尝试更改以下代码,则该函数无法按要求工作-不更新订单的“开始发布”元字段

我以前构建过类似的函数,可以根据设置的条件自动完成订单。我很难理解为什么这个特殊的功能不起作用,但我知道我可能遗漏了一些非常重要的东西

我写的代码是:

/*** UPDATE 'STARTING ISSUE' FIELD FOR ORDERS ***/

// Club membership ID = '7968'
// Subscription (non-gift) ID = '13962'
// Subscription (gift) ID = '13966'

add_action( 'first_issue_for_subs', 'first_issue_for_subs' );
function first_issue_for_subs( $order_id ) {    
    if ( ! $order_id ) { return; }
    global $woocommerce;
    $order = new WC_Order( $order_id );
    foreach( $order->get_items() as $item ) {                                           
        if ( ( $item['product_id'] == '7968' ) or ( $item['product_id'] == '13962' ) or ( $item['product_id'] == '13966' ) ) {        
            $product = wc_get_product( $item['product_id'] );         
            $variations = $product->children;        
            foreach ( $variations as $variation ) {        
                $variation_id = $variation->variation_id;        
                if ( $variation_id == '16171' or $variation_id == '16174' or $variation_id == '16168' ) {
                    // Current Issue
                    $current_args = [ 
                        'posts_per_page' => 1,
                        'post_type' => 'product',
                        'tax_query' => array( array( 'taxonomy' => 'product_cat', 'field' => 'slug', 'terms' => 'single_issues' ) ),                                 
                    ];
                    $current_query = get_posts( $current_args );
                    foreach ( $current_query as $queried_issue )  { 
                        $first_issue = the_title();
                        $order->update_field( 'starting_issue', $first_issue );
                    }
                }        
                elseif ( $variation_id == '16167' or $variation_id == '16170' or $variation_id == '16173' ) {
                    // Next Issue
                    $next_args = [ 
                        'posts_per_page' => 1, 
                        'post_status' => 'draft', 
                        'post_type' => 'product', 
                        'tax_query' => array( array( 
                            'taxonomy' => 'product_cat', 
                            'field' => 'slug', 
                            'terms' => 'single_issues' 
                        ) ), 
                        'orderby' => 'date', 
                        'order' => 'ASC', 
                    ];
                    $next_query = get_posts( $next_args );
                    foreach ( $next_query as $queried_issue ) { 
                        $first_issue = the_title();
                        $order->update_field( 'starting_issue', $first_issue );
                    }
                }   
                elseif ( $variation_id == '6169' or $variation_id == '16172' or $variation_id == '16166' ) {
                    // Previous Issue - gift
                    $previous_args = [ 
                        'posts_per_page' => 2,
                        'offset' => 1,
                        'post_type' => 'product',
                        'tax_query' => array( array( 
                            'taxonomy' => 'product_cat', 
                            'field' => 'slug', 
                            'terms' => 'single_issues' 
                        ) ),                                 
                    ];
                    $previous_query = get_posts( $previous_args );
                    foreach ( $previous_query as $queried_issue ) { 
                        $first_issue = the_title();
                        $order->update_field( 'starting_issue', $first_issue );
                    }
                }        
            } 
        } else {
            $first_issue = 'NOT_SUBSCRIPTION';
            $order->update_field( 'starting_issue', $first_issue );
        }
    } 
}

有人能解释一下吗?非常感谢您的帮助。

当这个钩子被称为“第一次发布”时?当这个钩子被称为“第一次发布”时?