Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/csharp-4.0/2.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
如何以编程方式添加Woocommerce订阅订单注释_Woocommerce_Woocommerce Subscriptions - Fatal编程技术网

如何以编程方式添加Woocommerce订阅订单注释

如何以编程方式添加Woocommerce订阅订单注释,woocommerce,woocommerce-subscriptions,Woocommerce,Woocommerce Subscriptions,使用下面的代码,我可以在订单完成时成功地将自定义订单注释添加到订阅续订订单中 但是,我想修改此选项,将注释添加到订阅注释中,而不是添加到订单注释中。我认为订阅说明使用与$Subscription->add\u order\u note相同的add\u order\u note功能,而不是$order->add\u order\u note。但是我试图让$subscription变量在下面的代码中工作,但没有成功 // Add box contents (product excerpt) as o

使用下面的代码,我可以在订单完成时成功地将自定义订单注释添加到订阅续订订单中

但是,我想修改此选项,将注释添加到订阅注释中,而不是添加到订单注释中。我认为订阅说明使用与
$Subscription->add\u order\u note
相同的
add\u order\u note
功能,而不是
$order->add\u order\u note
。但是我试图让$subscription变量在下面的代码中工作,但没有成功

// Add box contents (product excerpt) as order note for subscriptions

add_action( 'woocommerce_email_before_order_table', 'custom_action_on_completed_customer_email_notification', 10, 4 );
function custom_action_on_completed_customer_email_notification( $order, $sent_to_admin, $plain_text, $email ) {


if( 'customer_completed_renewal_order' == $email->id ){ // for processing order status customer notification…

$product_id = '';

foreach ($order->get_items() as $item_id => $item_values) {
    $product_id = $item_values['product_id'];

    break; // (optional) stop loop to first item
}

// The text for the note

$note = get_the_excerpt($product_id);

// Add the note
$order->add_order_note( $note, $is_customer_note = 1 );

// Save the data
$order->save(); 

}

}
您知道我需要添加/更改什么才能将此添加到订阅说明而不是订单说明吗?

该方法只是WordPress的包装。我不知道“订阅说明”,但如果插件也将其说明存储为注释,则可以使用功能wp_insert_注释。查看注释表,找出它们存储在哪个“注释类型”和“注释代理”下。这可能会有所帮助: