Repository Forums Support WooCommerce Extended Coupon Features PRO Contact us form – no reply

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #20621
    Adam Harris
    Participant

    Hi,

    I completed your contact form a few weeks ago asking for assistance with this plugin but i received no reply. Is that not monitored?

    #20624
    Soft79
    Keymaster

    I think I missed it. What is your question?

    #20652
    Adam Harris
    Participant

    I use a coupon to give a free product for every set of certain dog collars and leads.

    The problem I have is that I only want it to work when someone buy 1x collar and 1x dog lead. Then I would want it to repeat for each purchase of a set after that.

    So 1x collar 1x lead = 1 free product
    2x collar 2x lead = 2 free product etc.

    The issue I have is as I am pointing it to the category it would pick up 2x collar under the same coupon and give a free product then.

    How can we fix this?

    There are 3 collar categories and 2 lead categories.

    I’m currently using the Product categories (OR) and including all 5 categories in that field.

    Minimum quantity of matching products = 2.

    #20654
    Soft79
    Keymaster

    Hi,

    • Use ‘Categories ‘AND’ and choose the categories to restrict to
    • Set min quantity of matching products to: 2
    • Enable ‘Allow multiplication of the free products’
    • Paste the following snippet to your child theme

    NOTE: This will only work if you use a category that contains all collars and one that contains all leads. Otherwise this snippet needs customization.

    /**
     * If 'Categories AND' and multiply free products are enabled,
     * limit the amount of free products to the amount a product of each category is in the cart.
     */
    add_filter( 
        'wjecf_free_product_amount_for_coupon', 
        function( $coupon_qty, $coupon ) {
            $categories_and = $coupon->get_meta( '_wjecf_categories_and' ) == 'yes';
            if ( ! $categories_and ) return $coupon_qty;
            foreach ( $wc_discounts->get_items() as $item_key => $item ) {
                if ( ! $item->product ) continue;
                $product_id = $item->product->get_id();
                if ( 'product_variation' == get_post_type( $product_id ) ) {
                    $product_id = $item->product->get_parent_id();
                }
                $product_cats = array_merge( $product_cats, wp_get_post_terms( $product_id, 'product_cat', array( 'fields' => 'ids' ) ) );
            }
            //Filter used by WJECF_WPML hook
            $product_cats = apply_filters( 'wjecf_get_product_cat_ids', $product_cats );
            //check if every single category is in the cart
            foreach ( apply_filters( 'wjecf_get_product_cat_ids', $coupon->get_product_categories() ) as $cat_id ) {
                $count = array_count_values( $product_cats, $cat_id );
                $count_qty = min( $coupon_qty, $count );
            }
            return $coupon_qty;
        }, 10, 2
    );
Viewing 4 posts - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.