Home / eCommerce / Remove the coupon section for orders that did not use any coupon.
Duplicate Snippet

Embed Snippet on Your Site

Remove the coupon section for orders that did not use any coupon.

Code Preview
php
<?php
add_action( 'woocommerce_email_before_order_table', 'conditionally_remove_coupon_section_from_email', 5, 4 );
function conditionally_remove_coupon_section_from_email( $order, $sent_to_admin, $plain_text, $email ) {
    if ( ! $order instanceof WC_Order ) {
        return;
    }
    // Get applied coupons
    $coupons = $order->get_coupon_codes();
    // If NO coupons were used, remove the coupon section
    if ( empty( $coupons ) ) {
        remove_action(
            'woocommerce_email_before_order_table',
            array( \ACFWF()->Order_Details, 'coupons_list_email_register_hook' ),
            10
        );
        remove_action(
            'woocommerce_email_after_order_table',
            array( \ACFWF()->Order_Details, 'coupons_list_email_unregister_hook' ),
            10
        );
    }
}

Comments

Add a Comment