首页 文章

隐藏运输标签woocommerce

提问于
浏览
2

我需要在我的woocommerce购物车页面上隐藏运费 label ,但要在结帐页面上显示 .

我已经读过,我可以使用is_cart()来专门定位购物车但它没有使用我在functions.php中编写的任何代码 .

有谁知道怎么做到这一点?

-编辑-

我发现以下代码放在functions.php中:

add_filter('woocommerce_cart_shipping_method_full_label', 'remove_shipping_label', 10, 2);

function remove_shipping_label($label, $method) {
    $new_label = preg_replace('/^.+:/', '', $label);
    return $new_label;
}

现在我需要将代码与“if(is_cart())”结合起来专门定位购物车页面,但我还没弄清楚如何 .

3 回答

  • 0

    这就是我的工作,即编辑woocommerce运输细节模板 . 老问题我知道,我的回答与这个问题没有100%的关系,但是搜索并没有帮助我解决这个问题,所以我想我会帮助任何人继续寻找......

    $pos=strpos($wherefrom,"checkout");checkout 必须是结帐页面的名称(slug) . 该部分让's you choose payment methods is loaded by ajax, so all the ' is_page ', ' is_checkout ', etc, return blanks, so I resorted to useing the http_referrer. This is the result of way too many hours on one '小' problem. This code goes in the cart-shipping.php file as described in Yavour'的答案,并且必须替换现有的 <ul></ul> 之间的现有代码 .

    <ul id="shipping_method">
                <?php 
                $wherefrom=wp_get_referer();
                $pos=strpos($wherefrom,"checkout");
                if ($pos!==false)
                {
                    echo "<li>";
                    foreach ( $available_methods as $method )
                    {
                        if ($method->id==$chosen_method)
                        {
                            $mymethod=wp_kses_post(wc_cart_totals_shipping_method_label( $method ));
                        }
                    }
                    echo $mymethod; 
                    echo "</li>";
                }
                else
                {
                ?>
                    <?php foreach ( $available_methods as $method ) : ?>
                    <li>
                        <input type="radio" name="shipping_method[<?php echo $index; ?>]" data-index="<?php echo $index; ?>" id="shipping_method_<?php echo $index; ?>_<?php echo sanitize_title( $method->id ); ?>" value="<?php echo esc_attr( $method->id ); ?>" <?php checked( $method->id, $chosen_method ); ?> class="shipping_method" />
                        <label for="shipping_method_<?php echo $index; ?>_<?php echo sanitize_title( $method->id ); ?>"><?php echo wp_kses_post( wc_cart_totals_shipping_method_label( $method ) ); ?></label>
                    </li>
                    <?php endforeach; ?>
                <?php
                }
                ?>
    
            </ul>
    
  • 1
    function disable_shipping_calc_on_cart( $show_shipping ) {
        if( is_cart() ) {
            return false;
        }
        return $show_shipping;
    }
    add_filter( 'woocommerce_cart_ready_to_calc_shipping','disable_shipping_calc_on_cart', 99 );
    
  • 0

    购物车页面由插件文件夹中的模板加载:

    woocommerce/templates/cart/cart-shipping.php
    

    要覆盖此模板,您需要在主题中复制该文件:

    /your_theme_folder/woocommerce/cart/cart-shipping.php
    

    现在你可以用它做任何事情(甚至把它留空)它只会影响购物车页面 . 结帐页面使用不同的模板文件来生成送货字段 .

    资料来源:经验template overriding

相关问题