I am using WooCommerce 3.0+ and I have set the product price on a certain page.
$regular_price = get_post_meta( $_product->id, '_regular_price', true);
$buyback_percentage = get_post_meta( $_product->id, '_goldpricelive_buy_back', true);
$fixed_amount = get_post_meta( $_product->id, '_goldpricelive_fixed_amount', true);
$markedup_price = get_post_meta( $_product->id, '_goldpricelive_markup', true);
$buyback_price = ($regular_price - $fixed_amount)/(1 + $markedup_price/100) * (1-$buyback_percentage/100);
$_product->set_price($buyback_price);
The price is updating on my cart but when I click on to submit my order, Order object doesn't seem to get the price I set. It takes the origin product price.
Any idea on how I can accomplish this?
Thanks
Updated with
get_price()
method …You should use
woocommerce_before_calculate_totals
action hook setting inside this custom hooked function, your products IDs or an array of product IDs.Then for each of them you can make a custom calculation to set a custom price that will be set on Cart, checkout and after submitting in the order.
Here is that functional code tested on WooCommerce version 3.0+:
Code goes in function.php file of your active child theme (or theme) or also in any plugin file.