Title: Conditional
Last modified: July 15, 2020

---

# Conditional

 *  Resolved [Joelle](https://wordpress.org/support/users/joelle/)
 * (@joelle)
 * [5 years, 10 months ago](https://wordpress.org/support/topic/conditional-7/)
 * I’m adding a function to display a message after the product short description.
   But I only want it to show if the product has a dependency. I’m not sure what
   I need to add to my function to do that… if ________________ (do my function).
   Can you point me in the right direction?
 * Though, looking at it now, I suppose I could just add your custom message field
   instead of my generic note below. Thoughts? 🙂
 * (I do know that it appears along the top when you click “add to cart”, but we’d
   like it to do display under the short description all the time on products that
   require it, so the user knows beforehand.)
 * Thank you!
 *     ```
       add_filter('woocommerce_short_description','sf_add_text_short_descr');
       function sf_add_text_short_descr($description){
       	if ( is_singular('product') ) {
       $text="<div class='dependency-box'>This item can only be added to your cart if you are purchasing or have already purchased a <a href='#'>Herd Share Membership</a>. Not sure? <a href='#'>Log in</a>!</div>";
       return $description.$text;
       }
       }
       ```
   
    -  This topic was modified 5 years, 10 months ago by [Joelle](https://wordpress.org/support/users/joelle/).
    -  This topic was modified 5 years, 10 months ago by [Joelle](https://wordpress.org/support/users/joelle/).

Viewing 3 replies - 1 through 3 (of 3 total)

 *  Thread Starter [Joelle](https://wordpress.org/support/users/joelle/)
 * (@joelle)
 * [5 years, 10 months ago](https://wordpress.org/support/topic/conditional-7/#post-13128320)
 * Hey there,
 * I actually ended up going with this option, since there’s a bug in WC that seems
   to add the woocommerce_short_description after the variable products, too. Anyway,
   I did some digging in your plugin and came up with this, which seems to work.
 *     ```
       add_action( 'woocommerce_single_product_summary', 'custom_single_product_summary', 2 );
       function custom_single_product_summary(){
           global $product;
   
           remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_excerpt', 20 );
           add_action( 'woocommerce_single_product_summary', 'custom_single_excerpt', 20 );
       }
   
       function custom_single_excerpt(){
           global $post, $product;
   
           $short_description = apply_filters( 'woocommerce_short_description', $post->post_excerpt );
       	$notice = $product->get_meta( '_dependency_notice', true );
   
           if ( ! $short_description )
               return;
   
       	if ($notice == TRUE) {
           // The custom text
           $custom_text = "<div class='dependency-box'>This item can only be added to your cart if you are purchasing or have already purchased a <a href='#'>Herd Share Membership</a>. Not sure? <a href='#'>Log in</a>!</div>";
   
           ?>
           <div class="woocommerce-product-details__short-description">
               <?php echo $short_description . $custom_text; // WPCS: XSS ok. ?>
           </div>
           <?php
       }
       }
       ```
   
 *  Thread Starter [Joelle](https://wordpress.org/support/users/joelle/)
 * (@joelle)
 * [5 years, 10 months ago](https://wordpress.org/support/topic/conditional-7/#post-13128527)
 * Actually, that was wrong. I was stabbing in the dark. While it DOES work, it 
   also doesn’t show anything on products without a dependency, so I’m not sure 
   what to do.
    -  This reply was modified 5 years, 10 months ago by [Joelle](https://wordpress.org/support/users/joelle/).
    -  This reply was modified 5 years, 10 months ago by [Joelle](https://wordpress.org/support/users/joelle/).
 *  Plugin Author [Jason Kytros](https://wordpress.org/support/users/jasonkytros/)
 * (@jasonkytros)
 * [5 years, 10 months ago](https://wordpress.org/support/topic/conditional-7/#post-13132176)
 * Hey [@joelle](https://wordpress.org/support/users/joelle/),
 * Thanks for reaching out!
 * You may use either the `WC_Product_Dependencies::get_tied_product_ids( $product)`
   or the `WC_Product_Dependencies::get_tied_category_ids( $product )` function 
   to check if a specific product has any product/category dependencies. Both these
   functions should return an empty array if the product doesn’t have any dependencies.
 * Let us know if this helps!
 * Cheers,
    Jason Kytros Support Engineer | SomewhereWarm SMPC | [https://somewherewarm.com/](https://somewherewarm.com/)

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘Conditional’ is closed to new replies.

 * ![](https://ps.w.org/woocommerce-product-dependencies/assets/icon-256x256.png?
   rev=3243288)
 * [WooCommerce Product Dependencies](https://wordpress.org/plugins/woocommerce-product-dependencies/)
 * [Support Threads](https://wordpress.org/support/plugin/woocommerce-product-dependencies/)
 * [Active Topics](https://wordpress.org/support/plugin/woocommerce-product-dependencies/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/woocommerce-product-dependencies/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/woocommerce-product-dependencies/reviews/)

 * 3 replies
 * 2 participants
 * Last reply from: [Jason Kytros](https://wordpress.org/support/users/jasonkytros/)
 * Last activity: [5 years, 10 months ago](https://wordpress.org/support/topic/conditional-7/#post-13132176)
 * Status: resolved