AI Verified

Name

merge Woocommerce cart with woocommerce checkout

About

Merging the Woocommerce cart with the woocommerce checkout page in 4 steps. Much more userfriendly! Credit goes to @wpsimplehacks on youtube. Brilliant channel

Language

PHP

Rating

Voted: 1 by 1 user(s)

How to Setup Snippet

## Step 1: Merge Woocommerce cart and checkout page In this step we’re going to add a Woocommerce cart table above the checkout table Thus, grab this code here below and add it inside your child theme’s functions.php file or better yet, use [Code Snippets](https://wordpress.org/plugins/code-snippets/) plugin for it. There is nothing to configure, just paste it as it is. // 1. Add Woocommerce cart page on the checkout page add_action( 'woocommerce_before_checkout_form', 'add_cart_on_checkout', 5 ); function add_cart_on_checkout() { if ( is_wc_endpoint_url( 'order-received' ) ) return; echo do_shortcode('[woocommerce_cart]'); // Woocommerce cart page shortcode } ## Step 2: Redirect Woocommerce cart page to checkout page This part is optional and use it if you don’t want the “View cart” buttons to direct your users to cart page. Also, use it if you don’t want your users to access Woocommerce cart page directly. So, grab this code and add it to you functions.php file or Code Snippets code box. Pay attention that “cart” and “/checkout/” parts are your cart and checkout pages slugs. If you have any other slugs (karte or kassa for example) then change them accordingly. // 2. Redirect cart page to checkout add_action( 'template_redirect', function() { // Replace "cart" and "checkout" with cart and checkout page slug if needed if ( is_page( 'cart' ) ) { wp_redirect( '/checkout/' ); die(); } } ); ``` ## Step 3: Redirect empty Woocommerce checkout page to shop page Now, this part is needed only if you added a redirection from Woocommerce cart page to checkout page in the step 2. If you didn’t do it then you can skip this part. BUT if you are redirecting your cart page then this part is crucial because otherwise you will end up with “Too many redirects” error on your checkout page after deleting the products from cart. Take a look at the “shop” slug inside the code. Replace it with your own shop page slug. you could also redirect to another page use wp_safe_redirect( slug ); // Redirect to home url from empty Woocommerce checkout page add_action( 'template_redirect', 'redirect_empty_checkout' ); function redirect_empty_checkout() { if ( is_checkout() && 0 == WC()->cart->get_cart_contents_count() && ! is_wc_endpoint_url( 'order-pay' ) && ! is_wc_endpoint_url( 'order-received' ) ) { wp_safe_redirect( get_permalink( wc_get_page_id( 'shop' ) ) ); exit; } } // or alternative step 3 :**Show “Return to shop” button in empty checkout page** add_filter( 'woocommerce_checkout_redirect_empty_cart', '__return_false' ); add_filter( 'woocommerce_checkout_update_order_review_expired', '__return_false' );

Link for further information:

The author has provided the following URL that may be helpful to setting up or using this snippet:

https://youtu.be/bWYW_QmBA6s

Codevault

sophiemulders

Scroll down to see more snippets from this codevault.

Wordpress Compatability

The author has indicated that this snippet is compatable up to wordpress version: 6.1

Our AI bot has checked this snippet is compatable up to wordpress version: 6.1

Code Snippet Plugin Sync

Free & Pro

Download this snippet by clicking the download button, then head over to the Code Snippet Plugin settings in your wordpress admin dashboard, select the import menu then upload this file to import into your wordpress site.

Pro Only (Coming Soon)

You will be able to click a button and sync this snippet to your wordpress site automatically and from your dashboard manage all code snippets across all your wordpress sites that have the Code Snippets Pro plugin installed.

Website/ Profile URL:

https://sophiemulders.com

Snippet Source:

https://youtu.be/bWYW_QmBA6s

History

Last modified:

15/06/2023

Important Note

This snippet has the following status:

AI Verified

This snippet has been tested by our AI bot, see any comments below.

AI Bot Comments:

Found 0 vulnerabilities

merge Woocommerce cart with woocommerce checkout

 
                    
1// 1. Add Woocommerce cart page on the checkout page
2 
3add_action( 'woocommerce_before_checkout_form', 'add_cart_on_checkout', 5 );
4 
5function add_cart_on_checkout() {
6 if ( is_wc_endpoint_url( 'order-received' ) ) return;
7 echo do_shortcode('[woocommerce_cart]'); // Woocommerce cart page shortcode
8}
9 
10// 2. Redirect cart page to checkout
11add_action( 'template_redirect', function() {
12 
13// Replace "cart" and "checkout" with cart and checkout page slug if needed
14 if ( is_page( 'cart' ) ) {
15 wp_redirect( '/checkout/' );
16 die();
17 }
18} );
19 
20//3. Redirect to home url from empty Woocommerce checkout page
21 
22add_action( 'template_redirect', 'redirect_empty_checkout' );
23 
24function redirect_empty_checkout() {
25 if ( is_checkout() && 0 == WC()->cart->get_cart_contents_count() && ! is_wc_endpoint_url( 'order-pay' ) && ! is_wc_endpoint_url( 'order-received' ) ) {
26 wp_safe_redirect( get_permalink( wc_get_page_id( 'shop' ) ) );
27 exit;
28 }
29}
30 
31 //4. Show “Return to shop” button in empty checkout page
32add_filter( 'woocommerce_checkout_redirect_empty_cart', '__return_false' );
33add_filter( 'woocommerce_checkout_update_order_review_expired', '__return_false' );

1

Related Snippets

Please see some snippets below related to this snippet..

WooCommerce

AI Verified

0

Clear Woo Cart after 5 mins

Added: 7 months ago

Last Updated: 7 months ago

This will clear the Woo Cart after 5 mins of inactivity

WooCommerce

AI Verified

0

WooCommerce Product Colour Picker

Added: 1 year ago

Last Updated: 1 year ago

Yes you read that correctly, colour with a U. Here in the UK, we spell things a little differently. Anyway, to the guide. Adding a colour picker to the single product template is really easy. When a u...

WooCommerce

AI Verified

0

Add plus and minus buttons to quantity input woocommerce

Added: 2 months ago

Last Updated: 2 months ago

Adds plus and minus buttons to quantity input woocommerce

Other Snippets in this Codevault

These are some popular snippets from this users codevault..

WooCommerce

AI Verified

1

merge Woocommerce cart with woocommerce checkout

Added: 1 year ago

Last Updated: 1 year ago

Merging the Woocommerce cart with the woocommerce checkout page in 4 steps. Much more userfriendly! Credit goes to @wpsimplehacks on youtube. Brilliant channel

WooCommerce

AI Verified

0

Learndash 'my courses' tab on woocommerce my account page

Added: 1 year ago

Last Updated: 1 year ago

Add a short cut to the customers courses from his Woocommerce my acount dashboard.