Plugin Directory

Changeset 2192281


Ignore:
Timestamp:
11/13/2019 11:08:25 PM (6 years ago)
Author:
wplit
Message:

adding v1.0.1 to trunk

Location:
wplit-woo-conditions-for-oxygen/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • wplit-woo-conditions-for-oxygen/trunk/lib/conditions.php

    r2191180 r2192281  
    4545 */
    4646function lit_wco_condition_empty_cart_callback( $value, $operator ) {
     47   
     48    if (! is_user_logged_in() ) {
     49        return false;
     50    }
    4751
    4852    $emptycart = WC()->cart->is_empty();
     
    103107function lit_wco_condition_product_in_cart_callback( $value, $operator ) {
    104108   
     109    if (! is_user_logged_in() ) {
     110        return false;
     111    }
     112   
    105113    $product_object = get_page_by_title( $value, OBJECT, 'product' );
     114   
     115    if ( is_null($product_object) ) {
     116        return false;
     117    }
    106118
    107119    $id = $product_object->ID;
     
    157169function lit_wco_condition_product_type_callback( $value, $operator ) {
    158170   
    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);
    166181   
    167182    $value = (string) $value;
     
    177192
    178193}
    179 
    180194
    181195
     
    227241function lit_wco_condition_product_in_category_callback( $value, $operator ) {
    228242   
    229     if ( !is_product() ) {
    230         return false;
    231     }
    232    
    233243    $product_in_category = has_term( $value, 'product_cat' );
    234244   
     
    268278
    269279        // 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.
    271280        array(
    272281            'options' => $product_tags_clean,
     
    294303function lit_wco_condition_product_in_tag_callback( $value, $operator ) {
    295304   
    296     if ( !is_product() ) {
    297         return false;
    298     }
    299    
    300305    $product_has_tag = has_term( $value, 'product_tag' );
    301306   
     
    351356    // TO DO include variable products
    352357   
    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    }
    358364   
    359365    $product_on_onsale = $product->is_on_sale();
     
    403409    // TO DO include variable products
    404410   
    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    }
    410417   
    411418    $product_is_virtual = $product->is_virtual();
     
    453460function lit_wco_condition_product_is_downloadable_callback( $value, $operator ) {
    454461   
    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    }
    460468   
    461469    $productisdownloadable = $product->is_downloadable();
     
    505513function lit_wco_condition_product_has_image_callback( $value, $operator ) {
    506514   
    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    }
    512521   
    513522    $product_image = $product->get_image_id();
     
    561570function lit_wco_condition_product_in_stock_callback( $value, $operator ) {
    562571   
    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    }
    568578   
    569579    $product_in_stock = $product->is_in_stock();
     
    612622 */
    613623function lit_wco_condition_cart_weight_callback( $value, $operator ) {
     624   
     625    if (! is_user_logged_in() ) {
     626        return false;
     627    }
    614628
    615629    $cart_weight = WC()->cart->cart_contents_weight;
     
    660674function lit_wco_condition_endpoint_callback( $value, $operator ) {
    661675   
     676    if (! is_user_logged_in() ) {
     677        return false;
     678    }
     679   
    662680    if ($value == 'Any') {
    663681       
     
    767785function lit_wco_condition_customer_bought_product_callback( $value, $operator ) {
    768786   
    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   
    774794    $product_id = $product->get_id();
    775795    $current_user = wp_get_current_user();
     
    840860 */
    841861function lit_wco_condition_user_purchased_product_callback( $value, $operator ) {
     862
     863    if (! is_user_logged_in() ) {
     864        return false;
     865    }
    842866   
    843867    $product_object = get_page_by_title( $value, OBJECT, 'product' );
    844 
     868   
     869    if ( is_null($product_object) ) {
     870        return false;
     871    }
     872   
    845873    $id = $product_object->ID;
    846874   
     
    898926 */
    899927function lit_wco_condition_cart_total_callback( $value, $operator ) {
     928   
     929    if (! is_user_logged_in() ) {
     930        return false;
     931    }
    900932
    901933    $cart_total = WC()->cart->get_cart_contents_total();
  • wplit-woo-conditions-for-oxygen/trunk/readme.txt

    r2191127 r2192281  
    6060== Changelog ==
    6161
    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 =
    6368Initial Release.
Note: See TracChangeset for help on using the changeset viewer.