Created
May 2, 2022 14:59
-
-
Save plugin-republic/cb85eb47a3b1b7da0293a231fb172a62 to your computer and use it in GitHub Desktop.
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 | |
/** | |
* Specify the default quantities here | |
* You'll need to update the child product IDs to match yours | |
*/ | |
function florian_child_quantity( $quantity_field_value, $child_product_id, $item ) { | |
if( $child_product_id == 267 ) { | |
$quantity_field_value = 3; | |
} | |
if( $child_product_id == 269 ) { | |
$quantity_field_value = 2; | |
} | |
if( $child_product_id == 271 ) { | |
$quantity_field_value = 5; | |
} | |
return $quantity_field_value; | |
} | |
add_filter( 'pewc_child_quantity', 'florian_child_quantity', 10, 3 ); | |
/** | |
* Ensure that your child products are pre-selected if the default quantity is greater than 0 | |
* You'll need to update the child product IDs here as well | |
*/ | |
function florian_default_product_column_value_before_checked( $value, $id, $item, $child_product_id ) { | |
if( in_array($child_product_id, array( 267, 269, 271 ) ) ) { | |
$value = $child_product_id; | |
} | |
return $value; | |
} | |
add_filter( 'pewc_default_product_column_value_before_checked', 'florian_default_product_column_value_before_checked', 10, 4 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment