Reputation: 1087
Hi, I would like it to be like in the image and if the phone number don't match then it would not validate
really need help, thanks
Upvotes: 0
Views: 2002
Reputation: 1087
This is my answer to adding custom field in the billing section
add_filter( 'woocommerce_checkout_fields' , 'bbloomer_add_field_and_reorder_fields' );
function bbloomer_add_field_and_reorder_fields( $fields ) {
if (!$_POST['shipping_method_tax_exempt']) {
unset($fields['extra_fields']['claimant_name']);
unset($fields['extra_fields']['description_illness']);
unset($fields['extra_fields']['vat_confirm']);
}
// Add New Fields
$fields['billing']['billing_phone_confirm'] = array(
'label' => __('Phone confirm', 'woocommerce'),
'required' => true,
'class' => array('form-row-last'),
'clear' => false
);
/*$fields['shipping']['shipping_houseno'] = array(
'label' => __('House Number', 'woocommerce'),
'placeholder' => _x('House Number', 'placeholder', 'woocommerce'),
'required' => true,
'class' => array('form-row-last'),
'clear' => false
);*/
// Remove Address_2 Fields
unset($fields['billing']['billing_address_2']);
//unset($fields['shipping']['shipping_address_2']);
// Make Address_1 Fields Half Width
//$fields['billing']['billing_address_1']['class'] = array('form-row-first');
//$fields['shipping']['shipping_address_1']['class'] = array('form-row-first');
$fields['billing']['billing_country_field']['class'] = array('form-row-first');
// Billing: Sort Fields
$newfields['billing']['billing_first_name'] = $fields['billing']['billing_first_name'];
$newfields['billing']['billing_last_name'] = $fields['billing']['billing_last_name'];
$newfields['billing']['billing_company'] = $fields['billing']['billing_company'];
$newfields['billing']['billing_email'] = $fields['billing']['billing_email'];
$newfields['billing']['billing_phone'] = $fields['billing']['billing_phone'];
$newfields['billing']['billing_phone_confirm'] = $fields['billing']['billing_phone_confirm'];
$newfields['billing']['billing_country'] = $fields['billing']['billing_country'];
$newfields['billing']['billing_address_1'] = $fields['billing']['billing_address_1'];
//$newfields['billing']['billing_address_2'] = $fields['billing']['billing_address_2'];
$newfields['billing']['billing_city'] = $fields['billing']['billing_city'];
$newfields['billing']['billing_postcode'] = $fields['billing']['billing_postcode'];
$newfields['billing']['billing_state'] = $fields['billing']['billing_state'];
// Shipping: Sort Fields
$newfields['shipping']['shipping_first_name'] = $fields['shipping']['shipping_first_name'];
$newfields['shipping']['shipping_last_name'] = $fields['shipping']['shipping_last_name'];
$newfields['shipping']['shipping_company'] = $fields['shipping']['shipping_company'];
$newfields['shipping']['shipping_country'] = $fields['shipping']['shipping_country'];
$newfields['shipping']['shipping_address_1'] = $fields['shipping']['shipping_address_1'];
$newfields['shipping']['shipping_houseno'] = $fields['shipping']['shipping_houseno'];
$newfields['shipping']['shipping_city'] = $fields['shipping']['shipping_city'];
$newfields['shipping']['shipping_state'] = $fields['shipping']['shipping_state'];
$newfields['shipping']['shipping_postcode'] = $fields['shipping']['shipping_postcode'];
$checkout_fields = array_merge( $fields, $newfields);
return $checkout_fields;
}
now the problem is the confirmation, it should not validate if it does not match
here is what I'm using now
add_action( 'woocommerce_after_checkout_validation', 'wc_check_confirm_phone_matches_checkout', 10, 2 );
function wc_check_confirm_phone_matches_checkout( $posted ) {
$checkout = WC()->checkout;
if ( strcmp( $posted['billing_phone'], $posted['billing_phone_confirm_field'] ) !== 0 ) {
wc_add_notice( __( 'Phone number do not match.', 'woocommerce' ), 'error' );
}
}
The problem here is that is always shows "Phone number do not match." even if it matches, need help on this
Upvotes: 1
Reputation: 1
/**
*/
add_action( 'woocommerce_after_order_notes', 'some_custom_checkout_field' );
functionsome_custom_checkout_field( $checkout ) {
echo '
woocommerce_form_field( 'some_field_name', array(
'type' => 'text',
'class' => array('my-field-class form-row-wide'),
'label' => __('Additional Field'),
'placeholder' => __('Some hint'),
'required' => true,
), $checkout->get_value( 'some_field_name' ));
echo '';
}
Upvotes: 0