I have this result of $product->get_variation_prices(), see "price" and "sale_price":
array(3) {
["price"]=> array(3) {
[18042]=> string(6) "910.57"
[18044]=> string(6) "910.57"
[18043]=> string(7) "1050.00" }
["regular_price"]=> array(3) {
[18042]=> string(7) "1138.21"
[18043]=> string(7) "1138.21"
[18044]=> string(7) "1138.21" }
["sale_price"]=> array(3) {
[18042]=> string(6) "910.57"
[18044]=> string(6) "910.57"
[18043]=> string(7) "1050.00" }
}
I subtracted 100 from variation_prices
add_filter('woocommerce_variation_prices_price', 'theme_get_variation_price', 99, 3 );
function theme_get_variation_price($price, $variation, $product){
wc_delete_product_transients($variation->get_id());
if ( current_user_can('test') ){
return $price-100; //test
}
}
This is the $product->get_variation_prices() output:
array(3) {
["price"]=> array(3) {
[18042]=> string(6) "810.57"
[18044]=> string(6) "810.57"
[18043]=> string(6) "950.00" }
["regular_price"]=> array(3) {
[18042]=> string(7) "1138.21"
[18043]=> string(7) "1138.21"
[18044]=> string(7) "1138.21" }
["sale_price"]=> array(3) {
[18042]=> string(7) "1138.21"
[18043]=> string(7) "1138.21"
[18044]=> string(7) "1138.21" }
}
Why that everytime I make a change in $price, the ["sale_price"] values automatically equals to ["regular_price"]? How can I keep the "sale_price" values? Am I missing something? Edit: Just to be clear, I don't want the sale_price to subtract aswell. I want to keep the original values.