Skip navigation
Sun Mon Tue Wed Thu Fri Sat
12:00 – 20:00 12:00 – 20:00 12:00 – 20:00 12:00 – 20:00 12:00 – 20:00 - -
- - - - - - -

Часовой пояс сторонника: Asia/Karachi (GMT+05:00)

Эта тема содержит 0 ответов, имеет 1 голос.

Последнее обновление: katerinaK 1 месяц назад.

При содействии: Noman.

Автор Записи
20 августа, 2024 на 9:24 дп #16086250

katerinaK

Background of the issue:
Hello, we recently started using the plugin Mergado Pack to generate feed of our products for various ecommerce platforms. Unfortunately we noticed that the feed sometimes contains prices in EUR instead of CZK which is our default (and intended) currency for the feeds. Mergado doesn't support WCML, so it's my turn to resolve this problem. The feed is generated either manually by accessing a specific URL, or by WP Cron. It seems that when the feed is generated using the cron job, the currencies get mixed up. The easiest solution I could think of was to override the prices by specifying the currency manually using a filter. Mergado exposes a filter called `mergado_product_feed__product` that I can use to override the prices. It is actually kinda simple, so after some research I came up with the following code which I placed inside `functions.php`. It seems to work fine while testing this locally but I am not sure whether it will work with the cron job since I don't understand how `wcml_convert_price` will work when e.g. `wc_get_price_excluding_tax($product, $price_args)` returns the price in EUR. Will it correctly convert the price to CZK?:

function mergado_fix_product_price(MergadoFeedProductProductFeedItem $feed_item, WC_Product $product) {
$feed_currency = 'CZK';
$price_args = ['qty' => 1];
$feed_item->setCurrency($feed_currency);

if($product->is_on_sale()) {
$price_args['price'] = $product->get_sale_price();
$feed_item->setPriceDiscount(wcml_convert_price(wc_get_price_excluding_tax($product, $price_args), $feed_currency));
$feed_item->setPriceDiscountVat(wcml_convert_price(wc_get_price_including_tax($product, $price_args), $feed_currency));
}

$price_args['price'] = $product->get_regular_price();
$feed_item->setPrice(wcml_convert_price(wc_get_price_excluding_tax($product, $price_args), $feed_currency));
$feed_item->setPriceVat(wcml_convert_price(wc_get_price_including_tax($product, $price_args), $feed_currency));

return $feed_item;
}

add_filter("mergado_product_feed__product", "mergado_fix_product_price", 10, 3);

Additionally, converting each of the prices manually looks a bit too complicated. Isn't there something easier I could do, to kinda force WCML to always use CZK prices when the feed is generated? And if not, isn't there a way to get the discounted/not discounted VAT included/excluded prices already in the CZK currency?

Symptoms:
The feed sometimes contains prices in EUR instead of CZK, especially when generated using the cron job.

Questions:
Will the provided code correctly convert the price to CZK when `wc_get_price_excluding_tax($product, $price_args)` returns the price in EUR?
Is there an easier way to force WCML to always use CZK prices when the feed is generated?
Is there a way to get the discounted/not discounted VAT included/excluded prices already in the CZK currency?

Тема '[Закрытые] WCML Prices during Mergado Product Feed generation' закрыта для новых ответов.