Apply Discount by Cart Amount

February 9, 2021

If you want to apply a discount by cart amount, this article tells how to do this and gives a snippet. Shortly, if the cart total is bigger than your target value, the cart total will be discounted.

Copy & paste the below code to your function.php:

// Woofocus - Discount snippet starts

add_action( 'woocommerce_cart_calculate_fees', 'wf_apply_discount_by_cart_amount' );

function wf_apply_discount_by_cart_amount() {
    $wf_min_amount = get_option('wf_min_amount');
    $wf_min_amount_discount = get_option('wf_min_amount_discount');

    if(WC()->cart->subtotal >  $wf_min_amount){
        WC()->cart->add_fee( 'Fee', -$wf_min_amount_discount );
    }
}
add_action( 'customize_register', 'wf_customizer_register' );


function wf_customizer_register( $wp_customize ) {

    // Create our panels

    $wp_customize->add_panel( 'wfdiscountpanel', array(
        'title'          => __('WooFocus discount Panel', 'wf'),
    ) );

    // Create our sections

    $wp_customize->add_section( 'wf_discount_by_amount' , array(
        'title'             => __('Discount by amount', 'wf'),
        'priority'          => 1,
        'panel'             => 'wfdiscountpanel',
    ) );

    // Create our settings

    $wp_customize->add_setting( 'wf_min_amount' , array(
        'type'          => 'option',
        'transport'     => 'refresh',
    ) );

    $wp_customize->add_control( 'wf_min_amount_control', array(
        'label'      => __('Minimum Amount for Discount', 'wf'),
        'section'    => 'wf_discount_by_amount',
        'settings'   => 'wf_min_amount',
        'priority'   => 1,
        'type'       => 'text',
    ) );

    $wp_customize->add_setting( 'wf_min_amount_discount' , array(
        'type'          => 'option',
        'transport'     => 'refresh',
    ) );

    $wp_customize->add_control( 'wf_min_amount_discount_control', array(
        'label'      => __('Discount Fee', 'wf'),
        'section'    => 'wf_discount_by_amount',
        'settings'   => 'wf_min_amount_discount',
        'priority'   => 1,
        'type'       => 'text',
    ) );

}

// Woofocus - Discount snippet ends

After paste it, WooFocus Discount Panel will be added to the customizer menu as you can see on the picture.

Click “Discount by amount” buton

You can set your discount rule here.For example,

the subtotal on the image is 762.00, so it is bigger than 20 (Minumum Amount for Discount). It means this cart totals will be affected by discount.

762.00 – 400 ( Discount Fee ) equals the new cart total.

Don’t forget to click on the Save button to apply the discount by cart amount. Otherwise, you lose your changes.

For more WooCommerce Tutorials & Tricks, you can follow WooFocus.com.

Tags

What do you think?

What do you think?

58 Comments:
September 17, 2024

Стильные советы по подбору превосходных луков на любой день.
Статьи профессионалов, события, все новинки и мероприятия.
https://mvmedia.ru/novosti/122-gde-luchshe-pokupat-originalnye-brendovye-veshchi-kak-vybrat-nadezhnye-magaziny-i-platformy/

October 3, 2024

Модные советы по выбору модных луков на любой день.
Мнения экспертов, события, все показы и мероприятия.
https://luxe-moda.ru/chic/564-10-prichin-lyubit-brend-brunello-cucinelli/

October 4, 2024

Стильные советы по созданию крутых луков на каждый день.
Заметки стилистов, события, все новые коллекции и шоу.
https://urban-moda.ru/all/749-za-chto-my-lyubim-brend-coach-ikona-amerikanskogo-stilya-i-masterstva/

November 20, 2024

I don’t think the title of your article matches the content lol. Just kidding, mainly because I had some doubts after reading the article.

November 27, 2024

very neat thank you,peerjournal

November 28, 2024

very neat thank you,medicineinsights

November 28, 2024

very neat thank you,pharmares

November 28, 2024

very neat thank you,peerreviewedjournals

December 3, 2024

experience and quality thank you.planetbioplastics

December 3, 2024

experience and quality thank you.osteriailcapodaglio

