Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save plugin-republic/7530eeb9826a401d727937f7cde1913c to your computer and use it in GitHub Desktop.
Save plugin-republic/7530eeb9826a401d727937f7cde1913c to your computer and use it in GitHub Desktop.
<?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