Last active
March 2, 2022 18:21
-
-
Save tamarazuk/eeac6c9d06fa48c0ea134a969d5e3125 to your computer and use it in GitHub Desktop.
sv_wc_facebook_reset_all_products
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 // only copy this line if needed | |
function sv_wc_facebook_reset_all_products() { | |
if ( ! function_exists( 'facebook_for_woocommerce' ) ) { | |
return; | |
} | |
if ( get_option( 'sv_wc_facebook_reset_all_products', false ) || ! is_admin() ) { | |
return; | |
} | |
$offset = (int) get_option( 'sv_wc_facebook_reset_all_products_offset', 0 ); | |
$posts_per_page = 500; | |
do { | |
$products = get_posts( array( | |
'post_type' => 'product', | |
'post_status' => 'any', | |
'fields' => 'ids', | |
'offset' => $offset, | |
'posts_per_page' => $posts_per_page, | |
// uncomment and update the lines below to select specific taxonomy terms to update | |
// 'tax_query' => array( | |
// array( | |
// 'taxonomy' => 'product_cat', | |
// 'field' => 'term_id', | |
// 'terms' => array_merge( array( 849, 850, 851 ) ), | |
// ), | |
// ), | |
) ); | |
if ( ! empty( $products ) ) { | |
foreach ( $products as $product_id ) { | |
$integration = facebook_for_woocommerce()->get_integration(); | |
$integration->reset_single_product( $product_id ); | |
} | |
} | |
// increment offset | |
$offset += $posts_per_page; | |
// and keep track of how far we made it in case we hit a script timeout | |
update_option( 'sv_wc_facebook_reset_all_products_offset', $offset ); | |
} while ( count( $products ) == $posts_per_page ); // while full set of results returned (meaning there may be more results still to retrieve) | |
if ( count( $products ) !== $posts_per_page ) { | |
update_option( 'sv_wc_facebook_reset_all_products', 1 ); | |
} | |
} | |
add_action( 'init', 'sv_wc_facebook_reset_all_products' ); |
where i create file or post that code ?
function.php
https://developer.wordpress.org/themes/basics/theme-functions/#what-is-functions-php
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
where i create file or post that code ?