• Resolved happyday25

    (@happyday25)


    I have my gift cards set up to send to the recipient as soon as an order is placed. If only a gift card was ordered, the order complete emails are also sent at the same time to the person who placed the order.

    If the only item in the order is a gift card, is it possible to edit the body text of the order complete email to read something besides the default “Hi John, Great news, your order has shipped!” to something more appropriate like “Your gift card has been emailed to the recipient, here is your receipt.”?

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author pimwick

    (@pimwick)

    You can program the Order Complete email by overriding the template.

    WooCommerce has instructions on how to override the template here:

    https://woocommerce.com/posts/how-to-customize-emails-in-woocommerce/

    Once you have overridden the template, you will have to write code to examine the contents of the Order. Loop over each order item and check to see if it is a gift card product by doing something like this:

    if ( is_a( $product, 'WC_Product_PW_Gift_Card' ) ) {
        // Do something
    }

    This is not specific to the gift card plugin and would be outside the scope of what support we can provide so I’m marking the thread as resolved but let us know if you have any other questions!

    Thread Starter happyday25

    (@happyday25)

    Ok thank you for the information! I will look into this.

    Also, I am using the code below to change the subject line of the order complete emails when a gift card is added. When there isn’t one included though, the subject line is blank. Do you know what might be causing this?

    function woocommerce_custom_email_subject_per_product_depending_on_product_id( $subject, $order ) {
    global $woocommerce;
    $items = $order->get_items();
    foreach ( $items as $item ) {
    $product_id = $item['product_id'];
    if ( $product_id == 5354 ) {
    $subject = 'Your order receipt';
    }
    return $subject;
    }
    }
    add_filter( 'woocommerce_email_subject_customer_completed_order', 'woocommerce_custom_email_subject_per_product_depending_on_product_id', 10, 5 );

    Plugin Author pimwick

    (@pimwick)

    Looks like the “return $subject;” line is inside the foreach loop. Try this code instead and see if it does the trick:

    function woocommerce_custom_email_subject_per_product_depending_on_product_id( $subject, $order ) {
        global $woocommerce;
        
        $items = $order->get_items();
        
        foreach ( $items as $item ) {
            $product_id = $item['product_id'];
            
            if ( $product_id == 5354 ) {
                $subject = 'Your order receipt';
            }
    
            break;
        }
    
        return $subject;
    }
    Thread Starter happyday25

    (@happyday25)

    That fixed it, thank you so much!

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Change text in order complete emails when only gift card is purchased’ is closed to new replies.