使用以下代码,当订单完成时,我可以成功地将自定义订单注释添加到订阅续订订单中。
但是,我想对此进行修改,以将注释添加到订购注释,而不是订购注释。我认为订阅说明使用与add_order_note
相同的$subscription->add_order_note
函数,而不是$order->add_order_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();
}
}
您知道我需要添加/更改以使其添加到订购单而不是订购单吗?