Changeset 2192281
- Timestamp:
- 11/13/2019 11:08:25 PM (6 years ago)
- Location:
- wplit-woo-conditions-for-oxygen/trunk
- Files:
-
- 2 edited
-
lib/conditions.php (modified) (17 diffs)
-
readme.txt (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
wplit-woo-conditions-for-oxygen/trunk/lib/conditions.php
r2191180 r2192281 45 45 */ 46 46 function lit_wco_condition_empty_cart_callback( $value, $operator ) { 47 48 if (! is_user_logged_in() ) { 49 return false; 50 } 47 51 48 52 $emptycart = WC()->cart->is_empty(); … … 103 107 function lit_wco_condition_product_in_cart_callback( $value, $operator ) { 104 108 109 if (! is_user_logged_in() ) { 110 return false; 111 } 112 105 113 $product_object = get_page_by_title( $value, OBJECT, 'product' ); 114 115 if ( is_null($product_object) ) { 116 return false; 117 } 106 118 107 119 $id = $product_object->ID; … … 157 169 function lit_wco_condition_product_type_callback( $value, $operator ) { 158 170 159 if ( !is_product() ) { 160 return false; 161 } 162 163 global $post; 164 165 $product_type = WC_Product_Factory::get_product_type($post->ID); 171 // Check that we are either on single product page, or if we're in repeater. Returns false if we're on product archive / shop pages 172 if ( wc_get_product() && !is_shop() && !is_post_type_archive( 'product' ) && !is_tax( get_object_taxonomies( 'product' ) ) ) { 173 $product = wc_get_product(); 174 } else { 175 return false; 176 } 177 178 $product_id = $product->get_id(); 179 180 $product_type = WC_Product_Factory::get_product_type($product_id); 166 181 167 182 $value = (string) $value; … … 177 192 178 193 } 179 180 194 181 195 … … 227 241 function lit_wco_condition_product_in_category_callback( $value, $operator ) { 228 242 229 if ( !is_product() ) {230 return false;231 }232 233 243 $product_in_category = has_term( $value, 'product_cat' ); 234 244 … … 268 278 269 279 // Values: The array of pre-set values the user can choose from. 270 // Set the custom key's value to true to allow users to input custom values.271 280 array( 272 281 'options' => $product_tags_clean, … … 294 303 function lit_wco_condition_product_in_tag_callback( $value, $operator ) { 295 304 296 if ( !is_product() ) {297 return false;298 }299 300 305 $product_has_tag = has_term( $value, 'product_tag' ); 301 306 … … 351 356 // TO DO include variable products 352 357 353 if ( !is_product() ) { 354 return false; 355 } 356 357 $product = new WC_Product(get_the_ID()); 358 // Check that we are either on single product page, or if we're in repeater. Returns false if we're on product archive / shop pages 359 if ( wc_get_product() && !is_shop() && !is_post_type_archive( 'product' ) && !is_tax( get_object_taxonomies( 'product' ) ) ) { 360 $product = wc_get_product(); 361 } else { 362 return false; 363 } 358 364 359 365 $product_on_onsale = $product->is_on_sale(); … … 403 409 // TO DO include variable products 404 410 405 if ( !is_product() ) { 406 return false; 407 } 408 409 $product = new WC_Product(get_the_ID()); 411 // Check that we are either on single product page, or if we're in repeater. Returns false if we're on product archive / shop pages 412 if ( wc_get_product() && !is_shop() && !is_post_type_archive( 'product' ) && !is_tax( get_object_taxonomies( 'product' ) ) ) { 413 $product = wc_get_product(); 414 } else { 415 return false; 416 } 410 417 411 418 $product_is_virtual = $product->is_virtual(); … … 453 460 function lit_wco_condition_product_is_downloadable_callback( $value, $operator ) { 454 461 455 if ( !is_product() ) { 456 return false; 457 } 458 459 $product = new WC_Product(get_the_ID()); 462 // Check that we are either on single product page, or if we're in repeater. Returns false if we're on product archive / shop pages 463 if ( wc_get_product() && !is_shop() && !is_post_type_archive( 'product' ) && !is_tax( get_object_taxonomies( 'product' ) ) ) { 464 $product = wc_get_product(); 465 } else { 466 return false; 467 } 460 468 461 469 $productisdownloadable = $product->is_downloadable(); … … 505 513 function lit_wco_condition_product_has_image_callback( $value, $operator ) { 506 514 507 if ( !is_product() ) { 508 return false; 509 } 510 511 $product = new WC_Product(get_the_ID()); 515 // Check that we are either on single product page, or if we're in repeater. Returns false if we're on product archive / shop pages 516 if ( wc_get_product() && !is_shop() && !is_post_type_archive( 'product' ) && !is_tax( get_object_taxonomies( 'product' ) ) ) { 517 $product = wc_get_product(); 518 } else { 519 return false; 520 } 512 521 513 522 $product_image = $product->get_image_id(); … … 561 570 function lit_wco_condition_product_in_stock_callback( $value, $operator ) { 562 571 563 if ( !is_product() ) { 564 return false; 565 } 566 567 $product = new WC_Product(get_the_ID()); 572 // Check that we are either on single product page, or if we're in repeater. Returns false if we're on product archive / shop pages 573 if ( wc_get_product() && !is_shop() && !is_post_type_archive( 'product' ) && !is_tax( get_object_taxonomies( 'product' ) ) ) { 574 $product = wc_get_product(); 575 } else { 576 return false; 577 } 568 578 569 579 $product_in_stock = $product->is_in_stock(); … … 612 622 */ 613 623 function lit_wco_condition_cart_weight_callback( $value, $operator ) { 624 625 if (! is_user_logged_in() ) { 626 return false; 627 } 614 628 615 629 $cart_weight = WC()->cart->cart_contents_weight; … … 660 674 function lit_wco_condition_endpoint_callback( $value, $operator ) { 661 675 676 if (! is_user_logged_in() ) { 677 return false; 678 } 679 662 680 if ($value == 'Any') { 663 681 … … 767 785 function lit_wco_condition_customer_bought_product_callback( $value, $operator ) { 768 786 769 if ( !is_product() ) { 770 return false; 771 } 772 773 $product = new WC_Product(get_the_ID()); 787 // Check that we are either on single product page, or if we're in repeater. Returns false if we're on product archive / shop pages 788 if ( wc_get_product() && !is_shop() && !is_post_type_archive( 'product' ) && !is_tax( get_object_taxonomies( 'product' ) ) ) { 789 $product = wc_get_product(); 790 } else { 791 return false; 792 } 793 774 794 $product_id = $product->get_id(); 775 795 $current_user = wp_get_current_user(); … … 840 860 */ 841 861 function lit_wco_condition_user_purchased_product_callback( $value, $operator ) { 862 863 if (! is_user_logged_in() ) { 864 return false; 865 } 842 866 843 867 $product_object = get_page_by_title( $value, OBJECT, 'product' ); 844 868 869 if ( is_null($product_object) ) { 870 return false; 871 } 872 845 873 $id = $product_object->ID; 846 874 … … 898 926 */ 899 927 function lit_wco_condition_cart_total_callback( $value, $operator ) { 928 929 if (! is_user_logged_in() ) { 930 return false; 931 } 900 932 901 933 $cart_total = WC()->cart->get_cart_contents_total(); -
wplit-woo-conditions-for-oxygen/trunk/readme.txt
r2191127 r2192281 60 60 == Changelog == 61 61 62 = 1.0 = 62 = 1.0.1 (Date: November 14, 2019) = 63 * Product conditions now work in repeaters 64 * Product conditions work in global modals. 65 * Small performance improvements 66 67 = 1.0.0 = 63 68 Initial Release.
Note: See TracChangeset
for help on using the changeset viewer.