Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Snippet to bulk change the auto-post template for a selection of posts
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);
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