Support » Plugin: WooCommerce » Compare Product Attribute

  • harisrethink

    (@harisrethink)


    Hi

    I have a product variation called delivery slot which has 2 option, standard and pre-noon.

    If somebody chooses standard for one product and add to basket. I would like to make sure that the next product they choose can’t have pre-noon.

    So at the point of adding to basket, I would like an error to show up to say you can’t add that product with a different delivery slot.

    In theory, I need a combination of getting the variations that exist for the product in the basket and using the woocommerce_add_to_cart_validation hook to validate against the variations of the product being added.

    Thank You

    Haris

Viewing 1 replies (of 1 total)
  • harisrethink

    (@harisrethink)

    So I’ve managed to do the first bit

    $cart = WC()->cart->get_cart();
    foreach ($cart as $cart_item) {
    $name = $cart_item[‘data’]->name;
    $delivery = $cart_item[‘variation’][‘attribute_pa_delivery-slot’];

    echo ‘

    '.print_r(['name' => $name, 'delivery_slot' => $delivery], true).'

    ‘;
    }

    Now I just need to compare with the [‘variation’][‘attribute_pa_delivery-slot’] of the product that is to be added.

Viewing 1 replies (of 1 total)
  • You must be logged in to reply to this topic.