最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

woocommerce offtopic - woocommerce_email_subject_customer_completed_order

programmeradmin1浏览0评论

how do i combine this two codes, i need compare id producto for late teach a diferent subject when the order is completed. 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;
}

AND

    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;
 }
}

how do i combine this two codes, i need compare id producto for late teach a diferent subject when the order is completed. 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;
}

AND

    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;
 }
}
Share Improve this question edited Feb 10, 2020 at 12:40 ELE asked Feb 10, 2020 at 12:34 ELEELE 134 bronze badges 1
  • WooCommerce is off topic here. Go to their official forum. – Vitauts Stočka Commented Feb 10, 2020 at 14:24
Add a comment  | 

1 Answer 1

Reset to default 1
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);
发布评论

评论列表(0)

  1. 暂无评论