• Resolved gregorr64

    (@gregorr64)


    Is it possible to only allow products to be purchased if one product of each category is in the cart? For example, in order to buy a sink they must also buy a tap and vice versa. They must choose one sink and one tap to be able to purchase either.

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author SomewhereWarm

    (@somewherewarm)

    Hey @gregorr64

    Yes, this should be possible using the wc_pd_dependency_relationship filter. By default, dependencies are evaluated using OR logic, but this snippet will force an AND logic:

    add_filter( 'wc_pd_dependency_relationship', 'sw_pd_dependency_relationship' );
    
    function sw_pd_dependency_relationship( $product ) {
    return 'and';
    } 

    If you are not certain how to use snippets like this, I’d suggest having a look at this plugin — you may find it quite useful as it allows you to manage all your snippets in one place.

    Cheers,
    Manos

    • This reply was modified 6 years, 4 months ago by SomewhereWarm.
    Thread Starter gregorr64

    (@gregorr64)

    Hi Manos,

    Thanks for the reply. Does this not mean that it would only work for one of the categories as they need to add one to the cart without any dependencies to be able to add the other.

    For example, in order to purchase a tap they must already have a sink in their basket. But this would mean they could buy a sink without a tap?

    Thanks,
    Gregor

    Plugin Author SomewhereWarm

    (@somewherewarm)

    Hey Gregor,

    Maybe I misunderstood your original question — it’s not possible to attach dependencies at category-level, only at product-level.

    Is this what you are asking?

    Cheers,
    Manos

    Thread Starter gregorr64

    (@gregorr64)

    Hi Manos,

    What I meant is that both categories must be bought together.

    I’ve since worked out a different way to implement this using calculated fields.

    Thanks for the help.

    Cheers,
    Gregor

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Allow products to be purchased if one product from each category is in cart’ is closed to new replies.