Woocommerce emails

1 Reply ·

  1. I’m trying to customise woocommerce email headers.

    //https://wordpress.stackexchange.com/questions/218162/editing-header-titles-of-each-details-in-woocommerce-order-email
    add_filter('woocommerce_email_heading_customer_on_hold_order', 'filter_heading_customer_on_hold_order');
    function filter_heading_customer_on_hold_order($heading) {
    
        return 'New Membership Application Details and Form Download Link';
    
    }
    

    works fine, but changes the header on all on- hold emails.
    I am trying to do this on a per category basis using
    if ( has_term( 'memberships', 'product_cat' ) )

    I have been able to modify the email body text on a per category basis

    /*
    https://www.damiencarbery.com/2018/07/add-info-to-woocommerce-order-emails/
    */
    
    /* Add note to the order email. */
    add_action( 'woocommerce_email_order_details', 'railtrail_raffles_cat_delivery_info_to_order_email', 5, 4 ); 
    function railtrail_raffles_cat_delivery_info_to_order_email( $order, $sent_to_admin, $plain_text, $email ) {
        // Only customers need to know about the delivery times.
        if ( $sent_to_admin ) {
            return;
        }
    
        $order_has_raffles_product = false;
    
        $items = $order->get_items();
        foreach ( $items as $item_id => $item ) {
            $product = $item->get_product();
            if ( $product->is_type( 'variation' ) ) {
                $product = wc_get_product( $product->get_parent_id() );
            }
    
            if ( has_term( 'raffles', 'product_cat', $product->get_id() ) ) {
                $order_has_raffles_product = true;
            }
        }
    
        if ( $order_has_raffles_product ) {
            if ( $plain_text ) {
                echo "n** Please make your payment by Direct Bank Transfer USING YOUR ORDER NUMBER LISTED BELOW AS THE PAYMENT REFERENCE. Your order raffle numbers will be sent by email after the funds have cleared in our account.n";
            }
            else {
                 echo '<p>Please make your payment by Direct Bank Transfer <strong>USING YOUR ORDER NUMBER LISTED BELOW AS THE PAYMENT REFERENCE.</strong>.</p> <p>Your order raffle numbers will be sent by email after the funds have cleared in our account.</p>';
            }
        }
    }
    
    

    but the header does not have $order
    Some links I found when researching to try to understand:
    https://businessbloomer.com/woocommerce-visual-hook-guide-emails/
    http://hookr.io/filters/woocommerce_email_headers/
    https://wp-kama.com/hook/woocommerce_email_headers
    https://www.quora.com/How-can-I-customise-an-email-template-in-Wordpress-WooCommerce-to-remove-the-header
    https://github.com/woocommerce/woocommerce/blob/07351d5e11f8d5dfc3620577ec5fe3128e704e81/includes/emails/class-wc-email-customer-on-hold-order.php

  2. Justin Tadlock

    Here’s the filter hook from the WooCommerce code:

    return apply_filters( 'woocommerce_email_heading_' . $this->id, $this->format_string( $this->get_option( 'heading', $this->get_default_heading() ) ), $this->object, $this );
    

    Or, a simplified look at it:

    return apply_filters( 'woocommerce_email_heading_customer_on_hold_order', $heading, $this->object, $this );
    

    If I’m not mistaken (not really too familiar with WC), $this->object is the same the $order object. You should be able to pass it as a second parameter like so:

    add_filter( 'woocommerce_email_heading_customer_on_hold_order', 'your_filter', 10, 2 );
    
    function your_filter( $heading, $order ) {
    
    }