Remove action ‘woocommerce_email_before_order_table’ not working

I am trying to remove the “Our bank information” and payment instructions from Woocommerce BACS gateway thankyou page and emails.

I know it should be done simply by removing the woocommerce_thankyou_bacs and woocommerce_email_before_order_table action.

Read More

I managed to remove the message from thankyou page, but it still appears in the emails. I checked, woocommerce_thankyou_bacs and woocommerce_email_before_order_table are both removed from wp_filter global.

I am relying on a function i copied from here: http://wpquestions.com/question/showChrono/id/9204 due to having similar problem of remove_action not working due to different unique id, and it works, in a way that the actions are gone from wp_filter global.

I have tried all kind of priorities, 0-20, the thankyou page message is gone but email still shows the payment instructions.

My code is as follows:

add_action( 'woocommerce_thankyou_bacs', function() {
    if( function_exists( 'wc_gateway_remove_hook' ) ) {
        //Remove BACS payment instructions from thankyou page <- WORKS!
        wc_gateway_remove_hook( 'WC_Gateway_BACS', 'woocommerce_thankyou_bacs', 'thankyou_page' );
        //Remove BACS payment instructions from email <- DOESN'T WORK!
        wc_gateway_remove_hook( 'WC_Gateway_BACS', 'woocommerce_email_before_order_table', 'email_instructions' );  

    }
}, 10 );

function wc_gateway_remove_hook( $classname, $hook, $callback ) {
    foreach( (array) $GLOBALS['woocommerce']->payment_gateways->payment_gateways as $key => $gateway_obj ) {
        if( $classname === get_class( $gateway_obj ) ) {
            remove_action( $hook, array( $gateway_obj, $callback ) );
        }
    }
}

Related posts

Leave a Reply

1 comment

  1. Try this:

    add_action( 'woocommerce_email_before_order_table', function() {
        if( function_exists( 'wc_gateway_remove_hook' ) ) {
            wc_gateway_remove_hook( 'WC_Gateway_BACS', 'woocommerce_email_before_order_table', 'email_instructions' );
        }
    }, 10);
    
    function wc_gateway_remove_hook( $classname, $hook, $callback ) {
        foreach( (array) $GLOBALS['woocommerce']->payment_gateways->payment_gateways as $key => $gateway_obj ) {
            if( $classname === get_class( $gateway_obj ) ) {
                remove_action( $hook, array( $gateway_obj, $callback ) );
            }
        }
    }