• Resolved sunrosea

    (@sunrosea)


    Hello!

    I’ve been trying to get rid of the payment instructions that comes with every customer email for the ‘cod’ payment gateway, specifically for certain emails such as the invoice email.

    The information seems to be hooked into the order details, so unhooking order details just removes the order details and the payment instructions. All I want to get rid of is the payment instructions.

    So what I ended up trying to do is this:

    function custom_woocommerce_email_before_order_table($order, $sent_to_admin, $plain_text, $email){
    	
        $available_gateways = WC()->payment_gateways->payment_gateways();
    	
        if ( isset( $available_gateways['cod'] ) && $email->id == 'customer_invoice'){
    		
    		
    		remove_action( 'woocommerce_email_before_order_table', array( $available_gateways['cod'], 'email_instructions' ), 10, 3 );
    		
    	}
           
    }
    add_action( 'woocommerce_email_before_order_table','custom_woocommerce_email_before_order_table', 20, 4);

    Unfortunately, the remove_action is probably called too late at this point which is why it doesn’t work.

    Is there any neat solutions to this?

Viewing 5 replies - 1 through 5 (of 5 total)
  • Laurena Rehbein

    (@lrehbein)

    Automattic Happiness Engineer

    Hi @sunrosea,

    I have tried this, and it seems to work:

    add_action( ‘woocommerce_email_before_order_table’, ‘custom_remove_instructions’, `1);

    function custom_remove_instructions(){
    if ( ! class_exists( ‘WC_Payment_Gateways’ ) ) return;
    $gateways = WC_Payment_Gateways::instance(); // gateway instance
    $available_gateways = $gateways->get_available_payment_gateways();

    if ( isset( $available_gateways[‘cod’] ) )
    remove_action( ‘woocommerce_email_before_order_table’, array( $available_gateways[‘cod’], ’email_instructions’ ), 10, 3 );
    }`

    I built this based off this, for reference: https://stackoverflow.com/questions/45516304/removing-bacs-instructions-from-email-notiications-in-woocommerce

    Laurena Rehbein

    (@lrehbein)

    Automattic Happiness Engineer

    That pasted with some smart quotes, unfortunately. Trying again here:

    `
    add_action( ‘woocommerce_email_before_order_table’, ‘custom_remove_instructions’, 1);

    function custom_remove_instructions(){
    if ( ! class_exists( ‘WC_Payment_Gateways’ ) ) return;
    $gateways = WC_Payment_Gateways::instance(); // gateway instance
    $available_gateways = $gateways->get_available_payment_gateways();

    if ( isset( $available_gateways[‘cod’] ) )
    remove_action( ‘woocommerce_email_before_order_table’, array( $available_gateways[‘cod’], ’email_instructions’ ), 10, 3 );
    }
    `

    Thread Starter sunrosea

    (@sunrosea)

    Hello!

    I have seen that code and tried it. Peculiar how it works for you but not for me.
    When I use that code, and go to an order and select Order Actions -> Email invoice / order details to customer, it breaks the page and immediately loads the email template in the browser window instead of actually doing the action.

    The specific code that seems to break it is this part:
    $gateways = WC_Payment_Gateways::instance(); // gateway instance

    If I remove that, the code obviously doesn’t work, but then it doesn’t break the order page.

    Can you try using the code you provided me, and then go through the same steps by going to an order and select the “invoice customer” order actions option and see if it breaks your page too?

    Thank you for your assistance!

    • This reply was modified 5 years, 10 months ago by sunrosea.
    • This reply was modified 5 years, 10 months ago by sunrosea.
    Thread Starter sunrosea

    (@sunrosea)

    Anyone have any inputs/updates on this?

    Apparently, it’s not the gateways instance that messes it up now when I’m trying it. But something else still is. When you choose an order in the back-end and choose to send an invoice through the order actions, it still breaks the page and instead loads the email template on the page and I have to press the back button in the browser to get back to the order page.

    I have the latest Woocommerce v.3.6.1 and latest WordPress v.5.1.1 installed.

    Thanks.

    • This reply was modified 5 years, 10 months ago by sunrosea.
    jessepearson

    (@jessepearson)

    Automattic Happiness Engineer

    @sunrosea It looks like the quotes were broken in the previous snippets. I have cleaned up the code and placed it below and in a gist:
    https://gist.github.com/jessepearson/f36567682dd44e2e044bd3594d4ea079

    This works for me when placing an order and resending the Invoice email with WooCommerce 3.6.5.

    
    /**
     * Removes the payment instructions from the COD payment gateway in WooCommerce.
     */
    function jp_custom_remove_instructions(){
    	if ( ! class_exists( 'WC_Payment_Gateways' ) ) {
    		return;
    	}
    	$gateways           = WC_Payment_Gateways::instance(); // gateway instance
    	$available_gateways = $gateways->get_available_payment_gateways();
    	if ( isset( $available_gateways['cod'] ) ) {
    		remove_action( 'woocommerce_email_before_order_table', array( $available_gateways['cod'], 'email_instructions' ), 10, 3 );
    	}
    }
    add_action( 'woocommerce_email_before_order_table', 'jp_custom_remove_instructions', 1 );
    

    I am also setting this thread to resolved at this time. If you believe it is not resolved, you can switch the status back.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Removing payment instructions from certain emails’ is closed to new replies.