Title: Conditional Formatting
Last modified: August 31, 2016

---

# Conditional Formatting

 *  [AmandaEve](https://wordpress.org/support/users/amandaeve/)
 * (@amandaeve)
 * [10 years, 3 months ago](https://wordpress.org/support/topic/conditional-formatting-2/)
 * So … i’ve created a function snippet in the function.php file:
 *     ```
       function wc_custom_single_addtocart_text( $text, $product ) {
           switch ( $product->product_type ) {
               case 'simple'  : $text = 'Simple product text'; break;
               case 'variable': $text = 'Variable product text'; break;
               case 'external': $text = 'External product text'; break;
               case 'grouped' : $text = 'Grouped product text'; break;
               default        : $text = 'Add to Cart'; break;
           }
   
           return $text;
       ```
   
 * But I need something at the beginning that checks if they have a subscription.
 * My goal is to have the add to cart button change to ‘view product’ when the user
   has an active subscription.
 * [https://wordpress.org/plugins/woocommerce/](https://wordpress.org/plugins/woocommerce/)

Viewing 15 replies - 1 through 15 (of 16 total)

1 [2](https://wordpress.org/support/topic/conditional-formatting-2/page/2/?output_format=md)
[→](https://wordpress.org/support/topic/conditional-formatting-2/page/2/?output_format=md)

 *  Thread Starter [AmandaEve](https://wordpress.org/support/users/amandaeve/)
 * (@amandaeve)
 * [10 years, 3 months ago](https://wordpress.org/support/topic/conditional-formatting-2/#post-7075509)
 * OMG! I”m a GOd! I used this: [http://clicknathan.com/web-design/conditional-statement-woocommerce-subscriptions/](http://clicknathan.com/web-design/conditional-statement-woocommerce-subscriptions/)
 * but … the buttons are just little squares … no text.
 * Any ideas?
 *  Thread Starter [AmandaEve](https://wordpress.org/support/users/amandaeve/)
 * (@amandaeve)
 * [10 years, 3 months ago](https://wordpress.org/support/topic/conditional-formatting-2/#post-7075517)
 * update … in the single-product/add-to-cart/single.php … i found ` <button type
   =”submit”
    class=”single_add_to_cart_button button alt”><?php echo esc_attr($
   product->single_add_to_cart_text()); ?></button>`
 * so … i need to add the text for the link in there … but what do I put there?
   `
   <?php do_action( 'woocommerce_add_to_cart_button_text' ); ?>`
 * ^ i just made that up … i have no idea what that is.
 *  Thread Starter [AmandaEve](https://wordpress.org/support/users/amandaeve/)
 * (@amandaeve)
 * [10 years, 3 months ago](https://wordpress.org/support/topic/conditional-formatting-2/#post-7075528)
 * okay .. I just added
 *     ```
       add_filter( 'woocommerce_product_single_add_to_cart_text', 'woo_custom_cart_button_text' );    // 2.1 +
   
       function woo_custom_cart_button_text() {
   
               return __( 'View Issue', 'woocommerce' );
   
       }
       ```
   
 * i think it might have worked … i think.
 *  Thread Starter [AmandaEve](https://wordpress.org/support/users/amandaeve/)
 * (@amandaeve)
 * [10 years, 3 months ago](https://wordpress.org/support/topic/conditional-formatting-2/#post-7075557)
 * no … this isn’t working at all.
 * crap. even if the user is not a subscriber the buttons are showing as empty.
 *  Plugin Contributor [Mike Jolley](https://wordpress.org/support/users/mikejolley/)
 * (@mikejolley)
 * [10 years, 3 months ago](https://wordpress.org/support/topic/conditional-formatting-2/#post-7075688)
 * Can you clearly explain what this view button is replacing (on which screen) 
   and where it is going to link to?
 *  Thread Starter [AmandaEve](https://wordpress.org/support/users/amandaeve/)
 * (@amandaeve)
 * [10 years, 3 months ago](https://wordpress.org/support/topic/conditional-formatting-2/#post-7075720)
 * For instance this page: [http://nfldherald.stirlingpublications.com/product/issue5-jan-31-feb-16/](http://nfldherald.stirlingpublications.com/product/issue5-jan-31-feb-16/)
 * the button says add to cart, but i want the button to say and the link to be 
   different if someone is signed in.
 * Right now I have a short code set up so that the ‘View This Issue’ button is 
   only visible to users who are members.\
 *     ```
       [wcm_restrict]
       View Issue Button Here
       [/wcm_restrict]
       ```
   
 * But i don’t want two buttons … I’d like to have one button, but the attributes
   change according to the users membership status.
 * The worst case scenario would be that I have:
 *     ```
       [wcm_restrict]
       View Issue Button Here
       [/wcm_restrict]
   
       [short code that members can't see]
       Add to Cart
       [/short code that members can't see]'
   
       ^ but ... I don't even know if that exists - a short code that restricts members visibility, so only non-members can see it.
       ```
   
 *  Thread Starter [AmandaEve](https://wordpress.org/support/users/amandaeve/)
 * (@amandaeve)
 * [10 years, 3 months ago](https://wordpress.org/support/topic/conditional-formatting-2/#post-7075721)
 * WOW! I just found it: [woocommerce_members_only] Your content here for members
   only… [woocommerce_members_only]
 * [woocommerce_non_members_only] Your content for non-members only here… [woocommerce_non_members_only]
 * To specify membership plans, simply use parameter key (or keys for multiple keys),
   like this:
 * [woocommerce_members_only key=”silver”] Your content for members with plan Silver
   here… [woocommerce_members_only]
 *  Thread Starter [AmandaEve](https://wordpress.org/support/users/amandaeve/)
 * (@amandaeve)
 * [10 years, 3 months ago](https://wordpress.org/support/topic/conditional-formatting-2/#post-7075722)
 * wait – i don’t think that works
 *  Thread Starter [AmandaEve](https://wordpress.org/support/users/amandaeve/)
 * (@amandaeve)
 * [10 years, 3 months ago](https://wordpress.org/support/topic/conditional-formatting-2/#post-7075723)
 * Here is the new shortcode … just in case someone else is looking for it.
 * [wcm_nonmember]
    Whoops, this video is for members only. If you have a membership,
   please log in. If not, you can definitely get access! [Purchase a membership here](https://wordpress.org/membership/?output_format=md).[/
   wcm_nonmember]
 * [wcm_restrict]
    Embedded video displayed to members only. [/wcm_restrict]
 *  Thread Starter [AmandaEve](https://wordpress.org/support/users/amandaeve/)
 * (@amandaeve)
 * [10 years, 3 months ago](https://wordpress.org/support/topic/conditional-formatting-2/#post-7075724)
 * but I don’t know how to put short code around the button – it’s a part of the
   woocommerce set up … and I can’t imagine you could use that shortcode for this
   case.
 *  Plugin Contributor [Mike Jolley](https://wordpress.org/support/users/mikejolley/)
 * (@mikejolley)
 * [10 years, 3 months ago](https://wordpress.org/support/topic/conditional-formatting-2/#post-7075736)
 * Are there function equivalents to those shortcodes? Then you could actually place
   the code within templates/single-product/add-to-cart/subscription.php
 * [https://dl.dropboxusercontent.com/s/wtpg8u9isnihpuj/2016-02-19%20at%2012.43.png?dl=0](https://dl.dropboxusercontent.com/s/wtpg8u9isnihpuj/2016-02-19%20at%2012.43.png?dl=0)
 *  Thread Starter [AmandaEve](https://wordpress.org/support/users/amandaeve/)
 * (@amandaeve)
 * [10 years, 3 months ago](https://wordpress.org/support/topic/conditional-formatting-2/#post-7075789)
 * i don’t think so … i’ve looked. 🙁
 *  Thread Starter [AmandaEve](https://wordpress.org/support/users/amandaeve/)
 * (@amandaeve)
 * [10 years, 3 months ago](https://wordpress.org/support/topic/conditional-formatting-2/#post-7075790)
 * i don’t think so … i’ve looked. 🙁
 *  Plugin Contributor [Mike Jolley](https://wordpress.org/support/users/mikejolley/)
 * (@mikejolley)
 * [10 years, 3 months ago](https://wordpress.org/support/topic/conditional-formatting-2/#post-7075791)
 * I reckon there will be – refer to the docs of the plugin which has wcm_restrict
 *  Thread Starter [AmandaEve](https://wordpress.org/support/users/amandaeve/)
 * (@amandaeve)
 * [10 years, 3 months ago](https://wordpress.org/support/topic/conditional-formatting-2/#post-7075809)
 * Yeah, I found it … but it broke my site … so I had to revert.
 * I used this one.
 *     ```
       if ( wc_memberships_is_product_viewing_restricted() ) {
       echo 'Add To Cart Button';
       } else {
       echo 'View Issue Button';
       }
       ```
   
 * I just put it in the functions.php by itself, just to test – should I put it 
   in or out of the <php?

Viewing 15 replies - 1 through 15 (of 16 total)

1 [2](https://wordpress.org/support/topic/conditional-formatting-2/page/2/?output_format=md)
[→](https://wordpress.org/support/topic/conditional-formatting-2/page/2/?output_format=md)

The topic ‘Conditional Formatting’ is closed to new replies.

 * ![](https://ps.w.org/woocommerce/assets/icon.svg?rev=3234504)
 * [WooCommerce](https://wordpress.org/plugins/woocommerce/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/woocommerce/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/woocommerce/)
 * [Active Topics](https://wordpress.org/support/plugin/woocommerce/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/woocommerce/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/woocommerce/reviews/)

## Tags

 * [add to cart](https://wordpress.org/support/topic-tag/add-to-cart/)
 * [filter](https://wordpress.org/support/topic-tag/filter/)
 * [function](https://wordpress.org/support/topic-tag/function/)
 * [hook](https://wordpress.org/support/topic-tag/hook/)
 * [product](https://wordpress.org/support/topic-tag/product/)
 * [subscription](https://wordpress.org/support/topic-tag/subscription/)

 * 16 replies
 * 2 participants
 * Last reply from: [Mike Jolley](https://wordpress.org/support/users/mikejolley/)
 * Last activity: [10 years, 3 months ago](https://wordpress.org/support/topic/conditional-formatting-2/page/2/#post-7075813)
 * Status: not resolved