1 回答
TA贡献1829条经验 获得超4个赞
为此,您可以使用以下方法,通过 foreach 循环从订单对象获取产品 SKU。
在代码中添加了带有解释的注释
function filter_woocommerce_email_subject_new_order( $subject, $order ) {
// Blogname
$blogname = wp_specialchars_decode( get_option( 'blogname' ), ENT_QUOTES );
// Get order ID
$order_id = $order->get_id();
// Get billing first name
$first_name = $order->get_billing_first_name();
// Get billing last name
$last_name = $order->get_billing_last_name();
// Get order total
$order_total = $order->get_total();
// Empty array
$product_skus = array();
// Loop through order items
foreach( $order->get_items() as $item ) {
// Get an instance of corresponding the WC_Product object
$product = $item->get_product();
// Push to array
$product_skus[] = $product->get_sku();
}
// Array to string
$product_skus_str = implode( ", ", $product_skus );
// Subject
$subject = sprintf( '[%s] Order (# %s) From %s %s Total %s SKU %s', $blogname, $order_id, $first_name, $last_name, $order_total, $product_skus_str );
return $subject;
}
add_filter( 'woocommerce_email_subject_new_order', 'filter_woocommerce_email_subject_new_order', 1, 2 );
- 1 回答
- 0 关注
- 118 浏览
添加回答
举报