WooCommerce un-register user checkout

Posted in :

有人使用 WooCommerce v3.0.1 遇到,「開放未註冊訪客結帳」(woocommerce_enable_guest_checkout) 的 Checkout process 無效的問題嗎? 我試了「選取」和「未選取」沒註冊的會員都可以結帳.

 

先隨便找一支程式,丟出 woocommerce option:

<?php echo “woocommerce_enable_guest_checkout:”.get_option( ‘woocommerce_enable_guest_checkout’ ) ?>

測試結果是,設定值都是正確的。

 

檢查 includes/class-wc-checkout.php:

 /**
 * Is registration required to checkout?
 *
 * @since 3.0.0
 * @return boolean
 */
 public function is_registration_required() {
 return apply_filters( 'woocommerce_checkout_registration_required', 'yes' !== get_option( 'woocommerce_enable_guest_checkout' ) );
 }

原因是 templates/checkout/form-login.php:

if ( is_user_logged_in() || 'no' === get_option( 'woocommerce_enable_checkout_login_reminder' ) ) {
 return;
}

這段 code 檢查的是 woocommerce_enable_checkout_login_reminder (Display returning customer login reminder on the “Checkout” page.)而不是 woocommerce_enable_guest_checkout。

 


最後找到Bug, 在 checkout/form-checkout.php :

if ( ! $checkout->is_registration_enabled() && $checkout->is_registration_required() && ! is_user_logged_in() ) {
 echo apply_filters( 'woocommerce_checkout_must_be_logged_in_message', __( 'You must be logged in to checkout.', 'woocommerce' ) );
 return;
}

在 if 後面,多了一個 !,拿掉所有的結果都對了。

幫原作者開好bug, 並附上解法:
https://github.com/woocommerce/woocommerce/issues/14195

順便開了一個 PR(pull request):
https://github.com/woocommerce/woocommerce/pull/14197

issue 被關閉,PR也被打搶,但是我的問題也解決了,不能 commit 進去是真的,因為有side effect,這個改下去,別的情況會出包,github 上的神人真多~。

發佈留言

發佈留言必須填寫的電子郵件地址不會公開。 必填欄位標示為 *