I have a free product in Woocommerce, and used this tutorial from Skyverge to simplify the checkout process: https://www.skyverge.com/blog/how-to-simplify-free-woocommerce-checkout/
The problem is, for all other products we have 3 required fields in the Additional Information tab:
cracha_empresa cracha_primeironome cracha_sobrenome
And we removed "order_notes" all together. To achieve this, we are using the Woocommerce Checkout Field Editor.
When we try to go through the checkout process for this free product, the filter add_filter( 'woocommerce_enable_order_notes_field', '__return_false' ); is removing the additional fields (as expected), but when you try to complete the purchase, I get an error saying that the above fields are REQUIERED to fill out, even though they aren't showing.
From what I guess, I need to filter these fields in an array?
/** * Remove os cupons, notas, e campos que não são necessários para palestrantes. * */ function 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' );
I tried this with no luck:
/** * Remove os cupons, notas, e campos que não são necessários para palestrantes. * */ function 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' );