Forum Replies Created

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter lucasddweb

    (@lucasddweb)

    up

    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

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