Support » Plugin: WooCommerce » Woocommerce New Order Email Override

  • Resolved kingslayer21

    (@kingslayer21)


    What I want is to have a different header for Variable product and simple product on the email when there is a new order.

    EXAMPLE:

    Simple Product’s Header is: New Customer Order
    Variable Product’s Header is: New Customer Order Confirmed

    How do I add a condition whether the ordered product in the email is a Variable or Simple Product?

    https://wordpress.org/plugins/woocommerce/

Viewing 15 replies - 1 through 15 (of 15 total)
  • Plugin Author Mike Jolley (a11n)

    (@mikejolley)

    See docs.woothemes.com/document/template-structure/

    You’d need to loop over the items before this line and then set the email_heading to something else:

    https://github.com/woothemes/woocommerce/blob/master/templates/emails/customer-processing-order.php#L26

    Thread Starter kingslayer21

    (@kingslayer21)

    Actually, I have already modified the woocommerce cart and the customer can only buy one product at a time. So there’s no need to loop for checking the items. What I need is a conditional code in the email template wherein it checks if the product is variable or simple.

    Thanks

    Plugin Author Mike Jolley (a11n)

    (@mikejolley)

    You still need a loop because thats how products are stored in the order.

    $order->get_items();

    This returns an array of items.

    $variable = false;
    
    foreach ( $order->get_items() as $item ) {
         $_product = $order->get_product_from_item( $item );
         if ( $_product->is_type( 'variable' ) ) {
              $variable = true;
         }
    }
    Thread Starter kingslayer21

    (@kingslayer21)

    Where should I put this Mike?

    would this work?

    $order->get_items();
    
    foreach ( $order->get_items() as $item ) {
         $_product = $order->get_product_from_item( $item );
         if ( $_product->is_type( 'variable' ) ) {
              $email_heading= "New Customer Order Confirmed";
         } else {
              $email_heading= "New Customer Order";
         }
    }
    do_action( 'woocommerce_email_header', $email_heading, $email ); ?>
    Thread Starter kingslayer21

    (@kingslayer21)

    Tried my code above, and it seems that it does not work. Any other suggestions Mike?

    Plugin Author Mike Jolley (a11n)

    (@mikejolley)

    This code was to be adapted and put into the template files I referenced. Order does not exist in your code/hook.

    Thread Starter kingslayer21

    (@kingslayer21)

    What do you mean Mike? I think the order is working on my email template since it has the following hook:

    do_action( 'woocommerce_email_order_details', $order, $sent_to_admin, $plain_text, $email );

    Plugin Author Mike Jolley (a11n)

    (@mikejolley)

    Sorry misread what you’re doing.

    Which file did you place the code in? Processing affects customer processing emails, no others. So you’ll need to update a few if you want to affect other emails. The code looks ok aside from the first line is not needed.

    Thread Starter kingslayer21

    (@kingslayer21)

    wp-content/plugins/woocommerce/templates/emails/customer-processing-order.php

    I did put it on the php file above. But it does not change anything on the header.

    Plugin Author Mike Jolley (a11n)

    (@mikejolley)

    Which order email are you checking though? This is only the one to customer after payment.

    Thread Starter kingslayer21

    (@kingslayer21)

    Which order email are you checking though?

    what do you mean by that Mike?

    Thread Starter kingslayer21

    (@kingslayer21)

    I also edited and I added this block of code on the customer-completed-order.php and it works but only outputs the ELSE condition. Of course I have been testing it on the simple and variable products.

    foreach ( $order->get_items() as $item ) {
         $_product = $order->get_product_from_item( $item );
         if ( $_product->is_type( 'variable' ) ) {
              _e( "Your order has been received and is now being <b>PROCESSED</b>. Your order details are shown below for your reference:", 'woocommerce' );
         } else {
              _e( "Your order has been received and is <b>CONFIRMED</b>. Your order details are shown below for your reference:", 'woocommerce' );
         }
    }

    what could be the problem that I am facing Mike?

    Plugin Author Mike Jolley (a11n)

    (@mikejolley)

    Try:

    $_product->is_type( 'variation' )
    Thread Starter kingslayer21

    (@kingslayer21)

    wow, it is now working ! thank you so much Mike. I wonder what’s the difference between variation and variable? 🙂

    Plugin Author Mike Jolley (a11n)

    (@mikejolley)

    Variable is the parent. Variation is the child.

Viewing 15 replies - 1 through 15 (of 15 total)
  • The topic ‘Woocommerce New Order Email Override’ is closed to new replies.