Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save JeroenSormani/f32bc6a49c478bc1482a1ff44d3d6b5d to your computer and use it in GitHub Desktop.
Save JeroenSormani/f32bc6a49c478bc1482a1ff44d3d6b5d to your computer and use it in GitHub Desktop.
Set product quantity value through URL parameter in WooCommerce
<?php // For implementation instructions see; https://aceplugins.com/how-to-add-a-code-snippet/
/**
* Product quantity through URL parameter.
*
* Allow for setting a suggested product quantity in the product quantity field by adding
* a &quantity=5 URL parameter.
*
* @param array $args Original arguments.
* @param WC_Product $product Product being viewed.
* @return mixed Modified arguments.
*/
function ace_product_quantity_through_url( $args, $product ) {
if ( isset( $_GET['quantity'] ) && ! isset( $_POST['quantity'] ) ) {
$args['input_value'] = absint( $_GET['quantity'] );
}
return $args;
}
add_filter( 'woocommerce_quantity_input_args', 'ace_product_quantity_through_url', 10, 2 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment