I’m trying to update max quantity for all variations of my variable product to ie 345.
$available_variations = $product->get_available_variations();
foreach ($available_variations as $variation)
{
$variation_ID = $variation->ID;
update_post_meta( $variation_ID , 'max_qty', 345 );
}
It doesn’t happen.
2
Answers
Why not set it to 345 by default?
OR
Since it’s an online shop why not use MySQLi? It’s PHP powered so why not?
this way you can do MySQLi->query, and UPDATE the value.
Edited
You are not using the correct way to get the variation ID and the product meta key
max_qty
doesn’t exist in WooCommerce database onwp_postmeta
table forproduct_variation
post type.Instead you can use the following filter hook to set a specific maximum quantity to product variations:
Code goes in functions.php file of your active child theme (or active theme). Tested and work.