1
votes

for my woocommerce e-shop i use WpAllImport plugin for importing my products with their variations. Typically one product with the variations is shown below enter image description here The parent product has no price/sale price values and the price/sale price values are all the same for all variations. Now i want to export an xml file with only my parents products with WpAllExport plugin. As there is no price/sale price values the tag <price> </price> and <sale price> </sale price>is return empty with no values. I realise that i need php function for the export to pass any variation price/sale price to parent product price fields. Does someone help me with the php function i have to write?

Thank you in advance

1

1 Answers

1
votes

OK, finally I add the following code and it works fine.

<?php
function get_regular_price_for_xml($parent, $price)
{
    if ($parent == "0") {
        global $product;
        $product_variations = $product->get_available_variations();
        if (!empty($product_variations) && is_array($product_variations)) {
            $variation_product_id = $product_variations[0]['variation_id'];
            $variation_product = new WC_Product_Variation($variation_product_id);
            return $variation_product->regular_price;
        } else {
            return $price;
        }
    } else {
        return $price;
    }
}