命令get_post_meta(get_the_ID(),'add_price',true);在我的wordpress网站的此功能上不起作用:
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' );
您可以这样尝试吗?
function misha_recalculate_price( $cart_object ) {
if ( is_admin() && ! defined( 'DOING_AJAX' ) ) {
return;
foreach ( $cart_object->get_cart() as $hash => $value ) {
$nowprice = $value['data']->get_price();
$addprice = get_post_meta($value['data']->get_id(), 'add_price', true);
$newprice = $nowprice + $addprice;
$value['data']->set_price( $newprice );
}
}
}
add_action( 'woocommerce_before_calculate_totals', 'misha_recalculate_price', 10, 1 );
function misha_recalculate_price( $cart_object ) {
if ( is_admin() && ! defined( 'DOING_AJAX' ) )
return;
foreach ( $cart_object->get_cart() as $hash => $value ) {
$nowprice = $value['data']->get_price();
$addprice = get_post_meta($value['data']->get_id(), 'cost_price', true);
$newprice = $nowprice+$addprice ;
$value['data']->set_price( $newprice );
}
}
add_action( 'woocommerce_before_calculate_totals', 'misha_recalculate_price', 10, 1 );