用自定义文本信息替换WooCommerce购物车中的运费部分。

问题描述 投票:0回答:1

我已经在结账页面清除了计费字段,但不幸的是,这些字段在购物车页面仍然被记住。

add_filter( 'woocommerce_checkout_get_value', 'reigel_empty_checkout_billing_fields', 10, 2 );

function reigel_empty_checkout_billing_fields( $value, $input ) {

    if ( in_array( $input, $billing_fields ) ) {
        $value = '';
    }

    return $value;
}

我只是想在购物车页面上显示一个信息,即在填写运费字段后,下一步将显示运费。谁能帮帮我?

php wordpress woocommerce cart hook-woocommerce
1个回答
2
投票

下面的代码将删除购物车中的运费部分,用一个自定义的信息代替。

// Remove "shipping" section from cart page only
add_filter( 'woocommerce_cart_needs_shipping', 'filter_cart_needs_shipping' );
function filter_cart_needs_shipping( $needs_shipping ) {
    return is_cart() ? false : $needs_shipping;
}

// Add a custom shipping message row
add_action( 'woocommerce_cart_totals_before_order_total', 'cart_custom_shipping_message_row' );
function cart_custom_shipping_message_row() {
    if ( ! WC()->cart->needs_shipping() ) :

    $shipping_message = __("Costs will be calculated on next step.", "woocommerce");
    ?>
    <tr class="shipping">
        <th><?php _e( 'Shipping', 'woocommerce' ); ?></th>
        <td class="message" data-title="<?php esc_attr_e( 'Shipping', 'woocommerce' ); ?>"><em><?php echo $shipping_message; ?></em></td>
    </tr>
    <?php endif;
}

代码在您的子主题(或活动主题)的function.php文件中。经过测试和工作。

enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.