1 回答
TA贡献1824条经验 获得超6个赞
要在订单总计之前移动单选按钮,您需要使用另一个挂钩。但是你不能在费用总计行上有那个交付单选按钮......
我已经简化并重新访问了代码:
add_action( 'woocommerce_review_order_before_order_total', 'checkout_delivery_radio_buttons' );
function checkout_delivery_radio_buttons() {
echo '<tr class="delivery-radio">
<th>'.__("Delivery Options").'</th><td>';
$chosen = WC()->session->get( 'delivery' );
$chosen = empty( $chosen ) ? WC()->checkout->get_value( 'delivery' ) : $chosen;
$chosen = empty( $chosen ) ? '0' : $chosen;
woocommerce_form_field( 'delivery', array(
'type' => 'radio',
'class' => array( 'form-row-wide', 'update_totals_on_change' ),
'options' => array(
'2.95' => '60 MINUTES: €2.95',
'0' => '24 - 48 HOURS',
),
), $chosen );
echo '</td></tr>';
}
add_action( 'woocommerce_cart_calculate_fees', 'checkout_delivery_fee', 20, 1 );
function checkout_delivery_fee( $cart ) {
if ( $radio = WC()->session->get( 'delivery' ) ) {
$cart->add_fee( 'Delivery Fee', $radio );
}
}
add_action( 'woocommerce_checkout_update_order_review', 'checkout_delivery_choice_to_session' );
function checkout_delivery_choice_to_session( $posted_data ) {
parse_str( $posted_data, $output );
if ( isset( $output['delivery'] ) ){
WC()->session->set( 'delivery', $output['delivery'] );
}
}
代码进入您的活动子主题(或活动主题)的 functions.php 文件。测试和工作。
- 1 回答
- 0 关注
- 179 浏览
添加回答
举报