WooCommerce:访客结帐不起作用

标签 woocommerce

我一直在尝试弄清楚如何使我的支持访客结帐的网站正常运行,但到目前为止尚未成功。我激活了以下 WooCommerce 设置:

  • 启用访客结帐
  • 允许在“结帐”页面上注册

通常情况下,用户应该能够在不创建帐户的情况下结账,但如果愿意,也可以选择创建帐户。但是,如果我以访客身份下测试订单并选中“创建帐户?”框+填写用户名和密码字段,为计费和运输提供的任何信息都不会显示在“谢谢”页面或 WP 仪表板上。就像“创建帐户?”一样。框+用户名和密码将被忽略。

我怀疑这与我更改了帐户注册字段的默认位置有关。我已将它们添加到 form-login.php 文件中,以便它显示在与登录表单相同的部分中。它们最初包含在 form-b​​illing.php 字段中。请在下面找到这些文件:

表单计费.php

<?php
/**
 * Checkout billing information form
 *
 * This template can be overridden by copying it to yourtheme/woocommerce/checkout/form-billing.php.
 *
 * HOWEVER, on occasion WooCommerce will need to update template files and you
 * (the theme developer) will need to copy the new files to your theme to
 * maintain compatibility. We try to do this as little as possible, but it does
 * happen. When this occurs the version of the template file will be bumped and
 * the readme will list any important changes.
 *
 * @see     https://docs.woocommerce.com/document/template-structure/
 * @author  WooThemes
 * @package WooCommerce/Templates
 * @version 2.1.2
 */

if (!defined('ABSPATH')) {
    exit; // Exit if accessed directly
}

/** @global WC_Checkout $checkout */

?>
<div id="woocommerce-billing-fields" class="woocommerce-billing-fields">
<h3 class="billing-fields-title">Billing Address</h3>
    <?php
do_action('woocommerce_before_checkout_billing_form', $checkout);
?>

    <?php
foreach ($checkout->checkout_fields['billing'] as $key => $field):
?>

        <?php
    woocommerce_form_field($key, $field, $checkout->get_value($key));
?>

    <?php
endforeach;
?>



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




</div>

表单登录.php:

<?php wc_print_notices(); ?>
<?php echo '<div class="panel-group" id="checkout-accordion">'; ?>
<?php
/**
 * Checkout login form
 *
 * This template can be overridden by copying it to yourtheme/woocommerce/checkout/form-login.php.
 *
 * HOWEVER, on occasion WooCommerce will need to update template files and you
 * (the theme developer) will need to copy the new files to your theme to
 * maintain compatibility. We try to do this as little as possible, but it does
 * happen. When this occurs the version of the template file will be bumped and
 * the readme will list any important changes.
 *
 * @see         https://docs.woocommerce.com/document/template-structure/
 * @author         WooThemes
 * @package     WooCommerce/Templates
 * @version     2.0.0
 */

if (!defined('ABSPATH')) {
    exit; // Exit if accessed directly
}

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

echo '<div class="panel panel-default checkout-panel" id="panel-login">
    <div class="panel-heading checkout-heading" id="panel-login-heading" data-toggle="collapse" data-parent="#checkout-accordion" href="#collapse-login">
      <h4 class="panel-title checkout-acc-title"> <a class="accordion-checkout">Login/Register <i id="checkout-accordion-login" class="checkout-accordion-icon">&#xe04b;</i></a> </h4>
    </div>
    <div id="collapse-login" class="panel-collapse details collapse in">
      <div class="panel-body checkout-inside"><div class="checkout-left-login"><h3 class="login-option">Login</h3>';
$info_message = apply_filters('woocommerce_checkout_login_message', '<div class="already-registered">' . __('Already registered?', 'woocommerce') . '</div>');
wc_print_notice($info_message, 'notice');

?>



<?php

woocommerce_login_form(
    array(
        'redirect' => wc_get_page_permalink( 'checkout' ),
        'hidden'   => true,
    )
);
echo '</div>';

?>


<?php
if (!is_user_logged_in() && $checkout->enable_signup):
?>

        <?php
    if ($checkout->enable_guest_checkout):
?>

            <p class="form-row form-row-wide create-account">
                <input class="input-checkbox" id="createaccount" <?php
        checked((true === $checkout->get_value('createaccount') || (true === apply_filters('woocommerce_create_account_default_checked', false))), true);
?> type="checkbox" name="createaccount" value="1" /> <label for="createaccount" class="checkbox"><?php
        _e('Create an account?', 'woocommerce');
?></label>
            </p>

        <?php
    endif;
?>

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

        <?php
    if (!empty($checkout->checkout_fields['account'])):
?>

<div class="checkout-right-register">
<h3 class="login-option">Create an Account</h3>
            <div class="create-account">




                <?php
        foreach ($checkout->checkout_fields['account'] as $key => $field):
?>

                    <?php
            woocommerce_form_field($key, $field, $checkout->get_value($key));
?>

                <?php
        endforeach;
?>

                <div class="clear"></div>

            </div>



<?php
    endif;
?>

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

    <?php
endif;
?>




<button id="toggle-login" type="button" class="register-btn-checkout" data-toggle="collapse" onclick="setCookie('panel-billing')" data-parent="#checkout-accordion" href="#collapse-billing">Continue</button>


</div><div class="or-select-guest">OR</div><button id="toggle-login2" type="button" class="guest-btn-checkout" data-toggle="collapse" data-parent="#checkout-accordion" href="#collapse-billing" onclick="setCookie('panel-billing')">Checkout as Guest</button> 

<?php echo'</div></div></div>';

?>

附注:整个结帐表单将是一个 Accordion ,其中包含交付+计费、交付选项和付款部分。

我错过了什么吗?我怀疑该问题可能与 Woocommerce 操作有关,但我无法确定。

最佳答案

您是否使用过 Woocommerce 订阅?我问这个问题是因为我刚刚遇到了类似的问题,并最终意识到访客结帐实际上适用于除订阅产品之外的任何产品。我碰巧正在使用购物车中的订阅产品来测试结账页面...由于购买订阅产品会分配用户角色,因此购物车中的产品在结账时需要一个帐户。

这可能对您的具体情况没有帮助,但也许会帮助其他人寻找答案。

关于WooCommerce:访客结帐不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41783675/

相关文章:

php - 更新购物车后自动从购物车重定向到结账

jquery - 如何防止 Woocommerce 在结账页面选择默认付款方式?

php - 获取与 Woocommerce 中的产品类别相关的所有属性及其术语

php - 在 Woocommerce 中显示总购物车运输量值

php - 在 WooCommerce 中向非成员(member)显示成员(member)折扣价

woocommerce - 禁用访客结帐

javascript - 如果我在输入类型文本中写东西,请选中复选框

php - 如何添加将 WC_Product_Variable 扩展到购物车的自定义 WooCommerce 产品类型

php - 将优惠券字段移至购物车总计

php - 使用 Hook 替换 Woocommerce 商店页面上的图像