The commands get_post_meta(get_the_ID(), ‘add_price’, true); are not working at this function of my wordpress site:
function misha_recalculate_price( $cart_object ) {
var_dump(get_post_type($post_ID));
if ( is_admin() && ! defined( 'DOING_AJAX' ) )
return;
foreach ( $cart_object->get_cart() as $hash => $value ) {
$nowprice = $value['data']->get_price();
$addprice = get_post_meta(get_the_ID(), 'add_price', true);
$newprice = $nowprice+$addprice ;
$value['data']->set_price( $newprice );
}
}
add_action( 'woocommerce_before_calculate_totals', 'misha_recalculate_price' );
2
Answers
can you give it a try this way?