Skip to content

Instantly share code, notes, and snippets.

@imfromio
Last active October 2, 2019 13:53
Show Gist options
  • Save imfromio/f8d60b8d1affd29aa65e04058e1a5f6b to your computer and use it in GitHub Desktop.
Save imfromio/f8d60b8d1affd29aa65e04058e1a5f6b to your computer and use it in GitHub Desktop.
WooCommerce - bulk update all product's attributes
<?php
// limit number of products for each run to not overburden the server
$args = array(
'limit' => 10,
'offset' => 0,
'return' => 'ids',
);
$product_ids = wc_get_products( $args );
// loop through products
foreach ( $product_ids as $product_id ) :
// get product attributes from post meta
$atts = get_post_meta( $product_id, '_product_attributes', true );
// loop through product attributes
foreach ( $atts as $key => $value ) {
$att_name = $value['name'];
// set each attribute visibility to 1
$atts[$att_name]['is_visible'] = 1;
}
// update post meta
update_post_meta( $product_id, '_product_attributes', $atts );
endforeach;
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment