Untitled
webwizards
plain_text
10 hours ago
791 B
0
Indexable
add_filter('b2bking_product_min_value', 'set_minimum_product_quantity', 10, 3); function set_minimum_product_quantity($have, $product_id, $user_id) { // Check if user is B2B if (b2bking()->is_b2b_user()) { global $wpdb; // Query database directly for stock status and quantity $stock_status = $wpdb->get_var($wpdb->prepare( "SELECT meta_value FROM {$wpdb->postmeta} WHERE post_id = %d AND meta_key = '_stock_status'", $product_id )); // Set minimum to 3 if stock is 0 or out of stock if ($stock_status === 'outofstock' || $stock_status === 'onbackorder') { return 3; } } // Return original value if conditions not met return $have; }
Editor is loading...
Leave a Comment