如何以编程方式添加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_注释。查看注释表,找出它们存储在哪个“注释类型”和“注释代理”下。这可能会有所帮助: