Tagged: Currency, woocommerce, wpml
-
AuthorPosts
-
November 10, 2015 at 8:02 pm #533635
Hello there,
I am running WPML & Woocommerce for an international store. We list our products with Google Shopping and they have a requirement that the URL defaults to the specific currency for the country the ad is place in. This is not possible directly from WPML because their currency switcher requires you to select it from a menu once on the site. Bruno from WPML support has a solution that can be found here:
The fix uses this code in the Functions.php file in my child theme:
add_action( 'wcml_client_currency', 'currency' ); function currency( $current_currency ) { global $woocommerce,$sitepress; $currency = isset( $_GET['price'] ) ? esc_attr( $_GET['price'] ) : $current_currency; $currency = strtoupper( $currency ); $woocommerce->session->set('client_currency', $currency); return $currency; }
This works perfectly for me for the feature I need but breaks other parts of WPML & Woocommerce. It works fine in 2012, 2013 but breaks when I active Enfold. For instance, when listing products in WP-Admin, the price column shows this error for a variable product :
Fatal error: Call to a member function set() on a non-object in /nas/wp/www/staging/medafore/wp-content/themes/Enfold-Child-Theme-Template/functions.php on line 13
Line thirteen is this from the code above:
$woocommerce->session->set('client_currency', $currency);
It also stops me from saving WPML settings from the WPML admin area.
Any thoughts why this works in 2012 but not Enfold?
Thanks!
KeithNovember 13, 2015 at 8:30 pm #535713Any thoughts?
November 16, 2015 at 6:51 pm #536804Hi!
Not sure what it could be. Are all plugins updated? You have this one installed correct? https://wordpress.org/plugins/woocommerce-multilingual/
Cheers!
ElliottNovember 17, 2015 at 4:01 am #537060Hi Elliott,
Yes, WordPress, Enfold and all plugins are updated and Woocommerce multilingual is installed. I have a staging area for you to look at (see private details).
November 19, 2015 at 11:56 am #538893Hey!
wp login does not work for me. Can you check please?
Cheers!
AndyNovember 20, 2015 at 12:22 am #539285Sorry about that, I refreshed the staging site and forgot to add your login back in. Its there now if you’d like to see the problem.
That said, I put a ticket in with WPML and they have a solution that seems to be working. They added an if statement excluding the code if you’re logged in. Not sure why it works differently in Enfold than a default theme, but it does fix the problem.
The new code:
if(!is_admin()) { add_action( 'wcml_client_currency', 'currency' ); } function currency( $current_currency ) { global $woocommerce,$sitepress; $currency = isset( $_GET['price'] ) ? esc_attr( $_GET['price'] ) : $current_currency; $currency = strtoupper( $currency ); $woocommerce->session->set('client_currency', $currency); return $currency; }
November 20, 2015 at 11:28 am #539432Hi!
glad you have a solution now and thanks for sharing the code with us.
Let us know in a new ticket if you have some more questions about the theme. We are happy to assist you.
Best regards,
Andy -
AuthorPosts
- You must be logged in to reply to this topic.