Woocommerce 기반 -새 주문 이메일 제목에 사용자 이름 추가 . WooCommerce 이메일 제목을 변경하려고합니다. 주문시 사이트 관리자로받은 메일입니다.
다음 구조를 만들려고합니다.
[온라인 상점] 주문 (# ....) 이름, 두 번째 이름, 합계 -..., SKU1, SKU2, SKU3 ...
이 코드를 사용하는데 주문의 모든 제품에 대한 SKU를 얻는 방법을 모르겠습니까?
add_filter('woocommerce_email_subject_new_order', 'change_admin_email_subject', 1, 2);
function change_admin_email_subject( $subject, $order ) {
global $woocommerce;
$blogname = wp_specialchars_decode(get_option('blogname'), ENT_QUOTES);
$subject = sprintf( '[%s] Order (# %s) от %s %s Total-%u EU. %s ', $blogname, $order->id,
$order->billing_first_name, $order->billing_last_name, $order->order_total, $order->...);
return $subject;
}
이를 위해 다음을 사용할 수 있습니다. 제품 SKU는 주문 개체에서 foreach 루프를 통해 가져옵니다.
코드에 대한 설명과 함께 주석 추가
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 );
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다