Skip to content

Instantly share code, notes, and snippets.

@webdados
Created September 1, 2020 08:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save webdados/822bd3d6add49488e946ae68958d7ec4 to your computer and use it in GitHub Desktop.
Save webdados/822bd3d6add49488e946ae68958d7ec4 to your computer and use it in GitHub Desktop.
Only show the WooCommerce Barcode on processing (and completed) orders
<?php
//Add this to your (child-)theme functions.php file
//Before woocommerce_email_after_order_table 1 and woocommerce_order_details_after_order_table 1, because on the woocommerce_order_barcodes_display_barcode filter we don't have access to the $order object
add_action( 'woocommerce_email_after_order_table', 'custom_prevent_barcode', -1, 1 );
add_action( 'woocommerce_order_details_after_order_table', 'custom_prevent_barcode', -1, 1 );
function custom_prevent_barcode( $order ) {
$allowed_statuses = array(
'processing',
//'completed', //Uncomment this if you also want the barcode if the order is completed
);
//Status not allowed? Return false to the woocommerce_order_barcodes_display_barcode filter
if ( ! $order->has_status( $allowed_statuses ) ) {
add_filter( 'woocommerce_order_barcodes_display_barcode', '__return_false' );
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment