Barcode display for populated email notification status ONLY

On my WooCommerce website, I use the Woocommerce Order Barcodes to display email notification order barcodes.
I would like to hide or delete this barcode and show it ONLY in completed order status notifications.

I tried to edit the plugin file (I know this is not recommended). I deleted this (line 128 - 129) in the file : class-woocommerce-order-barcodes.php

// Add barcode to order complete email
add_action( 'woocommerce_email_after_order_table', array( $this, 'get_email_barcode' ), 1, 1 );

But it removes the barcodes of all email notifications.

How do I remove these barcodes from email notifications and show them only with a completed email notification?

thank

+4
source share
1 answer

A twist to make it work only for completed order status notifications is to add only this small condition to the IF statement:

$order->has_status( 'completed' )

So first you can try:

if (!$this->has_status( 'completed' ) ){
    add_action( 'woocommerce_email_after_order_table', array( $this, 'get_email_barcode' ), 1, 1 );
}

But since I'm not sure to get the $ order ($ this) object there, I looked further in the code for this plugin.

On line 358 , you have the code below where I add the condition.

/**
 * Get barcode for display in an email
 * @access  public
 * @since   1.0.0
 * @param   object $order Order object
 * @return  void
 */
public function get_email_barcode ( $order ) {

    if( ! $order ) return;

    // HERE is my condition  <====  <====  <====  <====  <====  <====  <====
    if (!$order->has_status( 'completed' ) ) return;

    // Generate correctly formatted HTML for email
    ob_start(); ?>

// … / …
// code of the function continues …

Here I am sure that this will work since I already received the object . The only thing you will need to add this code again every time you update this plugin. $order

, , . , .

+2

Source: https://habr.com/ru/post/1663590/


All Articles