Skip to content

Instantly share code, notes, and snippets.

@petrusnog
Created July 20, 2020 22:36
Show Gist options
  • Select an option

  • Save petrusnog/da614fda6eb4289d0d2457f62d65908f to your computer and use it in GitHub Desktop.

Select an option

Save petrusnog/da614fda6eb4289d0d2457f62d65908f to your computer and use it in GitHub Desktop.
Script that set all Woocommerce's "Product Visibility" to "Hidden"
<?php
$args = array(
"post_type" => "product",
"posts_per_page" => -1,
);
$post_query = new WP_Query($args);
if ( $post_query->have_posts() ) {
while ( $post_query->have_posts() ) { $post_query->the_post();
wp_set_post_terms(
get_the_ID(),
array(
"exclude-from-catalog",
"exclude-from-search"
),
"product_visibility"
);
echo "<h2>" . get_the_title() . "</h2><br><pre>";
print_r(get_terms("product_visibility")) . "</pre>";
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment