SlideShare a Scribd company logo
Advanced Customization:
Conditional Logic
CustomizeWoo.com
"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
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)
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)
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>";
}
}
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
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>";
}
}
Useful WC Product Conditional Tags
CustomizeWoo.com
● $product->is_type( 'simple' ): product type is simple
● $product->is_virtual()
● $product->is_on_sale()
● $product->is_in_stock() && $product->managing_stock()
● $product->has_weight()
(includesabstractsabstract-wc-product.php)
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)
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
Workflow Example: product in category
CustomizeWoo.com
add_action(
'woocommerce_before_shop_loop_item_title',
'cat_banner' );
function cat_banner( ) {
echo "<p>Test</p>";
}
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>";
}
}
Bonus: Conditional remove_action
CustomizeWoo.com
add_action( 'wp', 'no_image_prod_987' );
function no_image_prod_987( ) {
if ( is_single( 987 ) ) {
remove_action(
'woocommerce_before_single_product_summary',
'woocommerce_show_product_images', 20 );
}
}

More Related Content

Similar to WooCommerce: Conditional Logic

WordPress plugin #3
WordPress plugin #3WordPress plugin #3
WordPress plugin #3
giwoolee
 
How Not to Build a WordPress Plugin
How Not to Build a WordPress PluginHow Not to Build a WordPress Plugin
How Not to Build a WordPress Plugin
Will Norris
 
Web Components for Java Developers
Web Components for Java DevelopersWeb Components for Java Developers
Web Components for Java Developers
Joonas Lehtinen
 
A test framework out of the box - Geb for Web and mobile
A test framework out of the box - Geb for Web and mobileA test framework out of the box - Geb for Web and mobile
A test framework out of the box - Geb for Web and mobile
GlobalLogic Ukraine
 
AdWords Scripts and MCC Scripting
AdWords Scripts and MCC ScriptingAdWords Scripts and MCC Scripting
AdWords Scripts and MCC Scripting
marcwan
 
Service Oriented Architecture in Magento 2
Service Oriented Architecture in Magento 2Service Oriented Architecture in Magento 2
Service Oriented Architecture in Magento 2
Max Pronko
 
Windows Store app using XAML and C#: Enterprise Product Development
Windows Store app using XAML and C#: Enterprise Product Development Windows Store app using XAML and C#: Enterprise Product Development
Windows Store app using XAML and C#: Enterprise Product Development
Mahmoud Hamed Mahmoud
 
Webinar: AngularJS and the WordPress REST API
Webinar: AngularJS and the WordPress REST APIWebinar: AngularJS and the WordPress REST API
Webinar: AngularJS and the WordPress REST API
WP Engine UK
 
Webinar: AngularJS and the WordPress REST API
Webinar: AngularJS and the WordPress REST APIWebinar: AngularJS and the WordPress REST API
Webinar: AngularJS and the WordPress REST API
WP Engine
 
How to build an e-shop using Drupal and Ubercart
How to build an e-shop using Drupal and UbercartHow to build an e-shop using Drupal and Ubercart
How to build an e-shop using Drupal and Ubercart
infowonders
 
Gae Meets Django
Gae Meets DjangoGae Meets Django
Gae Meets Django
fool2nd
 
Real use cases of performance optimization in magento 2
Real use cases of performance optimization in magento 2Real use cases of performance optimization in magento 2
Real use cases of performance optimization in magento 2
Max Pronko
 
WooCommerce: Action Hooks
WooCommerce: Action HooksWooCommerce: Action Hooks
WooCommerce: Action Hooks
Rodolfo Melogli
 
Geek Moot '09 -- FrontendUsers/CustomContent
Geek Moot '09 -- FrontendUsers/CustomContentGeek Moot '09 -- FrontendUsers/CustomContent
Geek Moot '09 -- FrontendUsers/CustomContent
Ted Kulp
 
Modern frontend development with VueJs
Modern frontend development with VueJsModern frontend development with VueJs
Modern frontend development with VueJs
Tudor Barbu
 
WooCommerce: Anatomy of a Template File
WooCommerce: Anatomy of a Template FileWooCommerce: Anatomy of a Template File
WooCommerce: Anatomy of a Template File
Rodolfo Melogli
 
Three Simple Chords of Alternative PageObjects and Hardcore of LoadableCompon...
Three Simple Chords of Alternative PageObjects and Hardcore of LoadableCompon...Three Simple Chords of Alternative PageObjects and Hardcore of LoadableCompon...
Three Simple Chords of Alternative PageObjects and Hardcore of LoadableCompon...
Iakiv Kramarenko
 
Course CodeSchool - Shaping up with Angular.js
Course CodeSchool - Shaping up with Angular.jsCourse CodeSchool - Shaping up with Angular.js
Course CodeSchool - Shaping up with Angular.js
Vinícius de Moraes
 
Gail villanueva add muscle to your wordpress site
Gail villanueva   add muscle to your wordpress siteGail villanueva   add muscle to your wordpress site
Gail villanueva add muscle to your wordpress site
references
 
Introduction to Plugin Programming, WordCamp Miami 2011
Introduction to Plugin Programming, WordCamp Miami 2011Introduction to Plugin Programming, WordCamp Miami 2011
Introduction to Plugin Programming, WordCamp Miami 2011
David Carr
 

Similar to WooCommerce: Conditional Logic (20)

WordPress plugin #3
WordPress plugin #3WordPress plugin #3
WordPress plugin #3
 
How Not to Build a WordPress Plugin
How Not to Build a WordPress PluginHow Not to Build a WordPress Plugin
How Not to Build a WordPress Plugin
 
Web Components for Java Developers
Web Components for Java DevelopersWeb Components for Java Developers
Web Components for Java Developers
 
A test framework out of the box - Geb for Web and mobile
A test framework out of the box - Geb for Web and mobileA test framework out of the box - Geb for Web and mobile
A test framework out of the box - Geb for Web and mobile
 
AdWords Scripts and MCC Scripting
AdWords Scripts and MCC ScriptingAdWords Scripts and MCC Scripting
AdWords Scripts and MCC Scripting
 
Service Oriented Architecture in Magento 2
Service Oriented Architecture in Magento 2Service Oriented Architecture in Magento 2
Service Oriented Architecture in Magento 2
 
Windows Store app using XAML and C#: Enterprise Product Development
Windows Store app using XAML and C#: Enterprise Product Development Windows Store app using XAML and C#: Enterprise Product Development
Windows Store app using XAML and C#: Enterprise Product Development
 
Webinar: AngularJS and the WordPress REST API
Webinar: AngularJS and the WordPress REST APIWebinar: AngularJS and the WordPress REST API
Webinar: AngularJS and the WordPress REST API
 
Webinar: AngularJS and the WordPress REST API
Webinar: AngularJS and the WordPress REST APIWebinar: AngularJS and the WordPress REST API
Webinar: AngularJS and the WordPress REST API
 
How to build an e-shop using Drupal and Ubercart
How to build an e-shop using Drupal and UbercartHow to build an e-shop using Drupal and Ubercart
How to build an e-shop using Drupal and Ubercart
 
Gae Meets Django
Gae Meets DjangoGae Meets Django
Gae Meets Django
 
Real use cases of performance optimization in magento 2
Real use cases of performance optimization in magento 2Real use cases of performance optimization in magento 2
Real use cases of performance optimization in magento 2
 
WooCommerce: Action Hooks
WooCommerce: Action HooksWooCommerce: Action Hooks
WooCommerce: Action Hooks
 
Geek Moot '09 -- FrontendUsers/CustomContent
Geek Moot '09 -- FrontendUsers/CustomContentGeek Moot '09 -- FrontendUsers/CustomContent
Geek Moot '09 -- FrontendUsers/CustomContent
 
Modern frontend development with VueJs
Modern frontend development with VueJsModern frontend development with VueJs
Modern frontend development with VueJs
 
WooCommerce: Anatomy of a Template File
WooCommerce: Anatomy of a Template FileWooCommerce: Anatomy of a Template File
WooCommerce: Anatomy of a Template File
 
Three Simple Chords of Alternative PageObjects and Hardcore of LoadableCompon...
Three Simple Chords of Alternative PageObjects and Hardcore of LoadableCompon...Three Simple Chords of Alternative PageObjects and Hardcore of LoadableCompon...
Three Simple Chords of Alternative PageObjects and Hardcore of LoadableCompon...
 
Course CodeSchool - Shaping up with Angular.js
Course CodeSchool - Shaping up with Angular.jsCourse CodeSchool - Shaping up with Angular.js
Course CodeSchool - Shaping up with Angular.js
 
Gail villanueva add muscle to your wordpress site
Gail villanueva   add muscle to your wordpress siteGail villanueva   add muscle to your wordpress site
Gail villanueva add muscle to your wordpress site
 
Introduction to Plugin Programming, WordCamp Miami 2011
Introduction to Plugin Programming, WordCamp Miami 2011Introduction to Plugin Programming, WordCamp Miami 2011
Introduction to Plugin Programming, WordCamp Miami 2011
 

More from Rodolfo Melogli

WordCamp Italia 2021: da zero a PHP
WordCamp Italia 2021: da zero a PHPWordCamp Italia 2021: da zero a PHP
WordCamp Italia 2021: da zero a PHP
Rodolfo Melogli
 
WooCommerce: Issues With remove action()
WooCommerce: Issues With remove action()WooCommerce: Issues With remove action()
WooCommerce: Issues With remove action()
Rodolfo Melogli
 
WooCommerce: Custom Fields
WooCommerce: Custom FieldsWooCommerce: Custom Fields
WooCommerce: Custom Fields
Rodolfo Melogli
 
WooCommerce: Intro to PHP
WooCommerce: Intro to PHPWooCommerce: Intro to PHP
WooCommerce: Intro to PHP
Rodolfo Melogli
 
WooCommerce: Intro to CSS
WooCommerce: Intro to CSSWooCommerce: Intro to CSS
WooCommerce: Intro to CSS
Rodolfo Melogli
 
WooCommerce: Shortcodes
WooCommerce: ShortcodesWooCommerce: Shortcodes
WooCommerce: Shortcodes
Rodolfo Melogli
 
WooCommerce: Filter Hooks
WooCommerce: Filter HooksWooCommerce: Filter Hooks
WooCommerce: Filter Hooks
Rodolfo Melogli
 
WooCommerce: Where to Place Customization
WooCommerce: Where to Place CustomizationWooCommerce: Where to Place Customization
WooCommerce: Where to Place Customization
Rodolfo Melogli
 
WooCommerce: Plugin Settings Overview
WooCommerce: Plugin Settings OverviewWooCommerce: Plugin Settings Overview
WooCommerce: Plugin Settings Overview
Rodolfo Melogli
 
WooCommerce: Customization Mistakes to Avoid
WooCommerce: Customization Mistakes to AvoidWooCommerce: Customization Mistakes to Avoid
WooCommerce: Customization Mistakes to Avoid
Rodolfo Melogli
 
WooCommerce: Customization Definitions
WooCommerce: Customization DefinitionsWooCommerce: Customization Definitions
WooCommerce: Customization Definitions
Rodolfo Melogli
 
WooCommerce: Customization FAQ
WooCommerce: Customization FAQWooCommerce: Customization FAQ
WooCommerce: Customization FAQ
Rodolfo Melogli
 
10 PHP Snippets to Increase WooCommerce Sales
10 PHP Snippets to Increase WooCommerce Sales10 PHP Snippets to Increase WooCommerce Sales
10 PHP Snippets to Increase WooCommerce Sales
Rodolfo Melogli
 
WooCommerce Workshop. INSTALL. SET UP. PUBLISH. SELL.
WooCommerce Workshop. INSTALL. SET UP. PUBLISH. SELL.WooCommerce Workshop. INSTALL. SET UP. PUBLISH. SELL.
WooCommerce Workshop. INSTALL. SET UP. PUBLISH. SELL.
Rodolfo Melogli
 
How to Sell ANYTHING with WordPress + WooCommerce
How to Sell ANYTHING with WordPress + WooCommerceHow to Sell ANYTHING with WordPress + WooCommerce
How to Sell ANYTHING with WordPress + WooCommerce
Rodolfo Melogli
 
WooCommerce Customization Masterclass (WordCamp Dublin 2017)
WooCommerce Customization Masterclass (WordCamp Dublin 2017)WooCommerce Customization Masterclass (WordCamp Dublin 2017)
WooCommerce Customization Masterclass (WordCamp Dublin 2017)
Rodolfo Melogli
 
5 Growth Hacking Strategies + Google Analytics tips & tricks
5 Growth Hacking Strategies + Google Analytics tips & tricks5 Growth Hacking Strategies + Google Analytics tips & tricks
5 Growth Hacking Strategies + Google Analytics tips & tricks
Rodolfo Melogli
 
From Purchase to Customer Satisfaction: 7 Ways to Increase your Sales
From Purchase to Customer Satisfaction: 7 Ways to Increase your SalesFrom Purchase to Customer Satisfaction: 7 Ways to Increase your Sales
From Purchase to Customer Satisfaction: 7 Ways to Increase your Sales
Rodolfo Melogli
 
Top 15 Sales Generation Techniques (Ecommerce Customer Acquisition)
Top 15 Sales Generation Techniques (Ecommerce Customer Acquisition)Top 15 Sales Generation Techniques (Ecommerce Customer Acquisition)
Top 15 Sales Generation Techniques (Ecommerce Customer Acquisition)
Rodolfo Melogli
 
10 Ecommerce "Secrets" to Skyrocket your Sales
10 Ecommerce "Secrets" to Skyrocket your Sales10 Ecommerce "Secrets" to Skyrocket your Sales
10 Ecommerce "Secrets" to Skyrocket your Sales
Rodolfo Melogli
 

More from Rodolfo Melogli (20)

WordCamp Italia 2021: da zero a PHP
WordCamp Italia 2021: da zero a PHPWordCamp Italia 2021: da zero a PHP
WordCamp Italia 2021: da zero a PHP
 
WooCommerce: Issues With remove action()
WooCommerce: Issues With remove action()WooCommerce: Issues With remove action()
WooCommerce: Issues With remove action()
 
WooCommerce: Custom Fields
WooCommerce: Custom FieldsWooCommerce: Custom Fields
WooCommerce: Custom Fields
 
WooCommerce: Intro to PHP
WooCommerce: Intro to PHPWooCommerce: Intro to PHP
WooCommerce: Intro to PHP
 
WooCommerce: Intro to CSS
WooCommerce: Intro to CSSWooCommerce: Intro to CSS
WooCommerce: Intro to CSS
 
WooCommerce: Shortcodes
WooCommerce: ShortcodesWooCommerce: Shortcodes
WooCommerce: Shortcodes
 
WooCommerce: Filter Hooks
WooCommerce: Filter HooksWooCommerce: Filter Hooks
WooCommerce: Filter Hooks
 
WooCommerce: Where to Place Customization
WooCommerce: Where to Place CustomizationWooCommerce: Where to Place Customization
WooCommerce: Where to Place Customization
 
WooCommerce: Plugin Settings Overview
WooCommerce: Plugin Settings OverviewWooCommerce: Plugin Settings Overview
WooCommerce: Plugin Settings Overview
 
WooCommerce: Customization Mistakes to Avoid
WooCommerce: Customization Mistakes to AvoidWooCommerce: Customization Mistakes to Avoid
WooCommerce: Customization Mistakes to Avoid
 
WooCommerce: Customization Definitions
WooCommerce: Customization DefinitionsWooCommerce: Customization Definitions
WooCommerce: Customization Definitions
 
WooCommerce: Customization FAQ
WooCommerce: Customization FAQWooCommerce: Customization FAQ
WooCommerce: Customization FAQ
 
10 PHP Snippets to Increase WooCommerce Sales
10 PHP Snippets to Increase WooCommerce Sales10 PHP Snippets to Increase WooCommerce Sales
10 PHP Snippets to Increase WooCommerce Sales
 
WooCommerce Workshop. INSTALL. SET UP. PUBLISH. SELL.
WooCommerce Workshop. INSTALL. SET UP. PUBLISH. SELL.WooCommerce Workshop. INSTALL. SET UP. PUBLISH. SELL.
WooCommerce Workshop. INSTALL. SET UP. PUBLISH. SELL.
 
How to Sell ANYTHING with WordPress + WooCommerce
How to Sell ANYTHING with WordPress + WooCommerceHow to Sell ANYTHING with WordPress + WooCommerce
How to Sell ANYTHING with WordPress + WooCommerce
 
WooCommerce Customization Masterclass (WordCamp Dublin 2017)
WooCommerce Customization Masterclass (WordCamp Dublin 2017)WooCommerce Customization Masterclass (WordCamp Dublin 2017)
WooCommerce Customization Masterclass (WordCamp Dublin 2017)
 
5 Growth Hacking Strategies + Google Analytics tips & tricks
5 Growth Hacking Strategies + Google Analytics tips & tricks5 Growth Hacking Strategies + Google Analytics tips & tricks
5 Growth Hacking Strategies + Google Analytics tips & tricks
 
From Purchase to Customer Satisfaction: 7 Ways to Increase your Sales
From Purchase to Customer Satisfaction: 7 Ways to Increase your SalesFrom Purchase to Customer Satisfaction: 7 Ways to Increase your Sales
From Purchase to Customer Satisfaction: 7 Ways to Increase your Sales
 
Top 15 Sales Generation Techniques (Ecommerce Customer Acquisition)
Top 15 Sales Generation Techniques (Ecommerce Customer Acquisition)Top 15 Sales Generation Techniques (Ecommerce Customer Acquisition)
Top 15 Sales Generation Techniques (Ecommerce Customer Acquisition)
 
10 Ecommerce "Secrets" to Skyrocket your Sales
10 Ecommerce "Secrets" to Skyrocket your Sales10 Ecommerce "Secrets" to Skyrocket your Sales
10 Ecommerce "Secrets" to Skyrocket your Sales
 

Recently uploaded

10 Conversion Rate Optimization (CRO) Techniques to Boost Your Website’s Perf...
10 Conversion Rate Optimization (CRO) Techniques to Boost Your Website’s Perf...10 Conversion Rate Optimization (CRO) Techniques to Boost Your Website’s Perf...
10 Conversion Rate Optimization (CRO) Techniques to Boost Your Website’s Perf...
Web Inspire
 
Honeypots Unveiled: Proactive Defense Tactics for Cyber Security, Phoenix Sum...
Honeypots Unveiled: Proactive Defense Tactics for Cyber Security, Phoenix Sum...Honeypots Unveiled: Proactive Defense Tactics for Cyber Security, Phoenix Sum...
Honeypots Unveiled: Proactive Defense Tactics for Cyber Security, Phoenix Sum...
APNIC
 
Bengaluru Dreamin' 24 - Personal Branding
Bengaluru Dreamin' 24 - Personal BrandingBengaluru Dreamin' 24 - Personal Branding
Bengaluru Dreamin' 24 - Personal Branding
Tarandeep Singh
 
KubeCon & CloudNative Con 2024 Artificial Intelligent
KubeCon & CloudNative Con 2024 Artificial IntelligentKubeCon & CloudNative Con 2024 Artificial Intelligent
KubeCon & CloudNative Con 2024 Artificial Intelligent
Emre Gündoğdu
 
cyber crime.pptx..........................
cyber crime.pptx..........................cyber crime.pptx..........................
cyber crime.pptx..........................
GNAMBIKARAO
 
DocSplit Subsequent Implementation Activation.pptx
DocSplit Subsequent Implementation Activation.pptxDocSplit Subsequent Implementation Activation.pptx
DocSplit Subsequent Implementation Activation.pptx
AmitTuteja9
 
一比一原版(uc毕业证书)加拿大卡尔加里大学毕业证如何办理
一比一原版(uc毕业证书)加拿大卡尔加里大学毕业证如何办理一比一原版(uc毕业证书)加拿大卡尔加里大学毕业证如何办理
一比一原版(uc毕业证书)加拿大卡尔加里大学毕业证如何办理
dtagbe
 
