Website Building » WooCommerce » How Do I Add Another Price Field in WooCommerce?

How Do I Add Another Price Field in WooCommerce?

Last updated on January 23, 2023 @ 11:12 am

Adding a secondary pricing field to your WooCommerce product page can showcase different pricing options for your customers. For instance, if you have a product that comes in different sizes, you can include a size-specific pricing field so customers can see the price difference. Another example would be if you offer discounts for bulk orders, you can add a field for the discounted price.

There are two methods to add a secondary pricing field to your WooCommerce product page:

Method 1: Use the WooCommerce Product Add-ons plugin.

This plugin allows you to add custom fields to your product pages and it is free to use. Once installed and activated, go to WooCommerce > Add-ons and click on the Add New button. Select Price Field in the Field Type dropdown and enter a label for the field in the Field Label box. You can also add a description for the field in the Field Description box. (Optional) You can make this field required, limit the number of characters that can be entered, and display the field on the cart and checkout pages.

Method 2: Add custom code to your child theme’s functions.php file.

This method is more advanced but provides more control over how the fields are displayed on your product pages. Go to Appearance > Editor in your WordPress dashboard, select functions.php and copy and paste the code provided. Create a new custom field for each product by going to WooCommerce > Products and selecting the product you want to add the additional price field to.

Adding an additional price field is a great way show different pricing options for customers on WooCommerce products pages.

Here is an example of the code that would be added to the child theme’s functions.php file to add a secondary pricing field to a WooCommerce product page:

function add_secondary_price_field_to_product() {
 global $product;
 $secondary_price = get_post_meta( $product->get_id(), '_secondary_price', true );
  if( ! empty( $secondary_price ) ) {
    echo '<div class="secondary-price">Additional Price: ' . wc_price( $secondary_price ) . '</div>';
  }
}
add_action( 'woocommerce_single_product_summary', 'add_secondary_price_field_to_product', 25 );

This code creates a new function called “add_secondary_price_field_to_product” that retrieves the value of the secondary price field for the current product. If the field has a value, it will display it as a separate line item on the product page. The add_action function hooks the function to the woocommerce_single_product_summary action, which is where the product summary is displayed. This code is just an example and you may need to adjust it to match your specific use case.

PRO TIP: If you are not a developer, or are not comfortable with code, we recommend not attempting to add another price field in WooCommerce. This is because it involves modifying WooCommerce code, which can be complex, and can lead to errors on your site if not done correctly.
Dale Leydon

Dale Leydon

Sysadmin turned Javascript developer. Owner of 20+ apps graveyard, and a couple of successful ones.