| 123456789101112131415161718192021222324252627282930313233343536373839 |
- <?php
- /**
- * Extends WooCommerce order search to find orders by external_ref_ord_no.
- *
- * The hooks below cover both legacy (CPT) and HPOS storage modes. They make the
- * existing "Search orders" input also match the external reference number meta
- * — no additional UI is required.
- */
- defined('ABSPATH') || exit;
- class Order_Search_Manager {
- const META_KEY = 'external_ref_ord_no';
- public function __construct() {
- // Legacy CPT-backed storage: WC includes these post-meta keys in the search query.
- add_filter('woocommerce_shop_order_search_fields', array($this, 'add_meta_key_to_search'));
- // HPOS-backed storage: WC searches order meta listed here.
- add_filter('woocommerce_order_table_search_query_meta_keys', array($this, 'add_meta_key_to_search'));
- }
- /**
- * Append the external reference meta key to whichever list WC passes us.
- * Same callback works for both filters above.
- *
- * @param array $keys Meta keys / search fields collected by WC.
- * @return array
- */
- public function add_meta_key_to_search($keys) {
- if (!is_array($keys)) {
- $keys = array();
- }
- if (!in_array(self::META_KEY, $keys, true)) {
- $keys[] = self::META_KEY;
- }
- return $keys;
- }
- }
|