首页 文章

Woocommerce跳过结账免费产品

提问于
浏览
2

我正在WP和Woocommerce上 Build 网页 - 我想跳过购物车和结帐页面免费产品(或我可以指定ID的产品) . 这些产品是免费和虚拟的(无需付款,无需运送) . 该网页仅供注册用户使用 - 因此所有客户信息都存在 .

我希望得到的结果是,如果按产品页面上的ORDER按钮 - 订单已完成,客户将被重定向到Thank-You页面 .

BR,卡斯帕尔

2 回答

  • 2

    我应用了相同的概念,但在结账时处理订单时发现了一个主要问题;领域仍然是必需的 .

    主要问题是通过AJAX处理订单(使用 is_ajax() ),即使它在结帐页面上,也可能是最近的更改,或者它可能是网站的环境(主题) .

    以下是一些条件标记:https://docs.woocommerce.com/document/conditional-tags/

    看到事情如何变化,答案可以在这里编辑,但最初的概念位于:https://www.skyverge.com/blog/how-to-simplify-free-woocommerce-checkout/

    function wc_free_checkout_fields() {
        // Bail we're not at checkout, or if we're at checkout OR AJAX (payment process) but payment is needed.
        if ( function_exists( 'is_checkout' ) && ( ! ( is_checkout() || is_ajax() ) || ( ( is_checkout() || is_ajax() ) && WC()->cart->needs_payment() ) ) ) {
            return;
        }
    
        // Remove coupon forms since it's irrelevant with a free cart?
        remove_action( 'woocommerce_before_checkout_form', 'woocommerce_checkout_coupon_form', 10 );
    
        // Remove the "Additional Info" order notes.
        add_filter( 'woocommerce_enable_order_notes_field', '__return_false' );
    
        // Unset the fields we don't want in a free checkout.
        function wc_unset_unwanted_checkout_fields( $fields ) {
            // Add or remove billing fields you do not want.
            // @link http://docs.woothemes.com/document/tutorial-customising-checkout-fields-using-actions-and-filters/#section-2
            $billing_keys = array(
                'billing_company',
                'billing_phone',
                'billing_address_1',
                'billing_address_2',
                'billing_city',
                'billing_postcode',
                'billing_country',
                'billing_state',
            );
    
            // For each unwanted billing key, unset.
            foreach( $billing_keys as $key ) {
                unset( $fields['billing'][$key] );
            }
    
            return $fields;
        }
        add_filter( 'woocommerce_checkout_fields', 'wc_unset_unwanted_checkout_fields' );
    
        // A tiny CSS tweak for the account fields; this is optional.
        function wc_print_custom_css() {
            ?>
            <style>
                .create-account {
                    margin-top: 6em;
                }
            </style>
            <?php
        }
        add_action( 'wp_head', 'wc_print_custom_css' );
    }
    add_action( 'wp', 'wc_free_checkout_fields' );
    
  • 1

    使用WC() - > cart-> needs_payment()检查检查结账是否没有成本 . 有关详细信息,请参阅此内容:https://www.skyverge.com/blog/how-to-simplify-free-woocommerce-checkout/

相关问题