如何从WooCommerce中的结帐页面中删除帐单邮寄地址

时间:2017-12-08 04:06:16

标签: php html css wordpress woocommerce

我正在尝试重新组织结帐页面上的元素。 我想删除帐单邮寄地址,并在第一栏中仅显示送货地址。在第二栏中有"您的订单"和付款方式。

我将其更改为选中了复选框(用于送货地址)。 (form-shipping.php

<h3 id="ship-to-different-address">
    <span><?php _e('Delivery address', 'woocommerce'); ?></span>
    <input id="ship-to-different-address-checkbox" class="woocommerce-form__input woocommerce-form__input-checkbox input-checkbox" checked type="checkbox" name="ship_to_different_address" value="1" style="display:none;"/> 
</h3>

此外,我还将此代码添加到functions.php以禁用帐单字段验证。

function custom_override_checkout_fields($fields)
{
    unset($fields['billing']['billing_first_name']);
    unset($fields['billing']['billing_last_name']);
    unset($fields['billing']['billing_company']);
    unset($fields['billing']['billing_address_1']);
    unset($fields['billing']['billing_address_2']);
    unset($fields['billing']['billing_city']);
    unset($fields['billing']['billing_postcode']);
    unset($fields['billing']['billing_country']);
    unset($fields['billing']['billing_state']);
    unset($fields['billing']['billing_phone']);
    unset($fields['billing']['billing_address_2']);
    unset($fields['billing']['billing_postcode']);
    unset($fields['billing']['billing_company']);
    unset($fields['billing']['billing_last_name']);
    unset($fields['billing']['billing_email']);
    unset($fields['billing']['billing_city']);
    return $fields;
}

最后这是form-checkout.php

<form name="checkout" method="post" class="checkout woocommerce-checkout" action="<?php echo esc_url(wc_get_checkout_url()); ?>" enctype="multipart/form-data">
    <?php if ($checkout->get_checkout_fields()) : ?>
        <div class="col2-set" id="customer_details">
            <div class="col-1">
                <?php do_action('woocommerce_checkout_before_customer_details'); ?>

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

                <?php do_action('woocommerce_checkout_after_customer_details'); ?>
            </div>

            <div class="col-2">
                <h3 id="order_review_heading"><?php _e('Your order', 'woocommerce'); ?></h3>
                <?php do_action('woocommerce_checkout_before_order_review'); ?>
                <div id="order_review" class="woocommerce-checkout-review-order">
                    <?php do_action('woocommerce_checkout_order_review'); ?>
                </div>
                <?php do_action('woocommerce_checkout_after_order_review'); ?>
            </div>
        </div>
    <?php endif; ?>
</form>

<?php do_action('woocommerce_after_checkout_form', $checkout); ?>

所以结账页面看起来很棒!确切地说我想要它,但是验证送货地址字段存在问题。它即使出现错误的电子邮件,交货日期或电话号码也会加载付款方式(如果字段为空则会捕获并显示提示)。

有人可以帮我解决这个问题吗?或者解释实现目标的正确方法是什么?因为我非常确定从WP和编程的角度来看,我的方式并不是很好。谢谢!

0 个答案:

没有答案
相关问题