Skip to content

Commit

Permalink
prevent POS Only products from being added to cart
Browse files Browse the repository at this point in the history
  • Loading branch information
kilbot committed Jan 25, 2024
1 parent 07f55dd commit e3cc27e
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion includes/Products.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,14 @@ public function __construct() {
if ( $pos_only_products ) {
add_action( 'woocommerce_product_query', array( $this, 'hide_pos_only_products' ) );
add_filter( 'woocommerce_variation_is_visible', array( $this, 'hide_pos_only_variations' ), 10, 4 );
add_filter( 'woocommerce_add_to_cart_validation', array( 'prevent_pos_only_add_to_cart', 10, 2 ) );
// add_filter( 'woocommerce_get_product_subcategories_args', array( $this, 'filter_category_count_exclude_pos_only' ) );
}

/**
* Allow decimal quantities for products and variations.
*
* @TODO - this will affect the online store aswell, should I make it POS only?
* @TODO - this will affect the online store as well, should I make it POS only?
*/
$allow_decimal_quantities = woocommerce_pos_get_settings( 'general', 'decimal_qty' );
if ( \is_bool( $allow_decimal_quantities ) && $allow_decimal_quantities ) {
Expand Down Expand Up @@ -150,4 +151,21 @@ public function filter_category_count_exclude_pos_only( $args ) {

return $args;
}

/**
* Prevent POS Only products from being added to the cart.
*
* @param bool $passed
* @param int $product_id
*
* @return bool
*/
public function prevent_pos_only_add_to_cart( $passed, $product_id ) {
$pos_visibility = get_post_meta( $product_id, '_pos_visibility', true );
if ( $pos_visibility === 'pos_only' ) {
return false;
}

return $passed;
}
}

0 comments on commit e3cc27e

Please sign in to comment.