Repository Forums Support WooCommerce Extended Coupon Features PRO composite products count

Viewing 10 posts - 1 through 10 (of 10 total)
  • Author
    Posts
  • #19423
    almostretired
    Participant

    Hi, we are using WooCommerce Extended Coupon Features PRO with WooCommerce Composite Products

    Can Coupons based on the cart quantity exclude the component quantity of composite products while including them for a percentage discount?

    The problem comes up when we have a discount for a specific quantity. When someone chooses a composite product, it is considered 2 or more products in the cart even tho it is only one product.

    We would like to apply a quantity discount. Can you help us do this?

    Thanks.

    #19425
    Soft79
    Keymaster

    Can you send us a screenshot of a cart with composite products?

    #19426
    almostretired
    Participant

    Yes, here’s the screenshot. https://capture.dropbox.com/5aRbS53GGbovkDH3

    In this image, the product “Amateur Radio Coax Builder” is one product. That product is made up of 1 wire with a choice of the number of feet, and up to two connectors. The cart is applying a 3+ discount since it is counting each foot of wire and each connector.

    #19427
    Soft79
    Keymaster

    I’m not sure if this will work, this snippet will not count products of which the price is 0. Replace ‘my_coupon_code’ with the actual coupon code. If this snippet doesn’t do anything please send the snippet to the author of the Composite Product plugin and ask how we can detect that it’s a ‘child’-product of a composite product. Maybe the $values array contains an item that tells us the item is part of a composite product.

    
    add_filter(
        'woocommerce_coupon_is_valid_for_product', 
        function ( $valid, $product, $coupon, $values ) {
            if ( $coupon->get_code() === 'my_coupon_code' && $product->get_price() == 0 ) {
                $valid = false;
            }
            return $valid;
        }, 10, 4
    );
    
    
    #19430
    almostretired
    Participant

    We’re using the official WooCommerce Composite Products plugin. https://woocommerce.com/products/composite-products/

    The ‘composite_parent’ parent property should do what we need. For our purposes we don’t want to check specific coupon codes, since I doubt the client will ever include components in the quantity.

    Page with info: https://woocommerce.com/document/composite-products-data-structures-storage/

    We haven’t found the right combination of hooks and functions at the moment.

    Excluding by price doesn’t work because our component items alter the price. We would end up with a free product and a discount.

    #19431
    Soft79
    Keymaster

    Great info. Then this snippet should work. Make sure to replace my_coupon_code. Please note that the snippet is untested.

    
    add_filter(
        'woocommerce_coupon_is_valid_for_product', 
        function ( $valid, $product, $coupon, $values ) {
            if ( $coupon->get_code() === 'my_coupon_code' && array_key_exists( 'composite_parent', $values ) ) {
                $valid = false;
            }
            return $valid;
        }, 10, 4
    );
    
    #19433
    almostretired
    Participant

    This gives the same result as excluding based on the category. The count matches, but the percentage discount is based on the two included items only. Toggling Allow discount on the cart with excluded items does not change this behavior.

    #19437
    Soft79
    Keymaster

    That’s too bad. Our plugin can only discount products that are also considered for the total quantity of items. We could introduce a filter in the next version that can be used to alter the quantity; same as above snippet, but it will not change the validity of the coupon for the product.

    I will see if we can fit this in next week, maybe not an official release, but a preliminary release that you can already start using.

    #19440
    Soft79
    Keymaster

    Ok, why wait? I’ve published 3.3.3-dev.1 which you can download on your account page https://www.soft79.nl/my-account/ .

    It should work with this updated snippet:

    
    add_filter(
        'wjecf_coupon_item_quantity',
        function ( $item_quantity, $coupon, $item, $wc_discounts ) {
            if ( $coupon->get_code() === 'my_coupon_code' && array_key_exists( 'composite_parent', $item->object ) ) {
                $item_quantity = 0;
            }
            return $item_quantity;
        }, 10, 4
    );
    
    #19452
    almostretired
    Participant

    Sorry for the delay on this. Thanks so much for working this out. We did change one line of the code for our purposes.

    if ( array_key_exists( ‘composite_parent’, $item->object ) ) {

    I don’t think our client will ever make a sale on quantities that includes the components, so this version should be easier than checking for specific codes.

    This works! Thanks again for all of your help!

Viewing 10 posts - 1 through 10 (of 10 total)
  • You must be logged in to reply to this topic.