Skip Navigation

[Resuelto] Overide woocommerce price with extra field calcutation

Este hilo está resuelto. Aquí tiene una descripción del problema y la solución.

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 hace 6 años, 2 meses. 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.

Hoy no hay técnicos de soporte disponibles en el foro Juego de herramientas. Siéntase libre de enviar sus tiques y les daremos trámite tan pronto como estemos disponibles en línea. Gracias por su comprensión.

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)

Este tema contiene 6 respuestas, tiene 2 mensajes.

Última actualización por domenicoS hace 6 años, 2 meses.

Asistido por: Minesh.

Autor
Mensajes
#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

Idiomas: Inglés (English )

Zona horaria: 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
=> enlace oculto

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

Idiomas: Inglés (English )

Zona horaria: 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

Los hilos nuevos creados por Minesh y vinculados a este se encuentran a continuación:

https://toolset.com/es/forums/topic/split-overide-woocommerce-price-with-extra-field-calcutation-display-regular-price/

#1111345

Minesh
Supporter

Idiomas: Inglés (English )

Zona horaria: 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

Idiomas: Inglés (English )

Zona horaria: Asia/Kolkata (GMT+05:30)

Could you please close this ticket 🙂

#1111453

Thanks