Skip to content

Instantly share code, notes, and snippets.

@seebeen
Last active February 11, 2024 19:23
Show Gist options
  • Save seebeen/b2f4d4fcd4455b3923ce17ca5db80dc7 to your computer and use it in GitHub Desktop.
Save seebeen/b2f4d4fcd4455b3923ce17ca5db80dc7 to your computer and use it in GitHub Desktop.
WooCommerce - Change quantity args for products across frontend
<?php
/**
* @var array<int, array{
* input_value: int,
* max_value: int,
* min_value: int,
* step: int,
* }|null> $product_args Array of qty data or null for default - keyed by product ID
*/
$product_args = array();
$default_args = array(
'input_value' => 10,
'max_value' => 20,
'min_value' => 6,
'step' => 2
);
add_filter('woocommerce_quantity_input_args', function($args, $product) use ($product_args, $default_args) {
if ( ! in_array( $product->get_id(), $product_ids, true ) ) {
return $args;
}
return array_merge(
$args,
$product_ids[ $product->get_id() ] ?? $default_args,
);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment