dongxiegao3071 2016-09-26 19:12
浏览 41
已采纳

在结帐页面上默认显示送货字段

On my WooCommerce checkout page, I am selling only one product. The checkout page is showing this product and there is ckeckbox next to it, to show the shipping details, when clicked. This is on the default form-checkout.php WooCommerce template.

I would like to have this ckeckbox always selected, to show billing details by default.

I have tried to set:

$checkout = 1;

With no luck so far. The radio button is displayed by the following hook:

<?php do_action( 'woocommerce_checkout_before_customer_details'); ?>

Any help letting me know how I can achieve this will be very helpful.

Thanks.

  • 写回答

1条回答 默认 最新

  • donglang1894 2016-09-27 02:33
    关注

    If you look to the code of checkout/form-shipping.php WooCommerce template, inside the <h3> tag, where the checkbox code is located, there is woocommerce_ship_to_different_address_checked hook that you can use to achieve that. Here is an extract of this code template, that shows it:

    ?>
    <div class="woocommerce-shipping-fields">
        <?php if ( true === WC()->cart->needs_shipping_address() ) : ?>
    
            <h3 id="ship-to-different-address">
                <label for="ship-to-different-address-checkbox" class="checkbox"><?php _e( 'Ship to a different address?', 'woocommerce' ); ?></label>
                <input id="ship-to-different-address-checkbox" class="input-checkbox" <?php checked( apply_filters( 'woocommerce_ship_to_different_address_checked', 'shipping' === get_option( 'woocommerce_ship_to_destination' ) ? 1 : 0 ), 1 ); ?> type="checkbox" name="ship_to_different_address" value="1" />
            </h3>
    
            <div class="shipping_address">
    

    So you can use this hook this way, to get this checkbox always selected and displays billing details:

    add_filter( 'woocommerce_ship_to_different_address_checked', '__return_true');
    

    This code goes in function.php file of your active child theme (or theme) or also in any plugin file.

    The code is tested and fully functional.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 iOS绕地区网络检测
  • ¥15 python验证码滑块图像识别
  • ¥15 根据背景及设计要求撰写设计报告
  • ¥15 QT6颜色选择对话框显示不完整
  • ¥20 能提供一下思路或者代码吗
  • ¥15 用twincat控制!
  • ¥15 请问一下这个运行结果是怎么来的
  • ¥15 单通道放大电路的工作原理
  • ¥30 YOLO检测微调结果p为1
  • ¥15 DS18B20内部ADC模数转换器