Skip to content
  • Quick Ref
  • Contact
  • About
wpcanyon.com

wpcanyon.com

Tag: Checkout

WooCommerce: Add a handling fee or surcharge

Posted on August 19, 2025 By Admin No Comments on WooCommerce: Add a handling fee or surcharge

WooCommerce: Add a Handling Fee or Surcharge

Adding a handling fee or surcharge to your WooCommerce store can help cover extra costs such as packaging, payment processing, or special delivery requirements. This tutorial shows you how to woocommerce add handling fee quickly and effectively using custom code snippets, ensuring the fee appears transparently during checkout.

Quick Fix: Add a Handling Fee in WooCommerce

  1. Access your WordPress theme’s functions.php file or use a site-specific plugin.
  2. Copy and paste the provided PHP code snippet to add a fixed or percentage-based handling fee.
  3. Save changes and test the checkout to confirm the fee appears correctly.

Why This Happens

WooCommerce by default does not include a handling fee option. Many store owners need to add extra charges to cover costs beyond product prices and shipping. Since WooCommerce’s built-in fees are flexible but require manual input, adding a custom handling fee via code automates this process and ensures consistent application.

Requirements

  • WooCommerce installed and active on your WordPress site.
  • Access to your theme’s functions.php file or a custom plugin for adding PHP code.
  • Basic familiarity with editing WordPress files or using a code snippet plugin.

Step-by-Step: Adding a Handling Fee in WooCommerce

1. Backup Your Site

Before making any code changes, always backup your site to avoid accidental loss or downtime.

2. Open Your Theme’s functions.php File

Use FTP, cPanel File Manager, or the WordPress theme editor to open functions.php located in your active theme folder.

3. Add the Handling Fee Code Snippet

Paste the following code at the end of the functions.php file. This example adds a fixed handling fee of $5.00 to every order:

add_action( 'woocommerce_cart_calculate_fees', 'add_handling_fee' );
function add_handling_fee() {
    if ( is_admin() && ! defined( 'DOING_AJAX' ) )
        return;

    $handling_fee = 5.00; // Fixed handling fee amount
    WC()-cart-add_fee( 'Handling Fee', $handling_fee, true, '' );
}

4. Save the File

Save your changes and upload the file back to the server if using FTP.

5. Test the Checkout

Add products to your cart and proceed to checkout. You should see the “Handling Fee” line item added to the order totals.

Optional: Percentage-Based Handling Fee

If you prefer a handling fee based on a percentage of the cart subtotal, use this code instead:

add_action( 'woocommerce_cart_calculate_fees', 'add_percentage_handling_fee' );
function add_percentage_handling_fee() {
    if ( is_admin() && ! defined( 'DOING_AJAX' ) )
        return;

    $percentage = 0.05; // 5% handling fee
    $cart_subtotal = WC()-cart-get_subtotal();
    $handling_fee = $cart_subtotal * $percentage;

    WC()-cart-add_fee( 'Handling Fee (5%)', $handling_fee, true, '' );
}

Common Pitfalls

  • Fee not showing: Ensure the code is placed in the active theme’s functions.php or a site-specific plugin, and WooCommerce is active.
  • Fee applied multiple times: The code checks for admin and AJAX contexts to prevent duplication. Avoid adding the snippet multiple times.
  • Tax settings: The third parameter in add_fee() controls if the fee is taxable. Set it to true or false depending on your tax rules.
  • Compatibility: Custom code may conflict with other plugins that modify cart fees. Test thoroughly.

Works On

Environment Compatibility
Web Servers Apache, Nginx, LiteSpeed
Hosting Panels cPanel, Plesk, DirectAdmin
WordPress Versions WooCommerce compatible versions (4.0+ recommended)

FAQ

Q1: Can I add different handling fees based on payment method?

Yes. You can check the chosen payment method using WC()-session-get('chosen_payment_method') inside the fee function and conditionally add fees.

Q2: How do I make the handling fee tax-exempt?

Set the third parameter of add_fee() to false. For example: WC()-cart-add_fee( 'Handling Fee', $fee, false );

Q3: Can I add handling fees only for specific products or categories?

Yes. Use WC()-cart-get_cart() to loop through cart items and conditionally apply fees based on product IDs or categories.

Q4: Will this handling fee appear in order emails and invoices?

Yes. WooCommerce includes fees in order totals, so the handling fee will appear in emails, invoices, and admin order details.

Q5: Is there a plugin alternative to adding handling fees?

Yes. Plugins like “WooCommerce Advanced Fees” or “WooCommerce Extra Fees Plugin” offer GUI-based fee management without coding.…

WooCommerce How‑tos

WooCommerce: Remove checkout fields safely (no plugin)

Posted on August 19, 2025 By Admin No Comments on WooCommerce: Remove checkout fields safely (no plugin)

WooCommerce: Remove Checkout Fields Safely (No Plugin)

