Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to modify WooCommerce cart, checkout pages (main theme portion)

I have been researching and tweaking away at my custom Wordpress theme and overridden WooCommerce templates with now WooCommerce installed to rectify a bunch of small formatting issues that occur on the WooCommerce pages. I'm down to now the cart and checkout, which yeah they use cart.php (and whatever checkout php), but also uses the main Wordpress theme page.php. I've been able to use is_woocommerce() in conditionals other places but not here as I've learned the WooCommerce docs say that can't be used on checkout and cart.

is_woocommerce() - Returns true if on a page which uses WooCommerce templates (cart and checkout are standard pages with shortcodes and thus are not included). http://docs.woothemes.com/document/conditional-tags/

So how can I alter the appearance of these pages? I have a "View All Posts" and a date/time at the top, and categories sidebar of page.php that I don't want showing up for obvious reasons on the checkout and cart since they don't make sense at all. What are my options?

Can I make it use a different template other than page.php?

Is this an option? Is it bad practice... does it cause more load on every page with this loop? Where do I put it? http://saiyedfaishal.wordpress.com/2014/01/06/check-if-it-is-woocommerce-page/

What's the best way to go about this? Thanks for any help! This question is somewhat related to - How to modify woocommerce_before_cart action

like image 567
Michael K Avatar asked Oct 09 '14 22:10

Michael K


People also ask

How do I change the default checkout page in WordPress?

From the WordPress Dashboard, go to WooFunnels > Settings. Here, go to the Checkouts tab. Select the Checkout page from the drop-down that you want to set as your default checkout page.


2 Answers

Another way to totally override the cart.php is to copy:

woocommerce/templates/cart/cart.php to    yourtheme/woocommerce/cart/cart.php 

Then do whatever you need at the yourtheme/woocommerce/cart/cart.php

like image 155
ken Avatar answered Sep 30 '22 05:09

ken


You can use function: wc_get_page_id( 'cart' ) to get the ID of the page. This function will use the page setup as 'cart' page and not the slug. Meaning it will keep working also when you setup a different url for your 'cart' on the settings page. This works for all kind of Woocommerce special page, like 'checkout', 'shop' etc.

example:

if (wc_get_page_id( 'cart' ) == get_the_ID()) {   // Do something. } 
like image 23
Patrick van Efferen Avatar answered Sep 30 '22 05:09

Patrick van Efferen