Search code examples
wordpressmobilewoocommerceback-button

Woocommerce Back Button Not Working


I'm adding code below for back button. add_action('woocommerce_before_main_content', 'backbutton', 5); function backbutton() { echo ' Back '; }

But I'm not able to click the back button on mobile version. Is there any solutions?


Solution

  • You've added the text 'back' not a back button. You could put in something like this:

    add_action('woocommerce_before_main_content', 'backbutton', 5); 
    function backbutton() {
        echo ' <button type="button" onclick="history.back();"> Back </button> ';
    }
    

    This will output a back button similar to the back button in the browser.

    BUT this is not good practice. If a client comes from google to the product page the clicks this back button they will go back to google, you don't want that, you want them to stay on your site. if your shop's url was https://example.com/shop then you could put the following:

    add_action('woocommerce_before_main_content', 'backbutton', 5); 
    function backbutton() {
        echo ' <a href="https://example.com/shop"> Back to store </a> ';
    }