我正在建设可湿性粉剂和Woocommerce的网页-我想跳过购物车,也为免费产品(或产品ID-s我可以指定)结帐页面。这些产品是免费和虚拟的(不需要付款,不需要送货)。该网页仅供注册用户使用-因此所有客户信息都存在。
BR,Kaspar
发布于 2018-08-30 12:16:09
我应用了相同的概念,但在结帐时发现了一个主要问题;字段仍然是必需的。
主要的问题是通过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' );发布于 2016-10-10 23:01:50
使用WC()->购物车->needs_payment()检查结账是否没有成本。有关更多信息,请参阅:https://www.skyverge.com/blog/how-to-simplify-free-woocommerce-checkout/
发布于 2019-09-15 16:06:03
有无数的WooCommerce插件可以让你做到这一点。其中一个(免费的)就是这个:https://wordpress.org/plugins/download-now-for-woocommerce/
您还可以构建一个成员站点,在该站点中,您可以对单个用户或产品进行更多的控制。
https://stackoverflow.com/questions/39960911
复制相似问题