gpt4 book ai didi

Woocommerce 跳过免费产品结帐

转载 作者:行者123 更新时间:2023-12-04 13:41:04 33 4
gpt4 key购买 nike

我正在 WP 和 Woocommerce 上构建网页 - 我想跳过购物车和免费产品(或我可以指定 ID 的产品)的结帐页面。这些产品是免费的和虚拟的(不需要付款,不需要运输)。该网页仅供注册用户使用 - 因此会显示所有客户信息。

我想要的结果是,如果您在产品页面上按下订购按钮 - 订单已完成,客户将被重定向到感谢页面。

BR,卡斯帕

最佳答案

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

主要问题是通过 AJAX 处理订单(使用 is_ajax() ),即使它在结帐页面上,也没有返回 true。可能最近发生了变化,也可能是网站的环境(主题)。

以下是一些条件标签: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' );

关于Woocommerce 跳过免费产品结帐,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39960911/

33 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com