Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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