如果我在WooCommerce购物车页面中 Select 本地提货,右侧的运输成本会让我的客户感到困惑.你知道如果勾选了本地提货,如何只隐藏金额吗?

enter image description here

以下是发货复选框的当前HTML:

    <tr class="woocommerce-shipping-totals shipping">
    <th>Shipping</th>
        <td data-title="Shipping" colspan="2">
        <p class="nm-shipping-th-title">Shipping</p>
            <ul id="shipping_method" class="woocommerce-shipping-methods">
                <li>
                <input type="radio" name="shipping_method[0]" data-index="0" id="shipping_method_0_flat_rate1" value="flat_rate:1" class="shipping_method"><label for="shipping_method_0_flat_rate1">Shipping<span class="woocommerce-Price-amount amount"><bdi>15&nbsp;<span class="woocommerce-Price-currencySymbol">TL</span></bdi></span></label>   
                </li>
                <li>
                <input type="radio" name="shipping_method[0]" data-index="0" id="shipping_method_0_local_pickup8" value="local_pickup:8" class="shipping_method" checked="checked"><label for="shipping_method_0_local_pickup8">PickUp<span class="woocommerce-Price-amount amount"><bdi>1&nbsp;<span class="woocommerce-Price-currencySymbol">TL</span></bdi></span></label>
                </li>
            </ul>
        </td>
    </tr>

推荐答案

当选定的发货方法为Local Pickup时,您可以使用以下筛选器挂钩,从其他发货方法中 Select to remove displayed costs:

add_filter( 'woocommerce_cart_shipping_method_full_label', 'custom_cart_shipping_method_full_label', 10, 2 );
function custom_cart_shipping_method_full_label($label, $method){
    $chosen_methods = WC()->session->get('chosen_shipping_methods');
    $chosen_method = explode(':', reset($chosen_methods) );
    $chosen_method = reset($chosen_method); // Get the chosen shipping method

    if ( $method->get_method_id() !== 'local_pickup' && $chosen_method === 'local_pickup' && $method->cost > 0 ) {
        $label = $method->get_label();
    }
    return $label;
}

代码位于您的子主题的unctions.php文件中(或在插件中).经过测试,效果良好.


要删除显示的所有运输成本,即使是本地收件,当 Select 本地收件时,请改用以下选项:

add_filter( 'woocommerce_cart_shipping_method_full_label', 'custom_cart_shipping_method_full_label', 10, 2 );
function custom_cart_shipping_method_full_label($label, $method){
    $chosen_methods = WC()->session->get('chosen_shipping_methods');
    $chosen_method = explode(':', reset($chosen_methods) );
    $chosen_method = reset($chosen_method); // Get the chosen shipping method

    if ( $chosen_method === 'local_pickup' && $method->cost > 0 ) {
        $label = $method->get_label();
    }
    return $label;
}

Php相关问答推荐

composer如何解析包名?

Laravel区分大小写搜索

为WooCommerce中存储一些数据的购物车项目添加复选框

防止 WooCommerce 在前端加载全尺寸图像

Shopware 6 插件:如何删除布尔配置并将其迁移到多选配置

在 WooCommerce 更新结帐事件上动态更新自定义内容

如何使用 PHP 创建简化的 twig 替换?

为什么从一个页面到另一个页面都找不到 JQuery,因为它们使用相同的 twig 模板?

在特征中使用类的属性

PHP 创建 CSV 文件并用波斯语写入

在WooCommerce单产品页面中显示特价产品的节省金额

Woocommerce API 的 PHP Curl 附加参数

如何在 laravel 中的同一个 slug 上显示不同的内容?

Laravel auth()->id() 在生产服务器中不工作

php/html OnSubmit 禁用输入类型提交未给出预期结果

在 PHP 中验证签名

在 Laravel、Vuejs 和 Inertia 中配置 TypeScript 的问题

NetBeans 不显示中文内容

hasOne/belongsToMany 或多对多

使用 --exclude-dir 选项从 PHP 执行 grep 时出现问题