祝大家新年快乐:)
我正在使用常规 WooCommerce,并在通过 REST API 更改货物状态时发送客户电子邮件。 下面的代码运行得很好。 但启用 HPOS 后,数据不带有相同的代码。 我应该如何改变它? (我已经尝试了几种替代方案) get_post_meta 部分是问题所在。我发送了邮件,但数据丢失。
// Targets custom order status "shipping-progress"
// Uses 'woocommerce_order_status_' hook
add_action( 'woocommerce_order_status_shipping-progress', 'bbloomer_status_custom_notification', 20, 2 );
function bbloomer_status_custom_notification( $order_id, $order ) {
$heading = 'Your order is shipped';
$subject = 'Your order is shipped';
// Get WooCommerce email objects
$mailer = WC()->mailer()->get_emails();
$mailer['WC_Email_Customer_Completed_Order']->heading = $heading;
$mailer['WC_Email_Customer_Completed_Order']->settings['heading'] = $heading;
$mailer['WC_Email_Customer_Completed_Order']->subject = $subject;
$mailer['WC_Email_Customer_Completed_Order']->settings['subject'] = $subject;
// Send the email with custom heading & subject
$mailer['WC_Email_Customer_Completed_Order']->trigger( $order_id );
}
add_action( 'woocommerce_email_before_order_table', 'bbloomer_add_content_specific_email', 20, 4 );
function bbloomer_add_content_specific_email( $order, $sent_to_admin, $plain_text, $email ) {
$orderstatus = $order->get_status();
if ( $email->id == 'customer_completed_order' ) {
if ( $orderstatus == 'shipping-progress' ) {
$cargo_company = get_post_meta( $order->get_id(), 'shipping_company', true );
$cargo_shipping_no = get_post_meta( $order->get_id(), 'shipping_number', true );
echo '<p>Cargo Company: <strong>'.cargo_company.'</strong></p>';
echo '<p>Tracking number: <strong>'.cargo_shipping_no.'</strong></p>';
}
}
}
根据提供的代码,要获取订单元数据,当启用 woocommerce 高性能订单存储(HPOS)时,应使用以下代码。
$order->get_meta( 'shipping_company', true );
$order->get_meta( 'shipping_number', true );