Diese Präsentation wurde erfolgreich gemeldet.
Wir verwenden Ihre LinkedIn Profilangaben und Informationen zu Ihren Aktivitäten, um Anzeigen zu personalisieren und Ihnen relevantere Inhalte anzuzeigen. Sie können Ihre Anzeigeneinstellungen jederzeit ändern.

WooCommerce: Conditional Logic

15 Aufrufe

Veröffentlicht am

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/

Veröffentlicht in: Internet
  • Als Erste(r) kommentieren

  • Gehören Sie zu den Ersten, denen das gefällt!

WooCommerce: Conditional Logic

  1. 1. Advanced Customization: Conditional Logic CustomizeWoo.com
  2. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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 ); } }

×