4

On my WooCommerce web site I use Woocommerce Order Barcodes to display a order barcodes on email notifications.
I would like to hide or remove this barcode and display it ONLY on completed order status email notifications.

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

// 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 from all email notifications.

How can I remove these barcodes from email notification and show it only on completed email notification?

Thanks

LoicTheAztec
  • 229,944
  • 23
  • 356
  • 399
Nacer Chikhi
  • 109
  • 1
  • 6

1 Answers1

2

The turn around to make it work only for completed order status email notifications, is to add just this small condition in an IF statement:

$order->has_status( 'completed' )

So you could try it this way first:

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

But as I am not sure to get the $order object ($this) in there, I have looked further in the code of this plugin.

At line 358 you have the code below where I have 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 pretty sure that is going to work, as I we get already the $order object. The only thing is that you will have to add this code again each time you will update that plugin.

As this is untested, I am not sure that it will work. Please give me a feed back on it

LoicTheAztec
  • 229,944
  • 23
  • 356
  • 399