December 3, 2024

experience and quality thank you.lucagnizio

December 6, 2024

very neat thank you,jukumech

December 6, 2024

very neat thank you,kimmokakko

December 8, 2024

experience and quality thank you.ebiketime

December 8, 2024

experience and quality thank you.hoteldellaspina

December 12, 2024

experience and quality thank you.honefoss.bolkan

December 12, 2024

experience and quality thank you.heimdalbygg

December 12, 2024

experience and quality thank you.gjonnes-bygg

December 16, 2024

very neat thank you,fourcmanagement

December 16, 2024

very neat thank you,fourcmanagement

December 17, 2024

very neat thank you,federalnetworks

December 17, 2024

very neat thank you,federalnetworks

December 18, 2024

very neat thank you,fixcarsny

December 18, 2024

very neat thank you,fixcars

December 18, 2024

very neat thank you,floorbufferbrush

December 20, 2024

very neat thank you,greatneckcollision

December 20, 2024

very neat thank you,greenpowerchemical

December 20, 2024

very neat thank you,gmstowing

December 20, 2024

very neat thank you,handfordoil

December 20, 2024

experience and quality thank you.elgars

December 20, 2024

experience and quality thank you.pilotexamsdgca

December 21, 2024

very neat thank you,hamptonssepticservices

December 21, 2024

very neat thank you,horizonconceptinc

December 21, 2024

very neat thank you,housatonicpaper

December 21, 2024

very neat thank you,icsatc

December 23, 2024

very neat thank you,gritbrush

December 23, 2024

very neat thank you,goelectricnj

December 23, 2024

very neat thank you,icsatc

December 23, 2024

very neat thank you,imperialvendinginc

December 24, 2024

very neat thank you,industrialfinishings

December 24, 2024

very neat thank you,harrishardware

December 24, 2024

very neat thank you,insurancemarketingpros

December 24, 2024

very neat thank you,ircinc

December 24, 2024

very neat thank you,gettingerfeathers

December 24, 2024

experience and quality thank you.iasautomotive

December 25, 2024

very neat thank you,fninc

December 25, 2024

very neat thank you,sandvet

December 25, 2024

very neat thank you,tomscorvetteshop

December 25, 2024

very neat thank you,ttandlcontracting

December 25, 2024

very neat thank you,valley-stream-plumber

December 26, 2024

very neat thank you,blessingconstructionny

January 11, 2025

На этом ресурсе посетители можете ознакомиться с полезной информацией о лечении депрессии у людей старшего возраста. Здесь собраны советы и описания способов борьбы с данным заболеванием.
http://glazzette.com/uncategorized/hello-world/

January 15, 2025

Great! Thank you so much for sharing this. Visit my websitee: free stresser

January 19, 2025

I don’t think the title of your article matches the content lol. Just kidding, mainly because I had some doubts after reading the article.

January 26, 2025

Программа видеонаблюдения – это современный инструмент для обеспечения безопасности , сочетающий инновации и простоту управления.
На веб-ресурсе вы найдете детальные инструкции по выбору и настройке систем видеонаблюдения, включая облачные решения , их сильные и слабые стороны.
Программа видеонаблюдения
Рассматриваются комбинированные системы, сочетающие облачное и локальное хранилище , что делает систему универсальной и эффективной.
Важной частью является описание передовых аналитических функций , таких как определение активности, идентификация элементов и другие AI-технологии .

January 30, 2025

This extensive resource serves as an thorough guide to the world of modern video surveillance, offering valuable information for both experienced CCTV installers and business owners seeking to strengthen their security infrastructure.
Video Surveillance
The site offers a detailed analysis of remote video surveillance systems, exploring their advantages, limitations, and practical applications.

February 1, 2025

На этом сайте размещены свежие события РФ и всего мира.
Здесь можно прочитать значимые новостные материалы по разным темам .
https://ecopies.rftimes.ru/
Следите за ключевых событий ежедневно .
Проверенная информация и актуальность в каждом материале .

February 3, 2025

Thanks for sharing. I read many of your blog posts, cool, your blog is very good.

Leave a Reply

Your email address will not be published. Required fields are marked *

More notes