Skip to content

Instantly share code, notes, and snippets.

@bradleysa
Last active February 17, 2024 12:50
Show Gist options
  • Save bradleysa/7d1448253097784daf94 to your computer and use it in GitHub Desktop.
Save bradleysa/7d1448253097784daf94 to your computer and use it in GitHub Desktop.
WooCommerce: Add Continue Shopping Button on Cart Page
<?php
/**
* Add Continue Shopping Button on Cart Page
* Add to theme functions.php file or Code Snippets plugin
*/
add_action( 'woocommerce_before_cart_table', 'woo_add_continue_shopping_button_to_cart' );
function woo_add_continue_shopping_button_to_cart() {
$shop_page_url = get_permalink( woocommerce_get_page_id( 'shop' ) );
echo '<div class="woocommerce-message">';
echo ' <a href="'.$shop_page_url.'" class="button">Continue Shopping →</a> Would you like some more goods?';
echo '</div>';
}
@cookieweb
Copy link

Simple and works! Thanks for sharing.

@raoinam92
Copy link

Can you please tell me how I can this button on the Checkout page?

@Smyczek
Copy link

Smyczek commented Dec 14, 2017

For Cart & Checkout:

<?php
/**
* Add Continue Shopping Button on Cart Page & Checkout page
* Add to theme functions.php file or Code Snippets plugin
*/
add_action( 'woocommerce_before_cart_table', 'woo_add_continue_shopping_button_to_cart' );
add_action( 'woocommerce_before_checkout_form', 'woo_add_continue_shopping_button_to_cart' );

function woo_add_continue_shopping_button_to_cart() {
 $shop_page_url = get_permalink( wc_get_page_id( 'shop' ) );
 
 echo '<div class="woocommerce-message">';
 echo ' <a href="'.$shop_page_url.'" class="button">Continue Shopping →</a> Would you like some more goods?';
 echo '</div>';
}

@coachasymi
Copy link

Hi. Thanks for the code. Let's take it up a notch. How do you change the "Continue Shopping" URL instead of taking the user to the default Shop page, but to a different page, like Shop2 page?

@marjesch
Copy link

marjesch commented Jan 21, 2018

Excellent. Thank you for posting this. Very helpful. And Smyczek, thank you for your addition.

@tcolling
Copy link

Terrific. This is a big help. Thank you for posting this! 👍

@Bambinaros
Copy link

Thank you bradleysa, this has been very helpful. Is there a way to make the button get the search page with your last searched results, instead of just the search page, in both the Cart and Checkout pages? I've been looking everywhere and i can't seem to figure it out. Thnx again.

@smsnobin77
Copy link

Very helpful.

@msalep
Copy link

msalep commented May 3, 2018

Thank you so much! Worked like a charm!

@fencemaster
Copy link

This still works and is still useful - and appreciated - just so you know. Thanks. Raymond

@fecamposb
Copy link

Thank you so much!

I was looking for hours to this, and it worked perfectly!

@felixprojekt
Copy link

On Woocomerce higher than 3.0 this throws a notice, instead of woocommerce_get_page_id you can use wc_get_page_id to make it go away

@fadhilinsemwa
Copy link

thanx alot.

@stefaeva
Copy link

Fantastic!!! Thank's a lot :-)

@andre-vanrensburg
Copy link

Brilliant.

@antmid
Copy link

antmid commented Dec 22, 2018

Genius! Than you!

@stephanieangelabrauer
Copy link

Thank you so much :-)

@giacomoialenti
Copy link

Thanks a lot it is PERFECT!!!
Just one question is it possible to set the button just after the "APPLY COUPON" button?
Thank you in advance.
Giacomo

@Girlfoyle
Copy link

So, I put this in, and it adds the text but the link doesnt work? advice?

@jaychauhan2000
Copy link

this code is working nicely but the "continue shopping" button disappears when I click the "Update cart" button, Is there a way to fix it?

@fsask
Copy link

fsask commented Nov 19, 2019

Nice! Does exactly what it is supposed to do. Hard to believe that WooCommerce doesn't automatically add this functionality. Thank you so much!

@thewickedgrape
Copy link

Thanks so much for this!

I figured out how to change a couple of things:

  1. Custom Shop URL
  2. Move button to below the order summary
    woocommerce_after_cart_table instead of woocommerce_before_cart_table
  3. Restyled

/**

  • Add Continue Shopping Button on Cart Page
  • Add to theme functions.php file or Code Snippets plugin
    */

add_action( 'woocommerce_after_cart_table', 'woo_add_continue_shopping_button_to_cart' );

function woo_add_continue_shopping_button_to_cart() {
$shop_page_url = home_url( '/negozio/' );

echo '

';
echo ' prosegui con gli acquisti';
echo '
';
}

@talaljavedd
Copy link

Worked perfect, Thank you 😍👌

@btxaja
Copy link

