These slides belong to https://CustomizeWoo.com, a technical video course that shows you how to override WooCommerce pages and elements without using plugins. You can watch me code and learn by example.
A series of videos, screencasts, examples and exercises will help you feel more confident about WooCommerce customization, child themes, hooks and CSS/PHP snippets.
Watch and re-watch each video how many times you like, get lifetime access to me via the comment section, exercise as much as possible and keep learning.
Access your free videos or buy the course via https://businessbloomer.com/customizewoo-master-woocommerce-online-course/
2. "Conditional Logic"
"Conditional Tags e.g. is_front_page()
allow to display content or run PHP
functions on a particular WP/WC page
depending on what conditions that page
matches"
CustomizeWoo.com
3. Conditional Logic Benefits
CustomizeWoo.com
● Target specific product ID (conditional
behavior)
● Only run functions where needed
(performance)
● Achieve complex coding (e.g. shipping by
weight ranges)
4. Useful WC Conditional Tags
CustomizeWoo.com
● is_woocommerce(): true if WC page (e.g. Shop, single
product… excluding WP Pages: Cart, Checkout, ...)
● is_shop(): true if main Shop page (loop)
● is_product_category(): if product category page (loop)
● is_product(): single product page
● is_cart(): Cart page --- is_checkout(): Checkout page
● is_account_page(): account pages
● is_wc_endpoint_url( 'order-received' ): Thank You page
(includeswc-conditional-functions.php)
5. Example: specific product category
CustomizeWoo.com
add_action( 'woocommerce_archive_description',
'cat_banner' );
function cat_banner( ) {
if ( is_product_category( 'clearance' ) ) {
echo "<p>Half price while stock lasts!</p>";
}
}
6. Useful WP Conditional Tags
CustomizeWoo.com
● is_front_page(): home page
● is_home(): blog page (note the “false friend” :-) )
● is_single( '17' ): if single post/product page ID = 17
● is_page( 42 ): if WP page ID = 42
● has_term( 'hats', 'product_cat' ): product in category
● is_admin(): WP dashboard displayed (performance)
● current_user_can( 'install_plugins' ): capabilities
7. Example: product in category
CustomizeWoo.com
add_action(
'woocommerce_before_shop_loop_item_title',
'cat_banner' );
function cat_banner( ) {
if ( has_term( 'chairs', 'product_cat' ) ) {
echo "<p>Sit down and feel the comfort!</p>";
}
}
9. Useful WC Order Conditional Tags
CustomizeWoo.com
● $order->has_status( 'failed' )
● $order->is_paid()
● $order->has_downloadable_item()
● $order->needs_payment()
(includesabstractsabstract-wc-order.php and
includesclass-wc-order.php)
10. Conditional Logic Workflow
CustomizeWoo.com
1. Project specs e.g. "Display banner below
shop item if product = on sale & cat = tables"
2. Write a PHP function that works
everywhere (i.e. for every product) so you
know it works
3. Find the conditional tag/s and apply them to
the function as wrappers
11. Workflow Example: product in category
CustomizeWoo.com
add_action(
'woocommerce_before_shop_loop_item_title',
'cat_banner' );
function cat_banner( ) {
echo "<p>Test</p>";
}
12. Workflow Example: product in category
CustomizeWoo.com
add_action(
'woocommerce_before_shop_loop_item_title',
'cat_banner' );
function cat_banner( ) {
if ( has_term( 'chairs', 'product_cat' ) ) {
echo "<p>Sit down and feel the comfort!</p>";
}
}