Snippet to delete products in FB catalog
-
Hello,
during the plugin configuration, I add a lot of product categories to be not added in the FB catalog. Otherwhise, they are all added. Before, I already added 40 products with a XML file. In this catalog, I find only these 40 products but not all them added by your plugin. But all products are in the FB shop of my page ! So, I found your snippet to delete products in the catalog. I added it in functions.php. But how can I launch it ?? Because all products are always displayed on the FB Shop page !Thanks a lot !
The code snippet added :function sv_wc_facebook_delete_all_products() { if ( ! function_exists( 'facebook_for_woocommerce' ) ) { return; } if ( get_option( 'sv_wc_facebook_delete_all_products', false ) || ! is_admin() ) { return; } $offset = (int) get_option( 'sv_wc_facebook_delete_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 ) { $product = wc_get_product( $product_id ); if ( $product ) { $retailer_ids[] = \WC_Facebookcommerce_Utils::get_fb_retailer_id( $product ); } facebook_for_woocommerce()->get_products_sync_handler()->delete_products( $retailer_ids ); } } // 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_delete_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_delete_all_products', 1 ); } } add_action( 'init', 'sv_wc_facebook_delete_all_products' );
Viewing 6 replies - 1 through 6 (of 6 total)
Viewing 6 replies - 1 through 6 (of 6 total)
- The topic ‘Snippet to delete products in FB catalog’ is closed to new replies.