wordpress - 订单页面列中的自定义结帐字段 | 电子商务
问题描述
我有一些自定义结帐字段,我想将其显示为列,我已经厌倦了它,但似乎只适用于国家、州、名字等标准结帐字段。
这是我用来创建自定义结帐字段的代码:
add_action( 'woocommerce_before_order_notes', 'bbloomer_checkout_radio_choice');
function bbloomer_checkout_radio_choice() {
$chosen = WC()->session->get('radio_chosen');
$chosen = empty( $chosen ) ? WC()->checkout->get_value('radio_choice') : $chosen;
$chosen = empty( $chosen ) ? 'no_option' : $chosen;
$args = array(
'type' => 'radio',
'class' => array( 'form-row-wide' ),
'options' => array(
'option_1' => 'Thursday all day (£12.50)',
'option_2' => 'Thursday AM (£13.50)',
'option_3' => 'Friday AM (£13.50)',
),
'default' => $chosen
);
echo '<div id="checkout-radio">';
echo '<h3>Please Select Delivery Day</h3>';
echo '<p>"Our cut off point is 10am on Monday for orders to be received the same week. If you are placing your order later than this we will schedule your delivery for the following week."</p>';
woocommerce_form_field( 'radio_choice', $args, $chosen );
echo '</div>';
}
// Part 2
// Add Fee and Calculate Total
// Based on session's "radio_chosen"
#2 Calculate New Total
add_action( 'woocommerce_cart_calculate_fees', 'bbloomer_checkout_radio_choice_fee', 20, 1 );
function bbloomer_checkout_radio_choice_fee( $cart ) {
if ( is_admin() && ! defined( 'DOING_AJAX' ) ) return;
$radio = WC()->session->get( 'radio_chosen' );
$fee = 12.5;
$deliveryDay = "Normal";
if ( "option_1" == $radio ) {
$fee = 12.5;
$deliveryDay = "Thursday all day";
} elseif ( "option_2" == $radio ) {
$fee = 13.5;
$deliveryDay = "Thursday AM";
} elseif ( "option_3" == $radio ) {
$fee = 13.5;
$deliveryDay = "Friday AM";
}
$cart->add_fee( __('Shipping ('. $deliveryDay. ')', 'woocommerce'), $fee );
}
解决方案
推荐阅读
- flutter - 无法从颤动的资产中读取sql文件
- python - 如何在snakemake包装器中访问snakefile中定义的变量?
- excel - 根据单元格值复制行并粘贴 X 次
- python - Scipy 最小化成功终止,但不满足不等式约束
- javascript - 如何获取数组中每个项目的最后一个元素子元素,然后在单击它们时显示它们
- c# - UWP 框架在 Frame.Navigate 方法中为空
- python - Kivy:如何更改“微调器”按钮的颜色和大小?
- python - 生成数字列表 T*U 并在 T 的每个分支中从索引 0 开始相互过滤
- binary - 可以加密 Wasm 可执行文件以防止逆向工程吗?
- antlr4 - 如何在不使用 @header 的情况下使用 gradle antlr 插件将包名称传递给 antlr4 语法