Created
January 30, 2024 10:04
-
-
Save koen12344/52f11d249ee6fd8ac26723bf52d5e8f5 to your computer and use it in GitHub Desktop.
Clear references to uploaded images in the Product Sync for GBP
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 | |
/* | |
* Clears Product Sync for GPB image references on Google and forces re-upload | |
* | |
* Copy snippet into the Code Snippets plugin (https://wordpress.org/plugins/code-snippets/) and set it to only run once, then execute it | |
* | |
*/ | |
function psfg_clear_all_image_references(){ | |
$args = [ | |
'post_type' => 'product', | |
'post_status' => 'publish', | |
'posts_per_page' => -1, | |
'fields' => 'ids', | |
]; | |
$post_ids = get_posts($args); | |
foreach($post_ids as $post_id){ | |
$created_posts = get_post_meta($post_id, '_psfg_created_products', true); | |
if(!empty($created_posts) && is_array($created_posts)){ | |
foreach($created_posts as $created_post){ | |
unset( $created_post->image); | |
} | |
} | |
update_post_meta($post_id, '_psfg_created_products', $created_posts); | |
} | |
} | |
add_action('init', 'psfg_clear_all_image_references'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment