Skip to content

Instantly share code, notes, and snippets.

@koen12344
Created July 15, 2022 13:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save koen12344/7d1830fe086d6e87df1d34c4cfe85f7c to your computer and use it in GitHub Desktop.
Save koen12344/7d1830fe086d6e87df1d34c4cfe85f7c to your computer and use it in GitHub Desktop.
Snippet to bulk change the auto-post template for a selection of posts
<?php
function pgmb_batch_update_templates(){
$product_ids = get_posts([
'post_type' => 'product',
'fields' => 'ids',
'numberposts' => '-1',
]);
foreach($product_ids as $product_id){
$product = wc_get_product($product_id);
if(! $product instanceof \WC_Product){ continue; }
if ( $product->is_type( 'variable' ) ){
update_post_meta($product_id, '_pgmb_ap_template_id', 37272);
continue;
}
delete_post_meta($product_id, '_pgmb_ap_template_id');
}
}
add_action('init', 'pgmb_batch_update_templates');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment