我终于找到了解决方案。
我已设置为送货方式(商店取货和本地送货)。并隐藏未经检查的运输方式。一旦客户更改了选项(单击自定义单选按钮),即取货单选按钮和运输单选按钮。在 Pickup 单选按钮上选中我将商店取货运输方法设置为检查并触发运行 ajax 的 jquery 函数并更新购物车总数和运费。另一方面,我隐藏了本地交付运输方式单选按钮。反之亦然。
样式.css
.woocommerce ul#shipping_method li input {
position: absolute; left: -25px;
}
.woocommerce ul#shipping_method li {
margin: 0; overflow: hidden; padding: 0; position: relative;
text-indent: 0; display: none;
}
.woocommerce.pickup ul#shipping_method li:first-child {
display: block;
}
.woocommerce.ship ul#shipping_method li:last-child {
display: block;
}
jQuery
$('[name="order_type"]').on("change",function(){
/* Pickup Radio Button / Shipping Radio Button ?*/
showHideOrderTypeOptions();
});
function showHideOrderTypeOptions()
{
var order_type = $('[name="order_type"]:checked').val();
if(order_type == "Ship")
{
$(".shipping_address, #ship-to-different-address").show();
$(".store-locations-wrapper").hide();
$("#store_address_id").val("");
$("#ship-to-different-address-checkbox").attr("checked",true);
$('[name="store_address"]').attr("checked",false);
$(".woocommerce").removeClass('pickup').addClass("ship");
$("#shipping_method li").eq(1).find("input").trigger("click");
}
else
{
$(".shipping_address, #ship-to-different-address").hide();
$(".store-locations-wrapper").show();
$("#ship-to-different-address-checkbox").attr("checked",false);
$(".woocommerce").removeClass('ship').addClass("pickup");
$("#shipping_method li").eq(0).find("input").trigger("click");
}
}
woocommerce >> form-billing.php
<div class="order-type-wrapper">
<h3>Order Type - </h3>
<input id="order-type-pickup" class="input-radio" <?php checked( $order_type, 'Pickup' ); ?> type="radio" name="order_type" value="Pickup" />
<label for="order-type-pickup" class="radio"><?php _e( 'Pick up?', 'woocommerce' ); ?></label>
<input id="order-type-ship" class="input-radio" <?php checked( $order_type, 'Ship' ); ?> type="radio" name="order_type" value="Ship" />
<label for="order-type-ship" class="radio"><?php _e( 'Ship?', 'woocommerce' ); ?></label>
</div>
<div class="store-locations-wrapper">
<input type="hidden" id="store_address_id" name="store_address_id" value="<?php echo $store_address_id; ?>" />
<h3>Pickup Location</h3>
Store locations goes here.
</div>