Network Security and Cyber Laws (Complete Notes) for B.Tech/BCA/BSc. IT
Network Security and Cyber Laws (Complete Notes) for B.Tech/BCA/BSc. ITNetwork Security and Cyber Laws (Complete Notes) for B.Tech/BCA/BSc. IT
Network Security and Cyber Laws (Complete Notes) for B.Tech/BCA/BSc. IT
Sarthak Sobti
 
Unlimited Short Call Girls Mumbai ✅ 9833363713 FULL CASH PAYMENT
Unlimited Short Call Girls Mumbai ✅ 9833363713 FULL CASH PAYMENTUnlimited Short Call Girls Mumbai ✅ 9833363713 FULL CASH PAYMENT
Unlimited Short Call Girls Mumbai ✅ 9833363713 FULL CASH PAYMENT
rajesh344555
 
Securing BGP: Operational Strategies and Best Practices for Network Defenders...
Securing BGP: Operational Strategies and Best Practices for Network Defenders...Securing BGP: Operational Strategies and Best Practices for Network Defenders...
Securing BGP: Operational Strategies and Best Practices for Network Defenders...
APNIC
 
Unlimited Short Call Girls Navi Mumbai ✅ 9967824496 FULL CASH PAYMENT
Unlimited Short Call Girls Navi Mumbai ✅ 9967824496 FULL CASH PAYMENTUnlimited Short Call Girls Navi Mumbai ✅ 9967824496 FULL CASH PAYMENT
Unlimited Short Call Girls Navi Mumbai ✅ 9967824496 FULL CASH PAYMENT
rajesh344555
 
Bangalore Call Girls 9079923931 With -Cuties' Hot Call Girls
Bangalore Call Girls 9079923931 With -Cuties' Hot Call GirlsBangalore Call Girls 9079923931 With -Cuties' Hot Call Girls
Bangalore Call Girls 9079923931 With -Cuties' Hot Call Girls
narwatsonia7
 
EASY TUTORIAL OF HOW TO USE CiCi AI BY: FEBLESS HERNANE
EASY TUTORIAL OF HOW TO USE CiCi AI BY: FEBLESS HERNANE EASY TUTORIAL OF HOW TO USE CiCi AI BY: FEBLESS HERNANE
EASY TUTORIAL OF HOW TO USE CiCi AI BY: FEBLESS HERNANE
Febless Hernane
 
Decentralized Justice in Gaming and Esports
Decentralized Justice in Gaming and EsportsDecentralized Justice in Gaming and Esports
Decentralized Justice in Gaming and Esports
Federico Ast
 
一比一原版新西兰林肯大学毕业证(Lincoln毕业证书)学历如何办理
一比一原版新西兰林肯大学毕业证(Lincoln毕业证书)学历如何办理一比一原版新西兰林肯大学毕业证(Lincoln毕业证书)学历如何办理
一比一原版新西兰林肯大学毕业证(Lincoln毕业证书)学历如何办理
thezot
 

Recently uploaded (15)

10 Conversion Rate Optimization (CRO) Techniques to Boost Your Website’s Perf...
10 Conversion Rate Optimization (CRO) Techniques to Boost Your Website’s Perf...10 Conversion Rate Optimization (CRO) Techniques to Boost Your Website’s Perf...
10 Conversion Rate Optimization (CRO) Techniques to Boost Your Website’s Perf...
 
Honeypots Unveiled: Proactive Defense Tactics for Cyber Security, Phoenix Sum...
Honeypots Unveiled: Proactive Defense Tactics for Cyber Security, Phoenix Sum...Honeypots Unveiled: Proactive Defense Tactics for Cyber Security, Phoenix Sum...
Honeypots Unveiled: Proactive Defense Tactics for Cyber Security, Phoenix Sum...
 
Bengaluru Dreamin' 24 - Personal Branding
Bengaluru Dreamin' 24 - Personal BrandingBengaluru Dreamin' 24 - Personal Branding
Bengaluru Dreamin' 24 - Personal Branding
 
KubeCon & CloudNative Con 2024 Artificial Intelligent
KubeCon & CloudNative Con 2024 Artificial IntelligentKubeCon & CloudNative Con 2024 Artificial Intelligent
KubeCon & CloudNative Con 2024 Artificial Intelligent
 
cyber crime.pptx..........................
cyber crime.pptx..........................cyber crime.pptx..........................
cyber crime.pptx..........................
 
