skip to Main Content

WordPress Code Snippets


Adding Custom Fees to the WooCommerce Cart

Leverage this action hook to add extra fees to the cart. Perfect for handling shipping, taxes, or promotional discounts.

add_action('woocommerce_cart_calculate_fees', 'codebykp_custom_cart_fees');
function codebykp_custom_cart_fees() {
    if (WC()->cart->subtotal > 100) {
        WC()->cart->add_fee(__('Discount', 'woocommerce'), -10); // Add discount if subtotal exceeds 100
    }
}


I’m a WordPress developer with 10+ years of experience in WooCommerce and custom plugins. I combine technical expertise with design flair to help you create standout, user-friendly websites. Let’s transform your digital presence!

Best WordPress Hosting
Back To Top
Search