• Resolved italodamato

    (@italodamato)


    I’m having some sync issues like many here. I’ve tried to run your script to delete all products but it’s not doing anything. I’ve also tried some variations (see below), but still nothing. Can you please provide an alternative way to delete the FB catalog and start fresh? Thanks.

    function sv_wc_facebook_delete_all_products() {
    	debug_to_console('starting');
    
    	if ( ! function_exists( 'facebook_for_woocommerce' ) ) {
    		return;
    	}
    
    	if ( get_option( 'sv_wc_facebook_delete_all_products', false ) || ! is_admin() ) {
    		return;
    	}
    	debug_to_console('starting conditions met');
    
    	$products = get_posts( array(
    		'post_type'      => array('product','product_variation'),
    		// 'post_type'      => 'product',
    		// 'post_status'    => 'any',
    		'fields'         => 'ids',
    		'posts_per_page'    => -1,
    		// 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 ) ),
    		// 	),
    		// ),
    	) );
    
    	debug_to_console($products);
    	if ( ! empty( $products ) ) {
    		debug_to_console('starting deletion');
    
    		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_integration()->reset_single_product( $product_id );
    				facebook_for_woocommerce()->get_integration()->delete_fb_product( $product );
    			}
    		}
    		// debug_to_console($retailer_ids);
    		
    		// facebook_for_woocommerce()->get_products_sync_handler()->delete_products( $retailer_ids );
    	}
    
    	update_option( 'sv_wc_facebook_delete_all_products', 1 );
    	debug_to_console('completed');
    }
    add_action( 'init', 'sv_wc_facebook_delete_all_products' );
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
  • The topic ‘How to delete all products’ is closed to new replies.