Call Us Now at +1.403.536.9877 or fire us an email for a free quote

Blog

Welcome to Begin with B blog. You'll find news, update and web design tips depending on our moods and projects! Enjoy reading and feel free to post comments!

May 17, 2016
Posted by Bruno

After spending few hours trying to find a solution for this, I just came up with mine. 

I had a MotoPress slideshow that my client wanted edited so that instead of having the standard "bullet points" for browsing between slides, he actually gets the slides title as pagination.

My solution can work whatever the CMS: Joomla, Wordpress, Drupal or any other CMS. The only condition is that you already have some HTML tag used for pagination on your slideshow for browsing between slides.

Nov 05, 2015
Posted by Bruno

I wanted to show on the same website some products in Canadian dollars and some others in US dollars. By default you can't do that on WooCommerce. You have to choose which currency to display for the whole shop. There are some plugins that allow to switch between currencies but again that's for the whole shop. And my WooCommerce plugin is in Catalog mode so shopping cart currency is not an issue here.

I did not manage to find any hook to achieve this properly in the theme functions.php. I had then to modify some core WooCommerce files. Keep in mind that this method is not optimal as every time you will upgrade WooCommerce, your new edited files will be overwritten. Best way to achieve this would be to add extra field in your Woocommerce admin and display the currency depending on this field but I wanted to do something easy and simple.

To achieve the tweak, there are two files to edit.

Abstract-wc-product.php

/wp-content/plugins/woocommerce/includes/abstracts/abstract-wc-product.php

Look for the function:

function get_price_html

Replace

$price .= wc_price( $display_price ) . $this->get_price_suffix();

by

if ($this->post->ID == "2875") {
$price .= wc_price( $display_price,null,true) . $this->get_price_suffix();
}
else
{
$price .= wc_price( $display_price ) . $this->get_price_suffix();
}

where "2875" should be your product/post ID you want to display an alternative currency for. Obviously this file has to be edited each time you upload a new product in the alternative currency.

 

Wc-formatting-functions.php

/wp-content/plugins/woocommerce/includes/wc-formatting-functions.php

Look for 

function wc_price

We should add an argument to the function so just replace the header line by

function wc_price( $price, $args = array(), $usd = false ) {

Then look for this line:

$formatted_price = ( $negative ? '-' : '' ) . sprintf( $price_format, get_woocommerce_currency_symbol( $currency ), $price );

and replace it by

if ($usd==true){
$formatted_price = ( $negative ? '-' : '' ) . sprintf( $price_format, "USD$ ", $price );
}
else
{
$formatted_price = ( $negative ? '-' : '' ) . sprintf( $price_format, get_woocommerce_currency_symbol( $currency ), $price );
}

It will basically check if the $usd (you can call the variable anything of course) condition is met. Update the string "USD$ " to the alternative currency symbol you want to display and that's it! Trick's done. You'll now have some products in the main currency and some others showing up in the alternative currency. Happy tweaking!

Recent comments

  • Mark

    Bruno, I have a question, if instead of a single product, I have many products that differ from the original currency WooCommerce, as I add this option? Are there any plugin that allows this? Thank you
  • clark

    Gooooooooooooooooooooooooooooooooood
View other comments