DocSplit Subsequent Implementation Activation.pptx
DocSplit Subsequent Implementation Activation.pptxDocSplit Subsequent Implementation Activation.pptx
DocSplit Subsequent Implementation Activation.pptx
 
一比一原版(uc毕业证书)加拿大卡尔加里大学毕业证如何办理
一比一原版(uc毕业证书)加拿大卡尔加里大学毕业证如何办理一比一原版(uc毕业证书)加拿大卡尔加里大学毕业证如何办理
一比一原版(uc毕业证书)加拿大卡尔加里大学毕业证如何办理
 
Network Security and Cyber Laws (Complete Notes) for B.Tech/BCA/BSc. IT
Network Security and Cyber Laws (Complete Notes) for B.Tech/BCA/BSc. ITNetwork Security and Cyber Laws (Complete Notes) for B.Tech/BCA/BSc. IT
Network Security and Cyber Laws (Complete Notes) for B.Tech/BCA/BSc. IT
 
Unlimited Short Call Girls Mumbai ✅ 9833363713 FULL CASH PAYMENT
Unlimited Short Call Girls Mumbai ✅ 9833363713 FULL CASH PAYMENTUnlimited Short Call Girls Mumbai ✅ 9833363713 FULL CASH PAYMENT
Unlimited Short Call Girls Mumbai ✅ 9833363713 FULL CASH PAYMENT
 
Securing BGP: Operational Strategies and Best Practices for Network Defenders...
Securing BGP: Operational Strategies and Best Practices for Network Defenders...Securing BGP: Operational Strategies and Best Practices for Network Defenders...
Securing BGP: Operational Strategies and Best Practices for Network Defenders...
 
Unlimited Short Call Girls Navi Mumbai ✅ 9967824496 FULL CASH PAYMENT
Unlimited Short Call Girls Navi Mumbai ✅ 9967824496 FULL CASH PAYMENTUnlimited Short Call Girls Navi Mumbai ✅ 9967824496 FULL CASH PAYMENT
Unlimited Short Call Girls Navi Mumbai ✅ 9967824496 FULL CASH PAYMENT
 
Bangalore Call Girls 9079923931 With -Cuties' Hot Call Girls
Bangalore Call Girls 9079923931 With -Cuties' Hot Call GirlsBangalore Call Girls 9079923931 With -Cuties' Hot Call Girls
Bangalore Call Girls 9079923931 With -Cuties' Hot Call Girls
 
EASY TUTORIAL OF HOW TO USE CiCi AI BY: FEBLESS HERNANE
EASY TUTORIAL OF HOW TO USE CiCi AI BY: FEBLESS HERNANE EASY TUTORIAL OF HOW TO USE CiCi AI BY: FEBLESS HERNANE
EASY TUTORIAL OF HOW TO USE CiCi AI BY: FEBLESS HERNANE
 
Decentralized Justice in Gaming and Esports
Decentralized Justice in Gaming and EsportsDecentralized Justice in Gaming and Esports
Decentralized Justice in Gaming and Esports
 
一比一原版新西兰林肯大学毕业证(Lincoln毕业证书)学历如何办理
一比一原版新西兰林肯大学毕业证(Lincoln毕业证书)学历如何办理一比一原版新西兰林肯大学毕业证(Lincoln毕业证书)学历如何办理
一比一原版新西兰林肯大学毕业证(Lincoln毕业证书)学历如何办理
 

WooCommerce: Conditional Logic

  • 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>"; } }
  • 8. Useful WC Product Conditional Tags CustomizeWoo.com ● $product->is_type( 'simple' ): product type is simple ● $product->is_virtual() ● $product->is_on_sale() ● $product->is_in_stock() && $product->managing_stock() ● $product->has_weight() (includesabstractsabstract-wc-product.php)
  • 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>"; } }
  • 13. Bonus: Conditional remove_action CustomizeWoo.com add_action( 'wp', 'no_image_prod_987' ); function no_image_prod_987( ) { if ( is_single( 987 ) ) { remove_action( 'woocommerce_before_single_product_summary', 'woocommerce_show_product_images', 20 ); } }