Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #882592

    using a code snippet in the function.php file i added custom button to woocommerce product pages
    it looks like this

    // add "back to shop" button to single product pages
    function add_custom_single_button(){
    ?>
    <script>
    jQuery(window).load(function(){
    var r= jQuery('<a class="second-button" href="https://www.mysite.com/shop/">Return to the shop</a>');
            jQuery("button.single_add_to_cart_button").after(r);
    });
    </script>
    <?php
    }
    add_action('wp_footer', 'add_custom_single_button'); 

    and it worked perfectly
    problem is now i have two different languages in the website (English and Hebrew)
    and i’m not sure how to deal with this button
    I don’t wont to remove it but it always directs to the original Hebrew shop, even when it appears in the pages of the English shop
    ..is there a way to modify the function so each languages will have it’s own button text and URL?
    (obviously i installed WPML and it’s doing it’s thing but this button text and URL are out of the plugin translation reach)

    #883461

    Shalom Doron,

    Please try changing the code to following

    // add "back to shop" button to single product pages
    function add_custom_single_button(){
    ?>
    <script>
    jQuery(window).load(function(){
    var r= jQuery('<a class="second-button" href="https://www.mysite.com/shop/">Return to the shop</a>');
    var h= jQuery('<a class="second-button" href="https://www.mysite.com/shop/">Return to the shop in Hebrew</a>');
            jQuery("html[lang='en-US'] button.single_add_to_cart_button").after(r);
            jQuery("html[lang='he-IL'] button.single_add_to_cart_button").after(h);
    });
    </script>
    <?php
    }
    add_action('wp_footer', 'add_custom_single_button'); 

    If that does not work, please create a temporary admin login and post it here privately :)

    Best regards,
    Yigit

    • This reply was modified 7 years ago by Yigit.
    #884970

    Hi!
    sorry it took me so long to respond (for some reason i didn’t get any email notification)
    anyway – it works! like a charm!
    thank you so much!

    #885021

    Hi,

    Glad to hear that. Thanks for using Enfold :)

    Best regards,
    Nikko

Viewing 4 posts - 1 through 4 (of 4 total)
  • The topic ‘change a custom woocommerce button to work with two different languages’ is closed to new replies.