Blog: WordPress
Ninja with sword

Change Return To Shop Link In WooCommerce

Avatar for John Locke

John Locke is a SEO consultant from Sacramento, CA. He helps manufacturing businesses rank higher through his web agency, Lockedown Design & SEO.

WordPress currently powers 24% of all websites. By a wide margin, the most popular e-commerce plugin on WordPress is WooCommerce. So it’s natural that you might to modify some of the user interface copy that comes with WooCommerce out of the box.

Recently, a reader asked how would you change the Return To Shop link on the Cart page. The text on some WooCommerce buttons can be changed with filters that you add to your functions.php file. But this particular button requires a different approach.

Much like WordPress itself, WooCommerce has a template structure. This means that certain files are called to assemble certain pages.

The templates that make up the Cart page in WooCommerce are found in the cart folder. Normally, the path to this folder (from the root of your WordPress installation) is: wp-content > plugins > woocommerce > templates > cart.

The specific file that controls the Return To Shop link is the cart-empty.php file.

What we want to do is override the default Return To Shop button text without losing the ability to update WooCommerce regularly, so we maintain functionality and security.

Luckily, WooCommerce gives you the ability to override any template file, by creating a folder (aka directory) named woocommerce within the theme folder you are currently using on your server. Next, create a folder inside of that folder named cart.

You’ll notice this mimics the folder structure of the WooCommerce plugin, except it omits the templates directory.

If the plugin directory structure is plugins > woocommerce > templates > cart > cart-empty.php then the structure for overriding that file will look like this: themes > your-theme > woocommerce > cart > cart-empty.php.

Finally, you’ll need to copy the current version of the cart-empty.php file, change the button text to your liking, and upload it into the woocommerce > cart location in your current theme folder.

You can find the original file cart-empty.php file either in the WooCommerce zip files or on the WooCommerce GitHub page.

Let’s say you want to change the Return To Shop button to read Continue Shopping instead.

Here’s what the original file looks like (as of version 2.3.13):


<?php
/**
 * Empty cart page
 *
 * @author  WooThemes
 * @package WooCommerce/Templates
 * @version 2.0.0
 */

if ( ! defined( 'ABSPATH' ) ) {
	exit; // Exit if accessed directly
}

wc_print_notices();

?>

<p class="cart-empty"><?php _e( 'Your cart is currently empty.', 'woocommerce' ) ?></p>

<?php do_action( 'woocommerce_cart_is_empty' ); ?>

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


Here’s what our override file would look like with the button text changed:


<?php
/**
 * Empty cart page
 *
 * @author  WooThemes
 * @package WooCommerce/Templates
 * @version 2.0.0
 */

if ( ! defined( 'ABSPATH' ) ) {
	exit; // Exit if accessed directly
}

wc_print_notices();

?>

<p class="cart-empty"><?php _e( 'Your cart is currently empty.', 'woocommerce' ) ?></p>

<?php do_action( 'woocommerce_cart_is_empty' ); ?>

<p class="return-to-shop"><a class="button wc-backward" href="<?php echo esc_url( apply_filters( 'woocommerce_return_to_shop_redirect', wc_get_page_permalink( 'shop' ) ) ); ?>"><?php _e( 'Continue Shopping', 'woocommerce' ) ?></a></p>


Things To Remember

Keep in mind that you’ll have to check this override file each time you upgrade WooCommerce to the latest version. As long as this file doesn’t change in WooCommerce core, you can leave it in place, but you’ll need to keep your eyes peeled each time a new version is released.

Avatar for John Locke

John Locke is a SEO consultant from Sacramento, CA. He helps manufacturing businesses rank higher through his web agency, Lockedown Design & SEO.

4 comments on “Change Return To Shop Link In WooCommerce

  1. Hi there and thanks for great article!
    Tell me please, how do I redirect the “wc_get_page_permalink( ‘shop’ )” to home page instead of the shop page?

    TNX!
    Asaf

    1. Hi Asaf:

      My apologies for taking so long to reply to this.

      So your question is, how do you redirect the default WooCommerce Shop page to the Home page when it is called by wc_get_page_permalink('shop')?

      So, it sounds like your use case is for the breadcrumbs on the individual product pages, or you only have one or two products, and they are on the Home page, and so the Shop page is redundant.

      The easiest way to change the default Shop page permalink is to go into WooCommerce > Settings > Products > Display and change the Shop page to the Home page. That would look like this:

      WooCommerce /> Settings > Products > Display, then set Shop page to Home, or whatever you want.” /></p><p>So if you had a WooCommerce breadcrumb that looked like this: <code>Home / Shop / Product Category / Single Product</code>,<br /> that would now look like this: <code>Home / Product Category / Single Product</code></p></div><div class=Reply

    1. Hi Matt:

      This tutorial is older, so the best thing to do is check the newest WooCommerce documentation. I know they’ve made several changes to the code base since this was originally published.

      Thanks,
      John

Join the Conversation

Your email address will be kept private. Required fields marked *.