Skip to content

Commit

Permalink
Urgent Fix: product and user search not returning results for some users
Browse files Browse the repository at this point in the history
  • Loading branch information
kilbot committed Sep 27, 2023
1 parent 1fed0bb commit 66a47af
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 38 deletions.
59 changes: 28 additions & 31 deletions includes/API/Customers.php
Original file line number Diff line number Diff line change
Expand Up @@ -193,55 +193,52 @@ public function customer_query( array $prepared_args, WP_REST_Request $request )
return $prepared_args;
}

public function modify_user_query( $user_query ) {
if ( isset( $user_query->query_vars['_search_term'] ) && ! empty( $user_query->query_vars['_search_term'] ) ) {
$search_term = $user_query->query_vars['_search_term'];
public function modify_user_query( $user_query ) {
if ( isset( $user_query->query_vars['_search_term'] ) && ! empty( $user_query->query_vars['_search_term'] ) ) {
$search_term = $user_query->query_vars['_search_term'];

global $wpdb;
global $wpdb;

$like = '%' . $wpdb->esc_like( $search_term ) . '%';
$like_term = '%' . $wpdb->esc_like( $search_term ) . '%';

$meta_conditions = "
( wp_usermeta.meta_key = '_woocommerce_pos_uuid' AND wp_usermeta.meta_value LIKE '{$like}' )
$meta_conditions = $wpdb->prepare(
"({$wpdb->usermeta}.meta_key = '_woocommerce_pos_uuid' AND {$wpdb->usermeta}.meta_value LIKE %s)
OR
( wp_usermeta.meta_key = 'first_name' AND wp_usermeta.meta_value LIKE '{$like}' )
({$wpdb->usermeta}.meta_key = 'first_name' AND {$wpdb->usermeta}.meta_value LIKE %s)
OR
( wp_usermeta.meta_key = 'last_name' AND wp_usermeta.meta_value LIKE '{$like}' )
({$wpdb->usermeta}.meta_key = 'last_name' AND {$wpdb->usermeta}.meta_value LIKE %s)
OR
( wp_usermeta.meta_key = 'billing_first_name' AND wp_usermeta.meta_value LIKE '{$like}' )
({$wpdb->usermeta}.meta_key = 'billing_first_name' AND {$wpdb->usermeta}.meta_value LIKE %s)
OR
( wp_usermeta.meta_key = 'billing_last_name' AND wp_usermeta.meta_value LIKE '{$like}' )
({$wpdb->usermeta}.meta_key = 'billing_last_name' AND {$wpdb->usermeta}.meta_value LIKE %s)
OR
( wp_usermeta.meta_key = 'billing_email' AND wp_usermeta.meta_value LIKE '{$like}' )
({$wpdb->usermeta}.meta_key = 'billing_email' AND {$wpdb->usermeta}.meta_value LIKE %s)
OR
( wp_usermeta.meta_key = 'billing_company' AND wp_usermeta.meta_value LIKE '{$like}' )
({$wpdb->usermeta}.meta_key = 'billing_company' AND {$wpdb->usermeta}.meta_value LIKE %s)
OR
( wp_usermeta.meta_key = 'billing_phone' AND wp_usermeta.meta_value LIKE '{$like}' )
";
({$wpdb->usermeta}.meta_key = 'billing_phone' AND {$wpdb->usermeta}.meta_value LIKE %s)",
$like_term, $like_term, $like_term, $like_term, $like_term, $like_term, $like_term, $like_term
);

// Add conditions for user email, username, and ID
$user_conditions = "
( {$wpdb->users}.user_email LIKE '{$like}' )
$user_conditions = $wpdb->prepare(
"({$wpdb->users}.user_email LIKE %s)
OR
( {$wpdb->users}.user_login LIKE '{$like}' )
({$wpdb->users}.user_login LIKE %s)
OR
( {$wpdb->users}.ID = '{$search_term}' )
";
({$wpdb->users}.ID = %d)",
$like_term, $like_term, $search_term
);

// Combine meta_conditions and user_conditions
$all_conditions = "({$meta_conditions}) OR ({$user_conditions})";

// Append the all_conditions to the original query_where
$user_query->query_where .= " AND ( {$all_conditions} )";

remove_action( 'pre_user_query', array( $this, 'modify_user_query' ) );
}
}
$all_conditions = "($meta_conditions) OR ($user_conditions)";

$user_query->query_where .= " AND ( {$all_conditions} )";

remove_action( 'pre_user_query', array( $this, 'modify_user_query' ) );
}
}


