如何在Woocommerce结账页面移除配送选项并保留预设配送费?
移除结账页面配送选项并保留订单摘要配送费的方法
Shopify 场景解决方案
代码隐藏配送选项区块
针对旧版主题,可在checkout.liquid文件中添加CSS隐藏配送选项区域,同时订单摘要会自动同步购物车的配送费用:/* 隐藏结账页配送选项模块 */ .section--shipping-method { display: none !important; }若为新版主题,可通过主题编辑器的“自定义脚本”功能添加上述CSS代码。
设置单一配送方式并强制选中
在Shopify后台「设置→配送和物流」中仅保留一种配送方式,再添加JS代码默认选中该方式并隐藏选择框:document.addEventListener('DOMContentLoaded', () => { const defaultShippingRadio = document.querySelector('.shipping-method__radio'); if (defaultShippingRadio) { defaultShippingRadio.checked = true; defaultShippingRadio.closest('.shipping-methods').style.display = 'none'; } });
WooCommerce 场景解决方案
通过PHP代码禁用配送选择
在主题的functions.php文件中添加以下代码,既隐藏结账页的配送选项,又确保订单摘要保留购物车计算的配送费:// 移除结账页配送选项展示 add_action('init', 'remove_checkout_shipping_options'); function remove_checkout_shipping_options() { remove_action('woocommerce_checkout_shipping', 'woocommerce_checkout_shipping'); } // 确保订单摘要显示配送费明细 add_filter('woocommerce_cart_shipping_method_full_label', 'display_shipping_fee_in_summary', 10, 2); function display_shipping_fee_in_summary($label, $method) { return sprintf('%s: %s', $label, wc_price($method->cost)); }插件快速实现
安装「WooCommerce Force Shipping Method」插件,配置强制使用指定配送方式,即可自动隐藏结账页的配送选项,订单摘要会同步保留对应配送费用。
内容的提问来源于stack exchange,提问作者Mousebucks
相关产品推荐
相关产品推荐

