Woocommerce_email_subject_customer_completed_order

时间:2020-02-10 作者:ELE

如何将这两个代码结合起来,我需要比较id producto,以便在订单完成后教授不同的主题。THX:)

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] New Customer Order (# %s) from Name %s %s\', $blogname, $order->id, $order->billing_first_name, $order->billing_last_name );

    return $subject;
}
以及

    add_filter( \'woocommerce_email_format_string\' , \'filter_email_format_string\', 20, 2 );
function filter_email_format_string( $string, $email ) {
 // Get the instance of the WC_Order object
 $order = $email->object;
 $items = $order->get_items();
  foreach ( $items as $item ) {
  $product_id = $item[\'product_id\'];
  if ( $product_id == 153 ) {
     $subject = \'¡Bienvenida al Curso Online 4\';
  } elseif ( $product_id == 192 ) { 
    $subject = \'¡Bienvenida al Curso Online d2\'; 
  } else {
     $subject = \'¡Bienvenida al Curso Online 3\'; 
  }
 return $subject;
 }
}

1 个回复
最合适的回答,由SO网友:7uc1f3r 整理而成
function change_admin_email_subject( $subject, $order ) {
    // Get items
    $items = $order->get_items();

    foreach ( $items as $item ) {
        // Get product object
        $product = wc_get_product( $item[\'product_id\'] );

        // Get product id
        $product_id = $product->get_id();

        if ( $product_id == 153 ) {
            $subject = \'¡Bienvenida al Curso Online 4\';
        } elseif ( $product_id == 192 ) { 
            $subject = \'¡Bienvenida al Curso Online d2\'; 
        } else {
            $subject = \'¡Bienvenida al Curso Online 3\'; 
        }
    }

    return $subject;
}
add_filter(\'woocommerce_email_subject_new_order\', \'change_admin_email_subject\', 10, 2);

相关推荐