Woocommerce产品详情页面: -
答案 0 :(得分:0)
add_action( 'woocommerce_before_calculate_totals', 'add_custom_price' );
function add_custom_price( $cart_object ) {
$custom_price = 10; // This will be your custome price
foreach ( $cart_object->cart_contents as $key => $value ) {
$value['data']->price = $custom_price;
}
}
试试此代码段
答案 1 :(得分:0)
function calculate_extra10( $cart_object ) {
global $isProcessed;
if( !WC()->session->__isset( "reload_checkout" )) {
foreach ( $cart_object->cart_contents as $key => $value ) {
$price = $cart_object->cart_contents[$key]['data']->price;
$additionCost = $price * 10 / 100;
$cart_object->cart_contents[$key]['data']->set_price($price + `$additionCost);`
}
$isProcessed = true;
}
}
add_action( 'woocommerce_before_calculate_totals', 'calculate_extra10', 99 );
答案 2 :(得分:0)
function calculate_eyehole_fee( $cart_object ) {
global $isProcessed;
if( !WC()->session->__isset( "reload_checkout" )) {
foreach ( $cart_object->cart_contents as $key => $value ) {
$price = $cart_object->cart_contents[$key]['data']->price;
$additionCost = $price * 10 / 100;
$cart_object->cart_contents[$key]['data']->set_price($price + $additionCost);
}
$isProcessed = true;
}
}
add_action( 'woocommerce_before_calculate_totals', 'calculate_eyehole_fee', 99 );