So i have an array of products with there respectable sale price.
Normally getting value from an array is simple as below:
$the_sups = array(
21179 => 14.99, //shine
21169 => 17.95, //boost
1665 => 19.15, //flexx
1663 => 17.85, //revive
1661 => 19.75, //muscle
1657 => 17.85 //maximus
);
echo $the_sups[21179];
Which will return 14.99
And for the life of me i keep get a getting return of NULL when passing though the woocommerce_before_calculate_totals
Below is code im using which i know should work if the price is returned from the array:
$sup_discount= 0.9;
$the_sups = array(
21179 => 14.99, //shine
21169 => 17.95, //boost
1665 => 19.15, //flexx
1663 => 17.85, //revive
1661 => 19.75, //muscle
1657 => 17.85 //maximus
);
foreach (WC()->cart->get_cart() as $hash => $value ) {
if( in_array( 52, $value['data']->get_category_ids() ) ) {
echo $value['product_id']; //IS 21179
$product_value = $the_sups[$value['product_id']];
var_dump($product_value); //IS ALWAYS NULL
$value['data']->set_price($product_value * $sup_discount);
}
}
Could someone explain what i am doing wrong?