Open any product in WooCommerce, and you get 2 price boxes: Regular price and Sale price. There’s no built-in field for charging a little extra when a customer picks an option on the product page.
That becomes a problem the moment you sell anything with paid extras, like gift wrapping, custom engraving, or premium packaging, that should each add to the order total.
This guide covers both ways to fix it: a plugin (Advanced Product Fields) if you’d rather not touch code, and custom PHP for developers who want to avoid another dependency.
But first, let’s see all the different variations of an “extra price field.”
What an “extra price field” means in WooCommerce
If you need an “extra price field,” chances are you’re after one of these 3 things:
- Surcharge fields: Store-defined extras that add to the cart total when selected, like gift wrapping or engraving. This guide focuses on these.
- Display-only labels: Text next to the price that doesn’t change what’s charged, like “$12 per 100g.” Answered just below.
- Customer-defined pricing: The shopper enters their own price, like donations or pay-what-you-want.
Need the display-only version? Extra Price Fields for WooCommerce handles it without code, showing a label next to the price. Developers can do the same with a single woocommerce_get_price_html filter that appends the text. Either way, the label is cosmetic, and it doesn’t change the cart total.
Looking for cost price instead? That’s the wholesale (COGS) figure stored in admin for your records, not a customer-facing charge, so it needs a different solution.
Add a surcharge field with a plugin
Advanced Product Fields (APF) adds custom fields to any WooCommerce product, and a paid extra like gift wrapping is one of the simplest things it does.
The plugin ships with 18+ field types, so the same tool that adds a gift wrapping checkbox can also add engraving text boxes, image swatches for wrapping paper, file uploads for custom artwork, date pickers for delivery, and dropdowns for packaging tiers. Almost any field can carry its own price, which turns a plain product page into a full configurator without a line of code.
Here’s the setup for a “+$5 gift wrapping” checkbox:
- Download the plugin and go to Plugins → Add new → Upload plugin → Install Now.
- Create or edit the product you want to sell and set its base price in the General tab.
- Open the Custom fields tab and click Add your first field.

- Set Type to True/False for a single on/off checkbox.

- Set the Label to “Add gift wrapping” and use the Instructions line for a note like “Adds $5 at checkout.”

- Scroll to the Pricing setting, switch it on, and choose Flat fee with an amount of 5. To charge per item, pick Quantity based flat fee so the $5 multiplies by quantity.

- Update the product.
Visit the page, and APF shows 2 things automatically: a pricing hint beside the field, and a pricing summary above the add-to-cart button. The summary splits the cost into product price, options total, and grand total, so shoppers see the math before they buy.

Other useful fields for extra pricing
A surcharge checkbox is the starting point. A few other APF fields solve pricing problems a simple fee can’t:
- Products field: Links an option to a real WooCommerce product instead of a plain label, so its price, SKU, and stock stay tracked. Selecting the option adds that product to the cart and reduces its inventory, which is ideal for add-ons you actually hold stock of, like a branded gift box.

