我在Woocommerce中有一个免费产品,并且使用了Skyverge的本教程来简化结帐过程:https://www.skyverge.com/blog/how-to-simplify-free-woocommerce-checkout/
问题是,对于所有其他产品,我们在“附加信息”标签中有3个必填字段:
cracha_empresa cracha_primeironome cracha_sobrenome
然后我们一起删除了“ order_notes”。为此,我们使用了Woocommerce Checkout字段编辑器。
当我们尝试通过免费产品进行结帐时,过滤器add_filter('woocommerce_enable_order_notes_field','__return_false');正在删除其他字段(按预期方式),但是当您尝试完成购买时,我收到一条错误消息,要求填写以上字段,即使这些字段没有显示。
根据我的猜测,我需要将这些字段过滤为数组?
/ ** *删除铜杯,注意,不要再用任何古怪的东西。 * * / 函数sv_free_checkout_fields(){
// Se carrinho precisa de pagamento, não fazer nada
if ( WC()->cart && WC()->cart->needs_payment() ) {
return;
}
// Continuar somente se estamos no checkout
// is_checkout() foi quebrado em WooCommerce 3.2 no ajax, checkar se is_ajax está ativo
if ( function_exists( 'is_checkout' ) && ( is_checkout() || is_ajax() ) ) {
// Remove cupons para produtos gratuitos
remove_action( 'woocommerce_before_checkout_form', 'woocommerce_checkout_coupon_form', 10 );
// Remove o campo "Additional Info" nas notas dos pedidos
add_filter( 'woocommerce_enable_order_notes_field', '__return_false' );
// Desativa os campos para produtos gratuitos
function unset_unwanted_checkout_fields( $fields ) {
// Adiciona aqui o que deseja remover
// campos: http://docs.woothemes.com/document/tutorial-customising-checkout-fields-using-actions-and-filters/#section-2
$billing_keys = array(
'billing_persontype',
'billing_cpf',
'billing_rg',
'billing_cnpj',
'billing_company',
'billing_phone',
'billing_cellphone',
'billing_address_1',
'billing_address_2',
'billing_neighborhood',
'billing_city',
'billing_postcode',
'billing_country',
'billing_state',
'billing_number',
);
// unset each of those unwanted fields
foreach( $billing_keys as $key ) {
unset( $fields['billing'][ $key ] );
}
return $fields;
}
add_filter( 'woocommerce_checkout_fields', 'unset_unwanted_checkout_fields' );
}
} add_action('wp','sv_free_checkout_fields');
我没有运气尝试过这个
/ ** *删除铜杯,注意,不要再用任何古怪的东西。 * * / 函数sv_free_checkout_fields(){
// Se carrinho precisa de pagamento, não fazer nada
if ( WC()->cart && WC()->cart->needs_payment() ) {
return;
}
// Continuar somente se estamos no checkout
// is_checkout() foi quebrado em WooCommerce 3.2 no ajax, checkar se is_ajax está ativo
if ( function_exists( 'is_checkout' ) && ( is_checkout() || is_ajax() ) ) {
// Remove cupons para produtos gratuitos
remove_action( 'woocommerce_before_checkout_form', 'woocommerce_checkout_coupon_form', 10 );
// Remove o campo "Additional Info" nas notas dos pedidos
add_filter( 'woocommerce_enable_order_notes_field', '__return_false' );
// Desativa os campos para produtos gratuitos
function unset_unwanted_checkout_fields( $fields ) {
// Adiciona aqui o que deseja remover
// campos: http://docs.woothemes.com/document/tutorial-customising-checkout-fields-using-actions-and-filters/#section-2
$billing_keys = array(
'billing_persontype',
'billing_cpf',
'billing_rg',
'billing_cnpj',
'billing_company',
'billing_phone',
'billing_cellphone',
'billing_address_1',
'billing_address_2',
'billing_neighborhood',
'billing_city',
'billing_postcode',
'billing_country',
'billing_state',
'billing_number',
);
$order_keys = array(
'cracha_empresa',
'cracha_primeironome',
'cracha_sobrenome',
);
// unset each of those unwanted fields
foreach( $billing_keys as $key ) {
unset( $fields['billing'][ $key ] );
}
// unset each of those unwanted fields
foreach( $order_keys as $key ) {
unset( $fields['order'][ $key ] );
}
return $fields;
}
add_filter( 'woocommerce_checkout_fields', 'unset_unwanted_checkout_fields' );
}
} add_action('wp','sv_free_checkout_fields');
答案 0 :(得分:0)
只需禁用Woocommerce Checkout字段编辑器并尝试一下。
您可以在WooCommerce结帐页面中通过添加到主题函数.php文件中的2个过滤器删除“附加信息和订单注释”字段
// Removes Order Notes Title - Additional Information & Notes Field
add_filter( 'woocommerce_enable_order_notes_field', '__return_false', 9999 );
// Remove Order Notes Field
add_filter( 'woocommerce_checkout_fields' , 'remove_order_notes' );
enter code here
function remove_order_notes( $fields ) {
unset($fields['order']['order_comments']);
return $fields;
}
第一个过滤器woocommerce_enable_order_notes_field返回false,并且不会显示“其他信息”标题以及订单注释字段, 我发现有时需要以较高的优先级运行它,这就是为什么我在“ 9999”中添加了它。
第二个过滤器woocommerce_checkout_fields正在删除订单注释字段。