/**
/**
* Returns array of all customer ids.
*
* Note: user queries are a little more complicated than post queries, for example,
Expand Down
4 changes: 2 additions & 2 deletions includes/API/Products.php
Original file line number Diff line number Diff line change
Expand Up @@ -343,12 +343,12 @@ public function posts_search( string $search, WP_Query $wp_query ): string {
$search_array[] = $wpdb->prepare( "{$wpdb->posts}.post_title LIKE %s", $n . $like_term . $n );

// Search in _sku field
$search_array[] = $wpdb->prepare( "(wp_postmeta.meta_key = '_sku' AND wp_postmeta.meta_value LIKE %s)", $n . $like_term . $n );
$search_array[] = $wpdb->prepare( "({$wpdb->postmeta}.meta_key = '_sku' AND {$wpdb->postmeta}.meta_value LIKE %s)", $n . $like_term . $n );

// Search in barcode field
$barcode_field = woocommerce_pos_get_settings( 'general', 'barcode_field' );
if ( $barcode_field !== '_sku' ) {
$search_array[] = $wpdb->prepare( '(wp_postmeta.meta_key = %s AND wp_postmeta.meta_value LIKE %s)', $barcode_field, $n . $like_term . $n );
$search_array[] = $wpdb->prepare( "({$wpdb->postmeta}.meta_key = %s AND {$wpdb->postmeta}.meta_value LIKE %s)", $barcode_field, $n . $like_term . $n );
}
}

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@wcpos/woocommerce-pos",
"version": "1.3.10",
"version": "1.3.11",
"description": "A simple front-end for taking WooCommerce orders at the Point of Sale.",
"main": "index.js",
"workspaces": {
Expand Down
5 changes: 4 additions & 1 deletion readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Contributors: kilbot
Tags: cart, e-commerce, ecommerce, inventory, point-of-sale, pos, sales, sell, shop, shopify, store, vend, woocommerce, wordpress-ecommerce
Requires at least: 5.6 & WooCommerce 5.3
Tested up to: 6.3
Stable tag: 1.3.10
Stable tag: 1.3.11
License: GPL-3.0
License URI: http://www.gnu.org/licenses/gpl-3.0.html

Expand Down Expand Up @@ -63,6 +63,9 @@ There is more information on our website at [https://wcpos.com](https://wcpos.co

== Changelog ==

= 1.3.11 - 2023/09/27 =
* Urgent Fix: product and user search not returning results for some users

= 1.3.10 - 2023/08/29 =
* Urgent Fix: pages with slug starting with 'pos' redirecting to the POS page

Expand Down
6 changes: 3 additions & 3 deletions woocommerce-pos.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@
* Plugin Name: WooCommerce POS
* Plugin URI: https://wordpress.org/plugins/woocommerce-pos/
* Description: A simple front-end for taking WooCommerce orders at the Point of Sale. Requires <a href="http://wordpress.org/plugins/woocommerce/">WooCommerce</a>.
* Version: 1.3.10
* Version: 1.3.11
* Author: kilbot
* Author URI: http://wcpos.com
* Text Domain: woocommerce-pos
* License: GPL-3.0+
* License URI: http://www.gnu.org/licenses/gpl-3.0.txt
* Domain Path: /languages
* WC tested up to: 7.9
* WC tested up to: 8.1
* WC requires at least: 5.3
*
* @author Paul Kilmurray <[email protected]>
Expand All @@ -24,7 +24,7 @@
use function define;

// Define plugin constants.
const VERSION = '1.3.10';
const VERSION = '1.3.11';
const PLUGIN_NAME = 'woocommerce-pos';
const SHORT_NAME = 'wcpos';
define( __NAMESPACE__ . '\PLUGIN_FILE', plugin_basename( __FILE__ ) ); // 'woocommerce-pos/woocommerce-pos.php'
Expand Down

0 comments on commit 66a47af

Please sign in to comment.