When customizing your WooCommerce checkout page, you might want to remove unnecessary fields to simplify the user experience or tailor the form to your business needs. However, removing checkout fields incorrectly can cause errors or affect order processing. This guide shows you how to safely remove WooCommerce checkout fields without using a plugin by adding custom code to your theme or child theme.

Quick Fix: Remove WooCommerce Checkout Fields

  1. Identify the checkout fields you want to remove.
  2. Add a custom PHP function to your theme’s functions.php file or a site-specific plugin.
  3. Use the woocommerce_checkout_fields filter to unset the fields you want to remove.
  4. Test the checkout page to ensure the fields are removed and the checkout works correctly.

Why This Happens

WooCommerce checkout fields are defined in an array that includes billing, shipping, and additional fields. By default, WooCommerce requires certain fields for processing orders, but many fields are optional or customizable. Removing fields directly from the template files or via plugins without using the proper hooks can cause validation errors or break the checkout process. Using the woocommerce_checkout_fields filter allows you to safely modify the checkout fields array before it is rendered and validated.

Requirements

  • Access to your WordPress site’s theme files (preferably a child theme).
  • Basic knowledge of PHP and WordPress theme editing.
  • WooCommerce plugin installed and active.
  • FTP or hosting file manager access to restore files if needed.

Step-by-Step: Remove Checkout Fields in WooCommerce

  1. Backup your site. Always create a backup before editing theme files.
  2. Access your theme’s functions.php file. You can do this via Appearance > Theme Editor in WordPress admin or through FTP/cPanel file manager.
  3. Add the following code snippet to remove unwanted checkout fields. Customize the fields you want to remove by unsetting them from the array.
function custom_remove_woocommerce_checkout_fields( $fields ) {
    // Remove billing phone field
    unset( $fields['billing']['billing_phone'] );

    // Remove billing company field
    unset( $fields['billing']['billing_company'] );

    // Remove shipping address 2
    unset( $fields['shipping']['shipping_address_2'] );

    // Remove order comments
    unset( $fields['order']['order_comments'] );

    return $fields;
}
add_filter( 'woocommerce_checkout_fields', 'custom_remove_woocommerce_checkout_fields' );
  1. Save the file and test your checkout page. Visit the checkout page and verify the specified fields are no longer visible.
  2. Check order processing. Place a test order to ensure no validation errors occur and the order completes successfully.

Common Pitfalls

  • Removing required fields: Some fields like billing email or billing address are required for order processing. Removing them can cause checkout validation errors.
  • Editing parent theme files: Avoid editing the parent theme directly; use a child theme to prevent losing changes during updates.
  • Cache issues: Clear your site and browser cache after making changes to see the updated checkout form.
  • Plugin conflicts: Other plugins may add or modify checkout fields; test changes with plugins disabled if issues arise.

Works On

This method works on sites running WooCommerce on:

  • Apache or Nginx web servers
  • LiteSpeed servers
  • Hosting panels like cPanel and Plesk
  • Any WordPress theme that supports WooCommerce (preferably child themes)

FAQ

Q: Can I remove all checkout fields using this method?
A: You can remove most optional fields, but some fields are required by WooCommerce and should not be removed to avoid checkout errors.
Q: Will this code be overwritten when WooCommerce updates?
No. Since the code is added to your theme’s functions.php or a custom plugin, WooCommerce updates will not overwrite it.
Q: How do I find the exact field names to remove?
You can inspect the checkout form HTML or refer to WooCommerce documentation. Common field keys include billing_phone, billing_company, shipping_address_2, and order_comments.
Q: Can I add fields back later?
Yes. To add fields back, simply remove the unset() line for that field or add custom fields using the same woocommerce_checkout_fields filter.
Q: Is it better to use a plugin for this?
While plugins offer UI-based field management, using code is more lightweight and gives you full control without adding extra plugins.
…
WooCommerce How‑tos

Recent Posts

  • Top WordPress Themes for Blogs in 2025
  • WordPress Admin Panel Trick: Adding ID Field to the Posts Listing
  • Solution previous_posts_link and next_posts_link Not Working
  • Show Top Commentators in WordPress Without a Plugin
  • How to Style Admin Comments in WordPress

Recent Comments

    Archives

    • August 2025

    Categories

    • Admin & Blocks
    • Admin & UI
    • Automation
    • Automation & Plugins
    • Comments
    • Comparisons
    • Database & Revisions
    • Developer Snippets
    • Fixes & Errors
    • Media & Thumbnails
    • Queries & Pagination
    • Security
    • Speed & Security
    • Tips & Tricks
    • WooCommerce How‑tos
    • WordPress Snippets
    • WordPress Themes
    • Terms & Conditions
    • Affiliate Disclosure

    Copyright © 2025 wpcanyon.com.

    Powered by PressBook WordPress theme

    Also by the maker of MySurveyReviews.com