shvsh > /home/1168859.cloudwaysapps.com/rcyqmhwrmv/public_html/docs/wp-content/plugins/ht-knowledge-base/ht-knowledge-base.php
shvsh > /home/1168859.cloudwaysapps.com/rcyqmhwrmv/public_html/docs/wp-content/plugins/ht-knowledge-base/ht-knowledge-base.php
shvsh > /home/1168859.cloudwaysapps.com/rcyqmhwrmv/public_html/docs/wp-content/plugins/ht-knowledge-base/ht-knowledge-base.php

Is it possible & how to enable importing of all the products with the same SKU at once?

  • If you are using some plugin to translate your products to multiple languages.
  • Hence in such scenarios adding the same CSP rules to all the translated copies will be required.
  • If the same SKU is assigned to all the translated copies.
  • The following hook can be used to replicate the rule for all of the translated copies during an import.

“wdm_check_for_product_translations”

  • The following example will demonstrate how you can use this hook to import the same rule for all the products having the same SKU.(WPML)
add_filter('wdm_check_for_product_translations', 'wdmWPMLTranslations', 99, 2);

function wdmWPMLTranslations($status, $productId) {
    /**
     * function_exists('icl_object_id') is used to check if WPML is active
     */
    if (empty($productId) || $productId<=0 || !function_exists('icl_object_id')) {
        return false;
    }

    /**
     * Add the WPML language codes of the languages you are using on your site
     * to the following array $langArray
     */
    $langArray        = array('hi', 'nl');

    $translationIds = array();
    foreach ($langArray as $language) {
        $langId        = apply_filters( 'wpml_object_id', $productId, 'product', true, $language);
        if ($langId !== $productId) {
            $translationIds[] = $langId;
        }
    }

    if (!empty($translationIds)) {
        return $translationIds;
    }

    return false;
}
  • The function above “wdmWPMLTranslations” returns all the related product ids to the current product hence, the same rules get imported for all those translated products.

Updated on November 17, 2020
shvsh > /home/1168859.cloudwaysapps.com/rcyqmhwrmv/public_html/docs/wp-content/plugins/ht-knowledge-base/ht-knowledge-base.php
shvsh > /home/1168859.cloudwaysapps.com/rcyqmhwrmv/public_html/docs/wp-content/plugins/ht-knowledge-base/ht-knowledge-base.php
shvsh > /home/1168859.cloudwaysapps.com/rcyqmhwrmv/public_html/docs/wp-content/plugins/ht-knowledge-base/ht-knowledge-base.php

Was this article helpful?

shvsh > /home/1168859.cloudwaysapps.com/rcyqmhwrmv/public_html/docs/wp-content/plugins/ht-knowledge-base/ht-knowledge-base.php
shvsh > /home/1168859.cloudwaysapps.com/rcyqmhwrmv/public_html/docs/wp-content/plugins/ht-knowledge-base/ht-knowledge-base.php

Related Articles