• Resolved danina84

    (@danina84)


    Hi,
    I am only selling a single product, so I don’t need the “category” or product archive page. In my main navigation menu, I added the single product page and called it “shop”. I deleted the “shop” page that Woocommerce creates by default since this is the product archive page.
    Everything is working so far, but when you visit the shopping cart and it is empty(or when you empty it manually), the button “Return to shop” shws up and doesn’t redirect you to the single product page. It just stays on the cart page. So my question: How can I redirect the “Return to shop” button directly to the single product page?

    Thank you!

    https://wordpress.org/plugins/woocommerce/

Viewing 14 replies - 1 through 14 (of 14 total)
  • In

    /wp-content/plugins/woocommerce/templates/cart/cart-empty.php

    <p class="return-to-shop"><a class="button wc-backward" href="<?php echo apply_filters( 'woocommerce_return_to_shop_redirect', get_permalink( wc_get_page_id( 'shop' ) ) ); ?>"><?php _e( 'Return To Shop', 'woocommerce' ) ?></a></p>

    to

    <p class="return-to-shop"><a class="button wc-backward" href="/your-desired-page/"><?php _e( 'Return To Shop', 'woocommerce' ) ?></a></p>

    Thread Starter danina84

    (@danina84)

    Hi,
    do I need to create a “template” directory in my “woocommerce” directory and in this template directory another “cart” directory with the cart-empty file? Or just a cart directory with the cart-empt file in the woocommerce directory?
    To clarify: Do I need to create this:
    /wp-content/themes/my_child_theme/woocommerce/templates/cart/cart-empty.php

    or

    /wp-content/themes/my_child_theme/woocommerce/cart/cart-empty.php

    Thanks!

    Plugin Contributor royho

    (@royho)

    Hi, so a better way to do it is put the following code into your child theme’s functions.php file.

    add_filter( 'woocommerce_return_to_shop_redirect', 'return_to_shop_link' );
    
    function return_to_shop_link() {
         return 'http://yourlink'; // change to the link you want
    }

    This way you’re not modifying any template files at all and is totally update safe.

    Thread Starter danina84

    (@danina84)

    Hi Roy Ho,
    okay, I will try this, just a question(sorry but I am a total newbie…):
    Do I just copy the code you gave me into m functions.php file or do I need to write anything else above it? I noticed the fuctions file always starts with <?php .

    Thanks!

    Plugin Contributor royho

    (@royho)

    It needs to be within <?php but don’t add more if it already has them.

    Go with Roy Ho, however you must edit in any notepad editor so that if you face any issues with your mistake you can always undo it.

    Thread Starter danina84

    (@danina84)

    Thank you guys, it worked!!

    bingtx

    (@bingtx)

    You can make this change with out any additional code.

    Just go into Woocomerce setting > products > display

    And assign which ever page you want the “return to shop” button to go to as the “shop” page.

    bingtx, Thanks for providing this simple and easy solution! I didn’t want to make changes to the PHP code and try and mess around that. I had made some changes to my cart and I had accidentally left the information under WooCommerce > Products > Display > Shop Page blank! After I entered it, everything worked perfectly! Thanks!

    Does anyone know how to change the Return to Shop button Text? It says “Return to Shop” how could I change the button so it says something else “Return to Products”?

    I have a shop page whose url goes like :http://wordpress/catalogue
    And I have created a product category page and called it another shop page.Its url is http://localhost/wordpress/product-category/category1
    Now on the single product page; if I am coming from the catalogue page, on click of “Back to Catalogue”; I am redirected to catalogue page which is correct.
    But if I come to the single product page from the product category/category1 page then the still the click of “Back to Catalogue” link redirects me to the catalogue page. Actually, it should have been the category 1 page.
    How do I achieve this?

    I have found a cart-empty.php code in which it has the following piece of code which reads:

    “><?php _e( ‘Return To Shop’, ‘woocommerce’ ) ?>

    How am I supposed to go about making the redirection?

    Please guide.

    I got the solution
    In my functions.php i wrote this piece of code:

    /**
     * Changes the redirect URL for the Return To Shop button in the cart.
     *
     * @return string
     */
    function wc_empty_cart_redirect_url() {
    	return 'javascript:history.go(-1)';
    }
    add_filter( 'woocommerce_return_to_shop_redirect', 'wc_empty_cart_redirect_url' );

    And then included this filter in cart-empty.php as below:

    <p class="return-to-shop"><a class="button wc-backward" href="<?php echo apply_filters( 'woocommerce_return_to_shop_redirect', wc_empty_cart_redirect_url ); ?>"><?php _e( 'Return To Shop', 'woocommerce' ) ?></a></p>

    You can redirect the shop page to another page so if someone lands on it by mistake or types in the url they are still redirected.

    function shoppage_redirect()
    {
        if( is_shop( ))
        {
            wp_redirect( home_url( '/page_slug' ) );
            exit();
        }
    }
    add_action( 'template_redirect', 'shoppage_redirect' );

    BingTX is right.. You have to configure it in the control panel in order for it to work. Woo should have preconfigured it and left the option for customization. They also won’t add a gallery because there are plugins and they also won’t add a sign up on front page and an option to cancel out personal info for downloads because there are plugins.

    Woo! That was a lot to say.

Viewing 14 replies - 1 through 14 (of 14 total)
  • The topic ‘Redirecting "Return to shop" button’ is closed to new replies.