skip to Main Content

I want to update WooCommerce products by the WP All import. I have 2 independent xml files (from the first one I’m getting prices, from the second one descriptions). For some reasons product’s _sku is {code} from the first one xml not {ean}. So I put {ean} into product attribute pa_ean to match the products from the first one and the second one xml.
Now I don’t know how to write the php function to return product_id so WP All import could update right products with right descriptions.

2

Answers


  1. Chosen as BEST ANSWER

    I put {ean} to Custom field, not to Attribute and after that I can easily use it in WP All import.


  2. Do you have any unique identifier that are same for the product in both files? Like product_key or something. If you have it you can store it as custom meta for that product and get product by that meta key, something like below ↓

    function check_if_product_exist($rawDataFromFile) {
            global $products;
    
            // Get WC_Product Objects
            $products = wc_get_products([
                'meta_key' => 'your_meta_key',
                'meta_value' => $rawDataFromFile->your_key
            ]);
    
            if (!empty($products)) {
                return $products[0];
            }
            return null;
        }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search