Created
February 24, 2025 16:21
-
-
Save woogists/a8acd17f491a82dfbc23b953c467e8c8 to your computer and use it in GitHub Desktop.
Use this snippet to set a default quantity for a component of a composite product.
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 | |
/* | |
Use this snippet to set a default quantity for a component of a composite product. | |
Before using this snippet, replace 1234 with the ID of the component for which you’d like to set a default quantity. | |
You can find the ID of each component by: navigating to Product Data > Components and hovering over a specific component | |
*/ | |
add_filter( 'woocommerce_composited_product_quantity', 'sw_wc_cp_set_default_quantity', 10, 6 ); | |
function sw_wc_cp_set_default_quantity( $default_quantity, $quantity_min, $quantity_max, $product, $component_id, $composite_product ) { | |
if ( $component_id === '1234' ) { | |
$default_quantity = 5; | |
} | |
return $default_quantity; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment