• Resolved saurabhkamyab

    (@saurabhkamyab)


    User must purchased any one of the product in both categories
    see image below

    Here i need “and” condition between both category
    & “or” condition in category

    for eg. user is only eligible to purchase the current product if he purchased any of on product in each category
    eligible = category1(product.1) + category2(product.1 or product.2 )

    i hope you will understand what i exactly want
    let me know i can achieve my result with this plugin…

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

    (@somewherewarm)

    Hi there @saurabhkamyab

    First of all, please accept my apologies it took us so long to reply to your request! I see that we have replied to threads that were opened after this one, so it looks like this thread fell through the cracks ??

    By default, there is an ‘or’ relationship between the terms you add in the Product/Category Dependencies field. This means that even if one product that belongs in one of the selected Categories is in the cart, customers will be able to purchase the current product.

    As far as I understand, you’d like to create a more sophisticated rule, where customers will be allowed to purchase this product if they have purchased one product from each of the Categories you have selected — this would mean having an ‘and’ relationship between the Categories you have selected. Is this correct?

    If so, then please use the following snippet:

    add_filter( 'wc_pd_dependency_relationship', 'sw_pd_force_and_relationship', 10, 2 );
    
    function sw_pd_force_and_relationship( $relationship, $product ) {
    
    	if ( in_array( $product->get_id(), array( 123, 456, ) ) ) {
    		$relationship = 'and';
    	}
    	return $relationship;
    }

    Before using this snippet, please replace 123 and 456 with the IDs of the products to which you’d like it to apply (from the ones that have Product Dependencies rules).

    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.

    Let me know if this helps! Again, I’m very sorry for taking so long to reply to you!

    Cheers,
    Maria Chekimoglou
    Support Team Lead | SomewhereWarm | https://somewherewarm.com/

    • This reply was modified 3 years, 9 months ago by SomewhereWarm.
    Plugin Author SomewhereWarm

    (@somewherewarm)

    Hey @saurabhkamyab,

    Since we haven’t heard back from you in a while, I am going to mark this thread as resolved. Feel free to open a new one if there is anything else we can help with!

    Cheers,
    Jason Kytros
    Support Engineer

    SomewhereWarm SMPC
    https://somewherewarm.gr/

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Category Dependancy with and and within category or’ is closed to new replies.