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
1 Answer
Reset to default 1function 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);