Description
// Define steps by category
function ccom_get_step_by_product_category( $product_id ) {
// Categories in priority order
if( has_term( 'wheels', 'product_cat', $product_id ) ) { return 2; }
if( has_term( 'tires', 'product_cat', $product_id ) ) { return 2; }
if( has_term( 'fabrics', 'product_cat', $product_id ) ) { return 0.25; }
// Default to one
return 1;
}
// Update min value to the quantity field
add_filter( 'woocommerce_quantity_input_min', function( $default, $product ) {
$product_id = $product->get_id();
return ccom_get_step_by_product_category( $product_id );
}, 10, 2 );
// Update step value to the quantity field
add_filter( 'woocommerce_quantity_input_step', function( $default, $product ) {
$product_id = $product->get_id();
return ccom_get_step_by_product_category( $product_id );
}, 10, 2 );
// Replace the WooCommerce filter that is validating the quantity
remove_filter( 'woocommerce_stock_amount', 'intval' );
add_filter( 'woocommerce_stock_amount', 'floatval' );
// PayPal compatibility
add_filter( 'woocommerce_paypal_args', function( $args ) {
$custom = json_decode( $args['custom'] );
$order = wc_get_order( $custom->order_id );
$order_items = $order->get_items();
$counter = 1;
while( isset( $args[ 'quantity_' . $counter] ) ) {
foreach( $order_items as $order_item ) {
$product = $order_item->get_product();
if(
$product->get_name() == $args['item_name_' . $counter]
&& strpos( $order_item->get_quantity(), '.' )
) {
$args[ 'amount_' . $counter ] = number_format( $order_item->get_total(), 2, '.', '' );
$args[ 'quantity_' . $counter ] = 1;
$args[ 'item_name_' . $counter ] .= $order_item->get_quantity();
}
}
$counter ++;
}
return $args;
}, 100 );
Support
Using our Google upload form:
- Describe the issue and what you’ve observed.
- Describe your expected outcome(s).
- List steps to reproduce the issue.
- Optionally attach screen-shot images or a video.
Credits
We code all of our code snippets directly. Our clients provide most of the ideas and demand for the functionality provided by our code snippets.
There are several sources one can find on Google for code that has inspired or contributed to this open-source library. Here’s some main ones:
License & Disclaimer
All code snippets are licensed GPLv2 (or later) matching WordPress licensing.
Disclaimer of warranty:
EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM “AS IS” WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.