Skip to content

Instantly share code, notes, and snippets.

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