Last active
March 19, 2024 20:04
-
-
Save plugin-republic/7530eeb9826a401d727937f7cde1913c to your computer and use it in GitHub Desktop.
This file contains 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 | |
/** | |
* Force a child product to be automatically selected | |
*/ | |
function prefix_filter_default_child_independent_quantity( $quantity_field_value, $child_product_id, $item ) { | |
if( $child_product_id == 9999 ) { // Change this to your child product ID | |
return 1; | |
} | |
return $quantity_field_value; | |
} | |
add_filter( 'pewc_child_product_independent_quantity', 'prefix_filter_default_child_independent_quantity', 10, 3 ); | |
/** | |
* Set the default quantity when the user toggles on and off the checkbox | |
*/ | |
function prefix_set_child_quantity_default( $set, $post_id ) { | |
return 'yes'; | |
} | |
add_filter( 'pewc_set_child_quantity_default', 'prefix_set_child_quantity_default', 10, 2 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment