What This PHP Code Does:
Adds a “Continue Shopping” button on the product page, cart page, and checkout page of your Woocommerce website so that users can easily get back to your store in order to continue shopping.
How To Implement:
Go to Appearance > Theme Editor or via FTP and open the functions.php file. At the very bottom add the below code. Then add the custom CSS for the button.
The PHP Code:
// Add continue shopping button to Single product page, Cart page and Checkout page.
/* Single product
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 ' Continue Shopping';
}
/* Cart
Add a ‘Continue Shopping’ Button to Woo Commerce Checkout and 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 ' Continue Shopping';
}
/* Checkout
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 ' Continue Shopping';
}
The CSS Code:
a.button.continue {
font-size: 20px;
font-weight: 500;
padding: 0.3em 1em;
line-height: 1.7em !important;
background: transparent;
position: relative;
border: 2px solid;
border-radius: 3px;
-webkit-transition: all 0.2s;
transition: all 0.2s;
}