• 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/

Viewing 15 replies - 1 through 15 (of 16 total)
  • Thread Starter AmandaEve

    (@amandaeve)

    OMG! I”m a GOd! I used this: http://clicknathan.com/web-design/conditional-statement-woocommerce-subscriptions/

    but … the buttons are just little squares … no text.

    Any ideas?

    Thread Starter AmandaEve

    (@amandaeve)

    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

    (@amandaeve)

    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

    (@amandaeve)

    no … this isn’t working at all.

    crap. even if the user is not a subscriber the buttons are showing as empty.

    Plugin Author Mike Jolley (a11n)

    (@mikejolley)

    Can you clearly explain what this view button is replacing (on which screen) and where it is going to link to?

    Thread Starter AmandaEve

    (@amandaeve)

    For instance this page: 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

    (@amandaeve)

    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

    (@amandaeve)

    wait – i don’t think that works

    Thread Starter AmandaEve

    (@amandaeve)

    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.
    [/wcm_nonmember]

    [wcm_restrict]
    Embedded video displayed to members only.
    [/wcm_restrict]

    Thread Starter AmandaEve

    (@amandaeve)

    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 Author Mike Jolley (a11n)

    (@mikejolley)

    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

    Thread Starter AmandaEve

    (@amandaeve)

    i don’t think so … i’ve looked. 🙁

    Thread Starter AmandaEve

    (@amandaeve)

    i don’t think so … i’ve looked. 🙁

    Plugin Author Mike Jolley (a11n)

    (@mikejolley)

    I reckon there will be – refer to the docs of the plugin which has wcm_restrict

    Thread Starter AmandaEve

    (@amandaeve)

    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)
  • The topic ‘Conditional Formatting’ is closed to new replies.