Are you looking to uncheck the “Used for variations” option in WooCommerce programmatically? Here’s a quick guide on how to do this.
1 answers
1
Untick "Used for variations" in WooCommerce with PHP
In order to uncheck this, you need to load the page whilst calling the below PHP script.
$temp_array = get_post_meta( get_the_ID(), '_product_attributes', true );
$temp_array['pa_size']['is_variation'] = 0;
update_post_meta( get_the_ID(), '_product_attributes', $temp_array );
You could run this function, each time a user visits the product, as per the example below.
function wpza__untick_attribute_variation() {
if ( is_singular( 'product' ) ) {
$temp_array = get_post_meta( get_the_ID(), '_product_attributes', true );
$temp_array['pa_size']['is_variation'] = 0; // Change pa_size to your attribute name
update_post_meta( get_the_ID(), '_product_attributes', $temp_array );
wp_redirect( get_permalink( get_the_ID() ) );
die();
}
}
add_action( 'wp_head', 'wpza__untick_attribute_variation', 1 );
— Support WizardAnswer 1