PluginUs.Net - Business Tools for WooCommerce and WordPress

[realize your idea - make your dreams come true]

Support Forum

You need to log-in to create request (topic) to the support

Price Shortcodes Showing Incorrect Currency

The support doesn work on Saturdays and Sundays, so some Friday requests can be answered on Monday. If you have problems with registration ask help on contact us page please
If you not got email within 24~36 business hours, firstly check your spam box, and if no any email from the support there - back to the forum and read answer here. DO NOT ANSWER ON EMAILS [noreply@pluginus.net] FROM THE FORUM!! Emails are just for your info, all answers should be published only here.
The support doesn work on Saturdays and Sundays, so some Friday requests can be answered on Monday.

Hi Support,
We are successfully using your plugin on our website to geodetect visitor and shows correct currency on the website. We use USD currency as main and EUR as secondary. But we noticed an issue.
Your plugin supports to show product price with this shortcode [woocs_price id=12345] which is not sufficient for us because we also need to shows dynamic prices for discounted price, subscription prices and  currency. Thats why we created our own shortcodes which alows us to show these prices.

Here is the result with some css added: EUR: https://ibb.co/2Mfj3Xt USD: https://ibb.co/ftCCqzJ
And here is an example with discounted price provided as parameter: https://ibb.co/xYw3LqS
Trouble is that sometimes this happens: https://ibb.co/99yWP73 - our shortcodes show different currency as FOX detects.
This is normally and temporary resolved after clearing the page cache, but not always. We use LiteSpeed server with LiteSpeed wordpress plugin.

In our shortcodes we call wc_price(); and get_woocommerce_currency(); to get currency and we don't know why this sometimes doesn't show the same currency as FOX detects?

Below is code for all three shortcodes with screenshots.

Shortcode for discounted price:
Screenshot: https://ibb.co/MVxnnv9
Code:

Spoiler
// Add shortcode to display product price including custom discounted price
function AMPrice_shortcode($atts) {
// Extract shortcode attributes
$atts = shortcode_atts(array(
'id' => '',
'discounted_price' => '',
), $atts, 'AMPrice');

// Get product ID from shortcode attribute
$product_id = intval($atts['id']);

// Get product object
$product = wc_get_product($product_id);

// Check if product exists
if ($product) {
// Get regular price including tax
$regular_price = wc_get_price_including_tax($product);

// Get discounted price
if (!empty($atts['discounted_price'])) {
// Use custom discounted price if provided
$discounted_price = floatval($atts['discounted_price']);
} elseif ($product->is_on_sale()) {
// Use product's actual discounted price if on sale
$discounted_price = $product->get_price();
} else {
// Use regular price if not on sale and no custom discounted price provided
$discounted_price = $regular_price;
}

// Format regular price with class"AMPriceR" and strikethrough style
$formatted_regular_price = '<del class="AMPriceR">' . wc_price($regular_price, array('currency' => get_woocommerce_currency())) . '</del>';

// Format discounted price with class"AMPriceD"
$formatted_discounted_price = '<span class="AMPriceD">' . wc_price($discounted_price, array('currency' => get_woocommerce_currency())) . '</span>';

// Return formatted prices
return $formatted_regular_price . ' ' . $formatted_discounted_price;
} else {
return 'Product not found.';
}
}
add_shortcode('AMPrice', 'AMPrice_shortcode');

Shortcode for subscription price:
Screenshot: https://ibb.co/Dk5v5BB
Code:

Spoiler

add_shortcode('AMSubs_shortcode', 'cl_woo_product_price_shortcode');
function cl_woo_product_price_shortcode($atts) {
$atts = shortcode_atts(array(
'id' => null,
'discounted_price' => '', // Add support for discounted price attribute
), $atts, 'AMSubs_shortcode');

if (empty($atts['id'])) {
return ''; // Return empty string if ID is not provided
}

// Check if a discounted price is provided and if it's a valid number
if (!empty($atts['discounted_price']) && is_numeric($atts['discounted_price'])) {
return wc_price($atts['discounted_price']);
} else {
// Retrieve the product and its regular price if discounted price is not provided or invalid
$product = wc_get_product($atts['id']);

if (!$product) {
return ''; // Return empty string if product is not found
}

return wc_price($product->get_price()); // Return regular price
}
}

Shortcode to show currency:
Screenshot: https://ibb.co/fq07kxT
Code:

Spoiler

/*Show currency code*/
add_shortcode('AMCurrency_shortcode', 'current_currency_code_shortcode');
function current_currency_code_shortcode() {
// Get the current currency code
$currency_code = get_woocommerce_currency();

// Return the aligned text with the currency code
return '<div style="text-align: center; font-size:14px;">All prices in ' . $currency_code . '</div>';
}

Thank you in advance
Marty

Hello

Your custom price is cached.

Pay attention to the html prices - https://share.pluginus.net/image/i20240520122029.png - our plugin has the functionality of redrawing cached prices. But this functionality most likely will not suit your custom price

 

Thank you, I see the issue. Is there a way we could edit our shortcode so that the price won't get cached?

Hello

You can also implement the functionality as in our plugin. Checking and redrawing prices in Ajax mode

Could we call your plugin’s Ajax handler from our shortcode to fetch updated currency and price data? Also could we use your plugin’s JavaScript functions to dynamically redraw prices with our custom shortcodes?

Here is one of our shortest shortcodes for an example:
/* Show currency code */ add_shortcode('AMCurrency_shortcode', 'current_currency_code_shortcode'); function current_currency_code_shortcode() { $currency_code = get_woocommerce_currency(); return '<div style="text-align: center; font-size:14px;">All prices in ' . $currency_code . '</div>'; }

We want to ensure the displayed currency remains consistent with the currency detected by your plugin

Thank you

Our code will not work for you because you are using custom pricing

I understand. Is there a way we could use your plugin to properly show these discounted prices?

For an example we have a woocoommerce product with regular price 247€/$247 and we make a page in FunnelKit using this product but inside FunnelKit we set discounted price 197€/$197. Now if we use  your shortcodes [woocs_price] it will only show regular price 247€/$247. Is there a way to show discounted price using your plugin functionality?

Hello

In this case, this third party plugin should override (add a discount) to the standard function -  get_price_html()

Or you can use a hook -  woocs_price_shortcode  - https://share.pluginus.net/image/i20240527123736.png

Hi Pablo,

We’ve been trying to implement the suggestions you provided, but unfortunately, we haven’t had any success resolving the caching issues with our custom shortcodes. Would you be able to assist us in implementing a fix to handle these caching problems?

We’d like to continue using all three custom shortcodes (for discounted prices, subscription prices, and currency display) while ensuring the correct currency is shown consistently. We're also open to paying for this service if you can provide us with a quote.

Thank you, and I look forward to hearing from you.

Kind regards

Hello

I wrote to you in private data