• I’m attempting to use the woocommerce_email_before_order_table to add content to an email based upon
    1) whether or not the “Order” is a quote. This part of my code appears to be working fine.
    2) change the text depending upon whether the email is going to the customer or the administrator. That is what is NOT working.

    If the Order is a Quote,

    • The Administrator email should say:
      New Customer Quote.
    • The Customer email should say: Order Now – Please note your order will NOT be placed into our production until payment has been made’

    With the code below, both the administrator and customer emails are displaying the customer email text. What am I doing wrong?

    function add_order_email_instructionsNEW( $order, $sent_to_admin ) { // add_order_email_instructions
    	if($sent_to_admin) {
    		if (   $order->payment_method == 'jetpack_custom_gateway' ) {
    			echo '<p style="font-size:2em; background-color:#08456e; color:white; padding:30px;">New Customer Quote</p>';
    
    		} else {
    			echo 'New Customer Order';
    
    		}
    
    	} elseif (!$sent_to_admin)  {
    
        if (   $order->payment_method == 'jetpack_custom_gateway' ) {
          // quote
    		echo '<p style="font-size:2em; background-color:#08456e; color:white; padding:30px;">Here is your quote <a style=" background-color:#e5d11e; padding:10px; font-size:.5em; text-decoration:none; font-weight:bold; margin-left:30px;" href="https://accessfixtures.com/my-account/">Order Now</a></p>';
          echo '<p>Please note your order <strong>will NOT be placed into our production</strong> until payment has been made. </p>';
    
        }
    	 else {
          // other methods (ie credit card)
          echo '<p style="font-size:2em; background-color:#08456e; color:white; padding:30px;">Thank you for Your Order</p>';
    
        } 		
    
    	}
    
    } // END d_order_email_instructions
Viewing 7 replies - 1 through 7 (of 7 total)
  • Moderator bcworkz

    (@bcworkz)

    When you add this function as a callback, are you specifying that 2 parameters are to be passed? It appears $sent_to_admin does not have the value you think it should.

    What action/filter are you hooking anyway?

    Thread Starter MTWK-Applied

    (@mtwk-applied)

    $sent_to_admin – I was assuming that this meant that the email was true or false depending upon whether this email was being sent to the administrator. Apparently, bad assumption.

    The action I was targeting is:
    woocommerce_email_before_order_table
    add_action( 'woocommerce_email_before_order_table', 'add_order_email_instructionsNEW');

    Sorry late response. Email notification went into Spam.

    Thread Starter MTWK-Applied

    (@mtwk-applied)

    Is there a function that will indicate whether the email is being sent to the administrator vs. the customer?

    Thread Starter MTWK-Applied

    (@mtwk-applied)

    Ok. The functionality I wanted is working with:

    remove_action ( 'woocommerce_email_header', 'action_woocommerce_email_header', 10, 1 );
    add_action ( 'woocommerce_email_header', 'ai_indicate_quote_order', 10, 2 );
    function ai_indicate_quote_order($order, $is_admin) { // function
    
    	// Only for admin emails
    	if ($is_admin) { // test if admin
    
    		if ($order->payment_method == 'jetpack_custom_gateway') { // test order type
    		                                                          // quote
    			echo '<p style="font-size:2em; background-color:#08456e; color:white; padding:30px;">New Customer Quote</p>';
    		} else {
    
    			echo '<p style="font-size:2em; background-color:#08456e; color:white; padding:30px;">New Customer Order</p>';
    		} // test order type
    	} else {
    
    		if ($order->payment_method == 'jetpack_custom_gateway') { // test order type
    		                                                          // quote
    			echo '<p style="font-size:2em; background-color:#08456e; color:white; padding:30px;">Here is your quote <a style=" background-color:#e5d11e; padding:10px; font-size:.5em; text-decoration:none; font-weight:bold; margin-left:30px;" href="https://accessfixtures.com/my-account/">Order Now</a></p>';
    		} else {
    			// other methods (ie credit card)
    			echo '<p style="font-size:2em; background-color:#08456e; color:white; padding:30px;">New Customer Order</p>';
    		} // test order type
    	}
    } // END function

    except:
    1) the header is NOT going away with my remove action so I’m getting a “double header”
    2) How do I target a specific email – I ONLY want this functionality on the email templates: admin-new-order.php and customer-processing-order.php. Right now, my code is being applied to ALL emails. I’m trying to avoid changing the email templates themselves as I want to be able to update woocommerce without having to redo coding.

    Moderator bcworkz

    (@bcworkz)

    Something is cursed about this thread – I keep missing your posts.

    The remove action function takes three parameters, the final ‘1’ is invalid and likely causing the function call to be ignored.

    The ‘woocommerce_email_header’ action only has the header as an argument, there is no $is_admin flag. The idea being you could add or remove header actions from other contexts to manage what header is used. Thus the header isn’t the right place to manage the content you want.

    You can customize any template in the Woo templates structure by copying the file to a similar structure of your theme and altering that version. Any templates found will be used in place of the plugin’s versions. https://docs.woothemes.com/document/template-structure/

    Thread Starter MTWK-Applied

    (@mtwk-applied)

    “You can customize any template in the Woo templates structure by copying the file to a similar structure of your theme and altering that version”

    I’m fully aware that we can customize. However, after going that route with a previous version of woocommerce AND having to have to REDO the template changes when they updated the templates, I was hoping to avoid this path.

    I’m fully aware that we can customize. However, after going that route with a previous version of woocommerce AND having to have to REDO the template changes when they updated the templates, I was hoping to avoid this path.

    I’m attempting to do the same thing. Did you ever find a solution?

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Change woocommerce email based upon email template’ is closed to new replies.