Update category min-max

mail@pastecode.io avatar
unknown
php
3 years ago
658 B
2
Indexable
$products = get_posts(
	array(
		'post_type' => 'product',
		'posts_per_page' => -1,
		'post_status' => 'publish',
		'tax_query' => array(
			array(
				'taxonomy' => 'product_cat',
				'field' => 'term_id',
				'terms' => 16, // give your expected category id here
			)
		)
	)
);

if ( is_array( $products ) && count( $products ) > 1 ) {
	foreach ( $products as $product ) {
		$product_id = $product->ID;
		if ( get_post_meta( $product_id, '_wc_min_max_quantities_override', true ) ) {
			update_post_meta( $product_id, '_wc_min_max_quantities_override', 'yes' );
		}
		var_dump( get_post_meta( $product_id, '_wc_min_max_quantities_override', true ) );
	}
}