Created
April 30, 2019 14:11
-
-
Save JeroenSormani/f32bc6a49c478bc1482a1ff44d3d6b5d to your computer and use it in GitHub Desktop.
Set product quantity value through URL parameter in WooCommerce
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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