• I’m using the membership plugin to restrict some products from buying, because users should buy a yearly membership in order to be able to buy my products.
    I would like to write a function in which if the product “membership” (that unlocks all the other products) is in the cart, woocommerce automatically unlocks all the other products. This because I want users to be able to buy products, without doing a double separate purchase. Membership (to unlock the products) and then products. Actually they can’t because the system tells the users “You have to buy the membership to purchase this product”even if the “membership” product is already in the cart.

    I hope to have described clearly the request, in case not, please ask me further details.

    Thanks a lot

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Support con

    (@conschneider)

    Engineer

    Hi there,

    > I’m using the membership plugin to restrict some products from buying,

    Since each plugin has it’s own structure: Which membership plugin are you using exactly?

    Kind regards,

    Thread Starter lucasddweb

    (@lucasddweb)

    Hi Con

    I’m using “WooCommerce Memberships” by “SkyVerge”

    I added this function in order to insert the product to cart(for not logged users):

    function add_product_to_cart() {
    
                    if ( ! is_user_logged_in(false) ) {
    
                                    global $woocommerce;
    
                                    $product_id = 7660;
    
                                    $found = false;
    
                                    //check if product already in cart
    
                                    if ( sizeof( $woocommerce->cart->get_cart() ) > 0 ) {
    
                                                    foreach ( $woocommerce->cart->get_cart() as $cart_item_key => $values ) {
    
                                                                    $_product = $values['data'];
    
                                                                    if ( $_product->id == $product_id )
    
                                                                                    $found = true;
    
                                                    }
    
                                                    // if product not found, add it
    
                                                    if ( ! $found )
    
                                                                    $woocommerce->cart->add_to_cart( $product_id );
    
                                    } else {
    
                                                    // if no products in cart, add it
    
                                                    $woocommerce->cart->add_to_cart( $product_id );
    
                                    }
    
                    }
    
    }
    
    add_action( 'init', 'add_product_to_cart' );

    This function works correctly, but now i need a function that is able to replicate this scenario:

    If product 7660 (membership product) is in the cart, allow to add to cart all products “available”.

    Actually when i try to add any products to cart without having the subscription active (product_id = 7660 alredy buyed) the system tells me: “you have to buy the membership in order to add this product to cart”. So people is obliged to do 2 separate purchase.

    Thanks a lot

    Thread Starter lucasddweb

    (@lucasddweb)

    up

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Woocommerce Code integration – php functions’ is closed to new replies.