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
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.
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.
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
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/
Minesh
Supporter
Languages:
English (English )
Timezone:
Asia/Kolkata (GMT+05:30)
Could you please close this ticket 🙂