Skip to content

Commit

Permalink
Fix: POS Only Products appearing in the web store
Browse files Browse the repository at this point in the history
  • Loading branch information
kilbot committed Sep 4, 2024
1 parent 949c1a4 commit 4bb69cf
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 16 deletions.
1 change: 1 addition & 0 deletions includes/API.php
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,7 @@ public function rest_index( WP_REST_Response $response ): WP_REST_Response {
$response->data['wp_version'] = get_bloginfo( 'version' );
$response->data['wc_version'] = WC()->version;
$response->data['wcpos_version'] = VERSION;
$response->data['use_jwt_as_param'] = woocommerce_pos_get_settings( 'tools', 'use_jwt_as_param' );

return $response;
}
Expand Down
24 changes: 14 additions & 10 deletions includes/Products.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public function __construct() {
$pos_only_products = woocommerce_pos_get_settings( 'general', 'pos_only_products' );

if ( $pos_only_products ) {
add_filter( 'posts_where', array( $this, 'hide_pos_only_products' ), 10, 2 );
add_action( 'pre_get_posts', array( $this, 'hide_pos_only_products' ) );
add_filter( 'woocommerce_variation_is_visible', array( $this, 'hide_pos_only_variations' ), 10, 4 );
add_action( 'woocommerce_store_api_validate_add_to_cart', array( $this, 'store_api_prevent_pos_only_add_to_cart' ) );

Expand Down Expand Up @@ -76,22 +76,26 @@ public function product_set_stock( WC_Product $product ): void {
*
* @return string
*/
public function hide_pos_only_products( $where, $query ) {
// Ensure this only runs for the main WooCommerce shop queries
if ( ! is_admin() && $query->is_main_query() && ( is_shop() || is_product_category() || is_product_tag() ) ) {
global $wpdb;
public function hide_pos_only_products( $query ) {
// Ensure this only runs for the main WooCommerce queries on product-related pages
if ( ! is_admin() && $query->is_main_query() && ( is_shop() || is_product() || is_post_type_archive( 'product' ) || is_product_taxonomy() ) ) {

$settings_instance = Settings::instance();
$settings = $settings_instance->get_pos_only_product_visibility_settings();

if ( isset( $settings['ids'] ) && ! empty( $settings['ids'] ) ) {
$exclude_ids = array_map( 'intval', (array) $settings['ids'] );
$ids_format = implode( ',', array_fill( 0, count( $exclude_ids ), '%d' ) );
$where .= $wpdb->prepare( " AND {$wpdb->posts}.ID NOT IN ($ids_format)", $exclude_ids );
$exclude_ids = array_map( 'intval', (array) $settings['ids'] ); // Sanitize IDs as integers

// Merge any existing excluded IDs with the new ones
$existing_excludes = $query->get( 'post__not_in' );
if ( ! is_array( $existing_excludes ) ) {
$existing_excludes = array();
}

// Set the post__not_in query parameter to exclude specified IDs
$query->set( 'post__not_in', array_merge( $existing_excludes, $exclude_ids ) );
}
}

return $where;
}

/**
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.6.3",
"version": "1.6.4",
"description": "A simple front-end for taking WooCommerce orders at the Point of Sale.",
"main": "index.js",
"workspaces": {
Expand Down
6 changes: 5 additions & 1 deletion readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Contributors: kilbot
Tags: ecommerce, point-of-sale, pos, inventory, woocommerce
Requires at least: 5.6
Tested up to: 6.5
Stable tag: 1.6.3
Stable tag: 1.6.4
License: GPL-3.0
License URI: http://www.gnu.org/licenses/gpl-3.0.html

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

== Changelog ==

= 1.6.4 - 2024/09/04 =
* Fix: POS Only Products appearing in the web store
* Fix: Disable wp_footer for POS Order Pay template

= 1.6.3 - 2024/06/29 =
- Fix: Critical error preventing bulk update of products

Expand Down
8 changes: 4 additions & 4 deletions woocommerce-pos.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,18 @@
* 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.6.3
* Version: 1.6.4
* 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
* Requires at least: 5.6
* Tested up to: 6.5
* Tested up to: 6.6
* Requires PHP: 7.4
* Requires Plugins: woocommerce
* WC tested up to: 9.0
* WC tested up to: 9.2
* WC requires at least: 5.3
*
* @see http://wcpos.com
Expand All @@ -24,7 +24,7 @@
namespace WCPOS\WooCommercePOS;

// Define plugin constants.
const VERSION = '1.6.3';
const VERSION = '1.6.4';
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 4bb69cf

Please sign in to comment.