• Resolved ariebl

    (@ariebl)


    Hi
    Now I have a discout of 10% on the total card when buying 3 and more product in one card
    I did it by the following code placing in function.php

    add_action('woocommerce_cart_calculate_fees' , 'custom_cart_discount', 20, 1);
    function custom_cart_discount( $cart ){
        if ( is_admin() && ! defined( 'DOING_AJAX' ) )
            return;
        // Limitations: Only when there is 5 or more non on sale items in cart
        $starting_limit = 3;
    
        // Initialising variables
        $not_on_sale_subtotal = $discount = $items_count = 0;
    
        // Iterating through each item in cart
        foreach( $cart->get_cart() as $cart_item ){
    
            // For cart items is not on sale
            if( ! $cart_item['data']->is_on_sale() ){
                $not_on_sale_subtotal += (float) $cart_item['line_subtotal'];
                $items_count += $cart_item['quantity'];
            }
        }
        // Discount calculation
        $discount = $not_on_sale_subtotal * 0.1;
        // Applied discount only cart items that are not on sale
        if( $discount && $items_count >= $starting_limit )
            $cart->add_fee( '???? ???? 10%', -$discount );

    There is a need now for a different discount:
    A gradual discount on the product itself (and not on total) according to the quantity of products and the price of the product
    When buying one product: 10%
    On the purchase of 2 products: 10% on the expensive product and 20% for the cheapest product
    When buying 3 products: the cheapest product will receive the biggest discount (30%) and the most expensive product will receive the smallest discount (10%)

    The page I need help with: [log in to see the link]

Viewing 3 replies - 1 through 3 (of 3 total)
  • Hi,

    Try with plugins of dynamic price and discounts. By googling you can find some plugins (free and paid).

    Good luck!

    Thread Starter ariebl

    (@ariebl)

    Thanks for the replay but till now I did not find a plugin
    I need a discount by all this 3 conditions:
    1) Number of products in the cart
    2) By product price (the cheapest gets the higher discount)
    3) only for not in sale oroducts

    for example:
    If you buy 2 products, you get
    1) 10% discount for the expensive product
    2) and 20% discount for the cheapest product

    Plugin Support Fernando a11n

    (@fhaps)

    Automattic Happiness Engineer

    Hi there,

    This seems like a very custom setup, and I agree that a plugin like Dynamic Pricing would not be able to set up the discounts taking into account all of those variables.

    Something like this would require deeper custom development indeed, but I’m afraid we can’t help with writing the exact code you need. If you’d want to get some coding help, you may reach out to someone at Codeable to get a quote for their services.

    Given that this thread has been opened for a while and we haven’t received more suggestions from the community, I’m going to close this thread for now – if you have any further questions, you can start a new thread.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘discount per product’ is closed to new replies.