Advertisement
vapvarun

Modify Maximum Quantity for WooCommerce Products for Woo Sell Services

Dec 6th, 2023
762
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.14 KB | Software | 0 0
  1. /**
  2.  * Modify Maximum Quantity for WooCommerce Products
  3.  *
  4.  * This code snippet is used to adjust the maximum quantity input for WooCommerce products.
  5.  * Specifically, it targets products marked as a service or non-tangible item.
  6.  */
  7.  
  8. // Add a filter to modify the maximum quantity input for WooCommerce products
  9. add_filter( 'woocommerce_quantity_input_max', 'woo_sell_service_test_quantity_input_max', 20, 2 );
  10.  
  11. /**
  12.  * Function to set the maximum quantity for service-type products
  13.  *
  14.  * @param int $max_value The maximum quantity value.
  15.  * @param WC_Product $product The product object.
  16.  * @return int The modified maximum quantity value.
  17.  */
  18. function woo_sell_service_test_quantity_input_max( $max_value, $product ) {
  19.     // Check if the product is marked as a service or non-tangible item
  20.     if ( 'yes' == get_post_meta( $product->get_id(), '_wss_type', true ) ) {
  21.         // Ensure the product is not sold individually by clearing the '_sold_individually' meta
  22.         update_post_meta( $product->get_id(), '_sold_individually', '' );
  23.     }
  24.  
  25.     // Return the maximum quantity value (modified or unmodified)
  26.     return $max_value;
  27. }
  28.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement