我正在寻找一种方法来先显示送货详细信息,然后将“送货到其他地址”复选框更改为“账单到其他地址”,然后是帐单详细信息。 只是更改标签是行不通的,因为这样运费仍然是根据原始发货国家/地区(然后将显示为账单国家/地区)计算的(无论我是将发货目的地设置为客户的送货地址还是客户的账单地址) woocommerce 运输选项设置)。
所以我遇到了这个答案 (https://stackoverflow.com/a/55386894) 并按照描述编辑了模板。但是,运费没有正确更新。 我设置了以下送货选项:
无论我选择哪个国家作为送货国家,它都会显示免费送货(它会刷新 ajax,但不会更改运费)。只有当我选中“Bill to different address 复选框”时,运费才会正确更新(基于运送国家,意味着应该如此)。所以我需要一种方法来独立于单击复选框来更新运费。任何帮助将不胜感激。
这是我尝试过的:
在 form-checkout.php 中,我只是简单地切换了计费和运输输出。
在 form-billing.php 我有这个:
<div class="woocommerce-billing-fields">
<h3 id="ship-to-different-address">
<label class="woocommerce-form__label woocommerce-form__label-for-checkbox checkbox">
<input id="ship-to-different-address-checkbox" class="woocommerce-form__input woocommerce-form__input-checkbox 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" /> <span><?php esc_html_e( 'Different billing address?', 'woocommerce' ); ?></span>
</label>
</h3>
<?php do_action( 'woocommerce_before_checkout_billing_form', $checkout ); ?>
<div class="shipping_address">
<?php do_action( 'woocommerce_before_checkout_shipping_form', $checkout ); ?>
<div class="woocommerce-billing-fields__field-wrapper">
<?php
$fields = $checkout->get_checkout_fields( 'billing' );
foreach ( $fields as $key => $field ) {
woocommerce_form_field( $key, $field, $checkout->get_value( $key ) );
}
?>
</div>
<?php do_action( 'woocommerce_after_checkout_shipping_form', $checkout ); ?>
</div>
<?php do_action( 'woocommerce_after_checkout_billing_form', $checkout ); ?>
</div>
<div class="woocommerce-shipping-fields">
<?php if ( true === WC()->cart->needs_shipping_address() ) : ?>
<?php if ( wc_ship_to_billing_address_only() && WC()->cart->needs_shipping() ) : ?>
<h3><?php esc_html_e( 'Shipping & Billing', 'woocommerce' ); ?></h3>
<?php else : ?>
<h3><span class="checkout-step"><?php echo '1'; ?></span><span class="checkout-title"><?php esc_html_e( 'Shipping Address', 'woocommerce' ); ?></span></h3>
<?php endif; ?>
<div class="woocommerce-shipping-fields__field-wrapper">
<?php
$fields = $checkout->get_checkout_fields( 'shipping' );
foreach ( $fields as $key => $field ) {
woocommerce_form_field( $key, $field, $checkout->get_value( $key ) );
}
?>
</div>
<?php endif; ?>
</div>