Delete order info section from email template in woocommerce

前端 未结 3 1484
攒了一身酷
攒了一身酷 2021-01-03 16:15

I\'m trying to delete the Order Information section on a Completed Order and Customer Invoice emails.

Can\'t find how to delete this in th

相关标签:
3条回答
  • 2021-01-03 16:20

    do_action( 'woocommerce_email_order_meta', $order, $sent_to_admin, $plain_text );

    try to remove this hook.

    0 讨论(0)
  • 2021-01-03 16:39

    Removing this part should fix the job
    do_action( 'woocommerce_email_order_meta', $order, $sent_to_admin, $plain_text );

    0 讨论(0)
  • 2021-01-03 16:42

    You don't want to remove the entire action hook. This could effect other plugins that rely on it's presence. (Not to mention the order details are on the woocommerce_email_order_details details hook and not the woocommerce_email_order_meta hook anyway).

    The proper way to remove the order details from all emails is to remove their callback function which is WC_Emails::order_details() which is added to the woocommerce_email_order_details hook here

    You cannot call remove_action() directly and so must call it from inside an add_action() callback... after it has been added to it's hook, but before it has been run. In this case we're just going to sneak onto the same hook, but with an earlier priority. Also note, that remove_action() must have the same priority as the add_action() that you are trying to remove.

    function so_39251827_remove_order_details( $order, $sent_to_admin, $plain_text, $email ){
        $mailer = WC()->mailer(); // get the instance of the WC_Emails class
        remove_action( 'woocommerce_email_order_details', array( $mailer, 'order_details' ), 10, 4 );
    }
    add_action( 'woocommerce_email_order_details', 'so_39251827_remove_order_details', 5, 4 );
    

    EDIT: Instructions for use

    1. Stop overriding the emails/customer-completed-order.php template and remove it from your theme. You do not need to edit it directly to solve this question.
    2. Add the above code block to your theme's functions.php or preferably a custom-snippets plugin, such as this one.

    EDIT #2: Remove Subscriptions Info Only

    Replace the above code with the following:

    function so_39251827_remove_subscription_details( $order, $sent_to_admin, $plain_text, $email ){
        remove_action( 'woocommerce_email_after_order_table', array( 'WC_Subscriptions_Order', 'add_sub_info_email' ), 15, 3 );
    }
    add_action( 'woocommerce_email_after_order_table', 'so_39251827_remove_subscription_details', 5, 4 );
    
    0 讨论(0)
提交回复
热议问题