How to automatically run the Re-Initialize Visibility Meta button after every import using WP All Import

Table Of Contents

    After importing your products using a third party plugin like WP All Import, your products are not re-saved in a traditional way like what is discussed in this article. If this happens, you just need to click the Re-initialize Product Visibility Meta on the Help tab of our Wholesale Price settings, to save the correct wholesale meta values in the database.

    However, some customers update their products more often, usually via a scheduled import using a CRON job. It will be difficult for them to keep manually clicking this button each time they import their products. So the best workaround for this is to use the snippet below to automatically run the re-initialize button each time an import is made.

    Please put this snippet on your theme/child theme’s functions.php:

    function wwpp_product_visibility_fix() {
        $wwpp = WooCommerceWholeSalePricesPremium::instance();
        $wwpp_wholesale_roles = WWPP_Wholesale_Roles::instance();
        $wwpp_wholesale_role_payment_gateway = WWPP_Wholesale_Role_Payment_Gateway::instance( array( 'WWPP_Wholesale_Roles' => $wwpp_wholesale_roles ) );
        $wwpp_bootstrap = WWPP_Bootstrap::instance( array(
            'WWPP_Wholesale_Roles' => $wwpp_wholesale_roles,
            'WWPP_Wholesale_Role_Payment_Gateway' => $wwpp_wholesale_role_payment_gateway,
            'WWPP_CURRENT_VERSION' => $wwpp::VERSION
        ) );
        $wwpp_bootstrap->initialize_product_visibility_filter_meta();
    }
    add_action( 'pmxi_after_xml_import', 'wwpp_product_visibility_fix' );
    

    Please note that this custom snippet is a filter for a function called ‘pmxi_after_xml_import’. It is a function from WP All Import, which means that the code should run after the importing of your products.

    If you’re using other third-party plugins, we suggest contacting the plugin author or ask a developer to provide further assistance regarding this snippet.