- Number field with amount × field value: Multiplies your set price by whatever number the customer enters, covering per-unit charges and pay-what-you-want donations in a single field.
- Calculation and formula pricing: Prices a product from the customer’s own inputs, like charging per square meter for a made-to-measure blind.
- Percentage fee: Adds a fee as a percentage of the base price, keeping handling or insurance charges proportional across products of different values.
- Image and color swatches: Turn premium materials or finishes into clickable options, each carrying its own price.
Add an extra price field with code
Prefer to skip another plugin? You can build the same surcharge as a small custom plugin of your own, with no third-party dependency and full control over the markup.
The goal is to match the plugin experience: A gift-wrapping checkbox and an engraving field on the product page, a $5 fee added to the cart, and both details carried through to checkout and the order confirmation email. The code works with classic and block themes alike.
Build it as a dedicated plugin rather than editing your theme’s functions.php, so it survives theme switches:
- In
wp-content/plugins/, create a folder named wc-gift-wrap-surcharge. - Inside it, create a file named wc-gift-wrap-surcharge.php.
- At the top of that file, add a plugin header so WordPress lists it. The minimum is the plugin name:
/*
* Plugin Name: Gift Wrap Surcharge
*/Code language: PHP (php)
- Below the header, add the surcharge code:
add_action( 'woocommerce_before_add_to_cart_button', function () {
echo '<div class="gift-wrap-field" style="margin:1em 0;">'
woocommerce_form_field( 'gift_wrap', [
'type' => 'checkbox',
'label' => __( 'Add gift wrapping (+$5)', 'your-textdomain' ),
'class' => [ 'form-row-wide' ],
], '' );
woocommerce_form_field( 'engraving_message', [
'type' => 'text',
'label' => __( 'Engraving message', 'your-textdomain' ),
'placeholder' => __( 'Optional message', 'your-textdomain' ),
'class' => [ 'form-row-wide' ],
], '' );
echo '</div>';
} );
//Save selections into cart item
add_filter( 'woocommerce_add_cart_item_data', function ( $cart_item_data, $product_id ) {
if ( isset( $_POST['gift_wrap'] ) ) {
$cart_item_data['gift_wrap'] = 'yes';
$cart_item_data['unique_key'] = md5( microtime() . rand() );
}
if ( ! empty( $_POST['engraving_message'] ) ) {
$cart_item_data['engraving_message'] = sanitize_text_field( wp_unslash( $_POST['engraving_message'] ) );
$cart_item_data['unique_key'] = md5( microtime() . rand() );
}
return $cart_item_data;
}, 10, 2 );
//Display in cart and checkout
add_filter( 'woocommerce_get_item_data', function ( $item_data, $cart_item ) {
if ( ! empty( $cart_item['gift_wrap'] ) ) {
$item_data[] = [
'name' => __( 'Gift wrapping', 'your-textdomain' ),
'value' => __( 'Yes (+$5)', 'your-textdomain' ),
];
}
if ( ! empty( $cart_item['engraving_message'] ) ) {
$item_data[] = [
'name' => __( 'Engraving message', 'your-textdomain' ),
'value' => wc_clean( $cart_item['engraving_message'] ),
];
}
return $item_data;
}, 10, 2 );
//Add $5 fee per wrapped item
add_action( 'woocommerce_cart_calculate_fees', function ( $cart ) {
if ( is_admin() && ! defined( 'DOING_AJAX' ) ) {
return;
}
$gift_wrap_count = 0;
foreach ( $cart->get_cart() as $cart_item ) {
if ( ! empty( $cart_item['gift_wrap'] ) ) {
$gift_wrap_count += $cart_item['quantity'];
}
}
if ( $gift_wrap_count > 0 ) {
$cart->add_fee(
__( 'Gift wrapping', 'your-textdomain' ),
5 * $gift_wrap_count,
false
);
}
} );
//Save to order line item so it appears in admin + customer emails
add_action( 'woocommerce_checkout_create_order_line_item', function ( $item, $cart_item_key, $values, $order ) {
if ( ! empty( $values['gift_wrap'] ) ) {
$item->add_meta_data( __( 'Gift wrapping', 'your-textdomain' ), __( 'Yes (+$5)', 'your-textdomain' ), true );
}
if ( ! empty( $values['engraving_message'] ) ) {
$item->add_meta_data( __( 'Engraving message', 'your-textdomain' ), $values['engraving_message'], true );
}
}, 10, 4 );
// Conditional display of the engraving field only when gift wrap is checked
add_action( 'wp_footer', function () {
if ( ! is_product() ) {
return;
}
?>
<script>
jQuery(function($) {
const engraving = $('#engraving_message_field');
function toggleEngraving() {
engraving.toggle($('#gift_wrap').is(':checked'));
}
toggleEngraving();
$(document).on('change', '#gift_wrap', toggleEngraving);
});
</script>
<?php
} );Code language: PHP (php)
Here’s what each part does:
woocommerce_before_add_to_cart_button: Adds the checkbox and engraving field to the product page.woocommerce_form_field(): Generates WooCommerce-style form fields for gift wrapping and engraving.woocommerce_add_cart_item_data: Saves the submitted checkbox and message into the cart item when the product is added to the cart.sanitize_text_field() + wp_unslash(): Clean the engraving message before storing it.unique_key: Stops WooCommerce merging cart items that have different custom options.woocommerce_get_item_data: Displays the gift wrapping and engraving message in the cart and checkout.woocommerce_cart_calculate_fees: Adds the +$5 gift wrapping surcharge to the cart total.$cart->add_fee(): The WooCommerce method that creates the visible fee line in cart, checkout, and order totals.$cart_item['quantity']: Makes the fee apply per item quantity, not once per cart line.woocommerce_checkout_create_order_line_item: Saves the gift wrapping and engraving data into the final order item.$item->add_meta_data(): Makes the custom fields appear in the admin order, order details, and customer emails.- The
wp_footerscript handles the conditional logic, hiding or showing the engraving field as the gift wrap checkbox is toggled.
Finally, go to Plugins in your WordPress dashboard and activate it. Test on a staging site first, since these hooks touch the cart and checkout.
Build powerful surcharge fields without slowing your store down
The code route works, but it’s now yours to maintain through every WooCommerce update. Advanced Product Fields gets you the same surcharge with far more pricing and field options, and it stays fast.
In Studio Wombat’s 2025 benchmark of 6 product add-on plugins, APF loaded the smallest frontend footprint at 10.5KB and executed fastest at 0.012 seconds, ranking first overall. That footprint is at least 3 times smaller than the competitors tested.
Start with the free version on WordPress.org for simple products with flat-fee fields. When you need quantity-based, percentage, or formula pricing, Pro starts at $69/year.