Created
July 15, 2022 13:20
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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