btxaja commented Sep 30, 2020

Its Works

@computermobil
Copy link

That works perfect. Thank you very much for this snippet!

@noellesteegs
Copy link

Still works like a charm. :)

@photoMaldives
Copy link

Thanks ! Still good in 2021.
I'm no coder, but tweaked this slightly - plain button underneath cart, plus 'message' button above checkout.

/**
* Add Continue Shopping Button on Cart (& checkout) Page
*/

add_action( 'woocommerce_after_cart_table', 'woo_add_continue_shopping_button_to_cart' );

function woo_add_continue_shopping_button_to_cart() {
 $shop_page_url = get_permalink( woocommerce_get_page_id( 'shop' ) );
 
 echo '<div class="">';
 echo ' <a href="'.$shop_page_url.'" class="button">Continue Shopping</a>';
 echo '</div>';
}

add_action( 'woocommerce_before_checkout_form', 'woo_add_continue_shopping_button_to_checkout' );

function woo_add_continue_shopping_button_to_checkout() {
 $shop_page_url = get_permalink( wc_get_page_id( 'shop' ) );
 
 echo '<div class="woocommerce-message">';
 echo ' <a href="'.$shop_page_url.'" class="button">Continue Shopping</a> Not finished shopping ?';
 echo '</div>';
}

@paaljoachim
Copy link

Thank you for the code @bradleysa and the update @photoMaldives

I went ahead and adjusted based on a bunch of various resources.

// Add continue shopping button to Single product page, Cart page and Checkout page.

/* Single product
https://www.businessbloomer.com/woocommerce-continue-shopping-button-single-product-page/
https://www.businessbloomer.com/woocommerce-visual-hook-guide-single-product-page/ */

add_action( 'woocommerce_after_add_to_cart_button', 'continue_shopping_button_to_single_product' );
function continue_shopping_button_to_single_product() {
 $shop_page_url = get_permalink( woocommerce_get_page_id( 'shop' ) );
 echo ' <a class="continue button" href="'.$shop_page_url.'">Continue Shopping</a>';

}

/* Cart
https://wpbeaches.com/add-continue-shopping-button-woo-commerce-cart-page/
https://www.tychesoftwares.com/woocommerce-cart-page-hooks-visual-guide-with-code-examples/ */

add_action( 'woocommerce_cart_actions', 'continue_shopping_button_to_cart' );
function continue_shopping_button_to_cart() {
 $shop_page_url = get_permalink( woocommerce_get_page_id( 'shop' ) );
 echo ' <a class="continue button" href="'.$shop_page_url.'">Continue Shopping</a>';

}

/* Checkout
https://www.businessbloomer.com/woocommerce-visual-hook-guide-checkout-page/ 
https://gist.github.com/bradleysa/7d1448253097784daf94 */

add_action( 'woocommerce_review_order_before_submit', 'continue_shopping_button_to_checkout' );
function continue_shopping_button_to_checkout() {
 $shop_page_url = get_permalink( wc_get_page_id( 'shop' ) );
echo ' <a class="continue button" href="'.$shop_page_url.'">Continue Shopping</a>';

}

CSS class continue button:

a.button.continue {
	background-color: var(--wp--preset--color--primary) !important;
	padding: 0.8rem 1rem !important;
        border: 2px solid #ebe9eb !important;
        margin: 0;
	color: #fff !important;
}

I noticed I had to add in the !important tag on most of the code to get it to work.
I am tested with the theme Twenty Twenty Two.

Let me know of any adjustments that would be helpful to do.

@nootkan
Copy link

nootkan commented Apr 8, 2022

Thanks ! Still good in 2021. I'm no coder, but tweaked this slightly - plain button underneath cart, plus 'message' button above checkout.

/**
* Add Continue Shopping Button on Cart (& checkout) Page
*/

add_action( 'woocommerce_after_cart_table', 'woo_add_continue_shopping_button_to_cart' );

function woo_add_continue_shopping_button_to_cart() {
 $shop_page_url = get_permalink( woocommerce_get_page_id( 'shop' ) );
 
 echo '<div class="">';
 echo ' <a href="'.$shop_page_url.'" class="button">Continue Shopping</a>';
 echo '</div>';
}

add_action( 'woocommerce_before_checkout_form', 'woo_add_continue_shopping_button_to_checkout' );

function woo_add_continue_shopping_button_to_checkout() {
 $shop_page_url = get_permalink( wc_get_page_id( 'shop' ) );
 
 echo '<div class="woocommerce-message">';
 echo ' <a href="'.$shop_page_url.'" class="button">Continue Shopping</a> Not finished shopping ?';
 echo '</div>';
}

Everything I've tried from this thread works but I was wondering how to keep the button on the cart page the same way but have "continue shopping" show in the "have a coupon click here to enter your code" button instead of below it like the code above has it?

@sadhonKumar
Copy link

Awesome!!!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment