I would like to update the price of products adding a custom price in cart using this simple piece of code update_post_meta( $product->id, '_regular_price', $frame_price_added);
.
Note: what I'm trying to achieve is to add this custom price to each product in cart.
I have try to get $frame_price_added
this way:
$frame_price = $res['_number_field'][0];
$frame_price_added = $product->price + $frame_price;
Here $product->price
is price coming from woocomerce product and $frame_price
is coming from my newly added price.
I was wondering how do I associate this new price to cart, because it doesn't work.
I have tried using update_post_meta( $product->id, '_price', $frame_price_added);
and when page is refreshed it adds and stores the custom price to the product, and saved it.
Any idea on how I can achieve this properly?
Thanks.
Edit: One more thing… I have searched a function that can being called on add to cart and i didn't find any thing, and also an action hook being called on
woocommerce_template_single_add_to_cart
which hadwoocommerce_single_product_summary
but it didn't find any function.
_regular_price
to thesale_price
and the sale price's sale dates to determine the_price
key. The_price
is then the price that users will pay. Best that I can tell, it sounds like you may want to consider Product Addons. – Smarm