Skip Navigation

[Resolved] Overide woocommerce price with extra field calcutation

This thread is resolved. Here is a description of the problem and solution.

Problem:
Overide woocommerce price with extra field calcutation

Solution:
You can use standard save_post action to update the product field.

You can find the proposed solution, in this case, with the following reply:
https://toolset.com/forums/topic/overide-woocommerce-price-with-extra-field-calcutation/#post-1111319

Relevant Documentation:

This support ticket is created 6 years, 2 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Kolkata (GMT+05:30)

This topic contains 6 replies, has 2 voices.

Last updated by domenicoS 6 years, 2 months ago.

Assisted by: Minesh.

Author
Posts
#1111303

Hi Minesh ,

I write you to have help with my last develop.

I created 2 custom field (price-1 and price-2)

I need to set the price for a product using a sum (price-1 + price-2) = regular-price

There are many pluhgin usefull for this, but I want't charge to many plugin for conflict issue. So the solution is a simple function to override the woocommerce price from these field

I know maybe I should use the following hook

add_action( 'woocommerce_before_calculate_totals', 'add_custom_price' );

The question is, how can I calculate the new price from these custom field? And How can return and override the woocommerce regular price?

Thanks a lot for your help!!

Domenico

#1111311

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Hello. Thank you for contacting the Toolset support.

Well - Yes, I think you can use the said hook. Just add your releted PHP code within it to add price1 and price2.

Here are a few examples:
=> https://stackoverflow.com/questions/12327251/woocommerce-add-product-to-cart-with-price-override
=> hidden link

If you need help with that please share access details and where exactly at which place you want to update the price.

#1111319

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

I've added following code to your current theme's functions.php file:

function func_update_regular_price( $post_id, $post ){
    if ( 'product' == $post->post_type ) {
				
		$price1 = $_POST['wpcf']['prezzo-1'];
		$price2 = $_POST['wpcf']['prezzo-2'];
		$regular_price = $price1 + $price2;
		update_post_meta($post_id,'_regular_price',$regular_price);
      
    }
}
add_action( 'save_post', 'func_update_regular_price', 30, 2 );

Now, I can see the regular price is updated. Could you please confirm.

#1111324

I don't see the price. I0ve add the following shorte code in the layout to display it but nothing is displayed

[wpv-woo-product-price]
[wpv-woo-buy-options]

The price and button should be displayed under the table "Prenotazione e Partenze" in the frontend page of the product I share you in the first post

#1111345

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Well - your original issue is resolved with this ticket. Could you please resolve this and we will continue with new ticket here:
=> https://toolset.com/forums/topic/split-overide-woocommerce-price-with-extra-field-calcutation-display-regular-price/

#1111450

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Could you please close this ticket 🙂

#1111453

Thanks