Skip to content

Commit 2fe7c48

Browse files
committed
Exclude a list of product barcode that provide their own fields
1 parent 100a668 commit 2fe7c48

File tree

1 file changed

+23
-1
lines changed

1 file changed

+23
-1
lines changed

includes/Admin/Products/Single_Product.php

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public function __construct() {
4646
'online_only' => __( 'Online Only', 'woocommerce-pos' ),
4747
);
4848

49-
if ( $this->barcode_field && ! \in_array( $this->barcode_field, array( '_sku', '_global_unique_id' ), true ) ) {
49+
if ( $this->barcode_field && ! \in_array( $this->barcode_field, $this->get_excluded_barcode_fields(), true ) ) {
5050
add_action( 'woocommerce_product_options_sku', array( $this, 'woocommerce_product_options_sku' ) );
5151
add_action( 'woocommerce_process_product_meta', array( $this, 'woocommerce_process_product_meta' ) );
5252
add_action( 'woocommerce_product_after_variable_attributes', array( $this, 'after_variable_attributes_barcode_field' ), 10, 3 );
@@ -280,4 +280,26 @@ public function save_product_variation_pos_only_products( $variation_id ): void
280280
$settings_instance->update_visibility_settings( $args );
281281
}
282282
}
283+
284+
/**
285+
* Get the list of barcode fields that should be excluded from custom barcode field functionality.
286+
*
287+
* These fields are built-in WooCommerce or plugin fields that don't need custom barcode input.
288+
*
289+
* @return array Array of excluded barcode field keys.
290+
*/
291+
private function get_excluded_barcode_fields(): array {
292+
$excluded_fields = array(
293+
'_sku', // default WooCommerce SKU field
294+
'_global_unique_id', // default WooCommerce GTIN, UPC, EAN, or ISBN
295+
'_alg_ean', // https://wpfactory.com/item/ean-barcodes-woocommerce/
296+
);
297+
298+
/*
299+
* Filter the list of barcode fields that should be excluded from custom barcode field functionality.
300+
*
301+
* @param array $excluded_fields Array of field keys to exclude from custom barcode input.
302+
*/
303+
return apply_filters( 'woocommerce_pos_excluded_custom_barcode_fields', $excluded_fields );
304+
}
283305
}

0 commit comments

Comments
 (0)