Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • #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!
    Keith

    #535713

    Any thoughts?

    #536804

    Hi!

    Not sure what it could be. Are all plugins updated? You have this one installed correct? https://wordpress.org/plugins/woocommerce-multilingual/

    Cheers!
    Elliott

    #537060

    Hi 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).

    #538893

    Hey!

    wp login does not work for me. Can you check please?

    Cheers!
    Andy

    #539285

    Sorry 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;
    }
    
    #539432

    Hi!

    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

Viewing 7 posts - 1 through 7 (of 7 total)
  • You must be logged in to reply to this topic.