Last active
September 2, 2019 12:33
-
-
Save paaljoachim/986f679fb91c9a838f92b5bf2ad13c2b to your computer and use it in GitHub Desktop.
WooCommerce Checkout: Add multiple custom fields to billing area
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// https://businessbloomer.com/woocommerce-add-shipping-phone-checkout/ | |
// Year | |
add_filter( 'woocommerce_checkout_fields', 'bbloomer_billing_year_checkout' ); | |
function bbloomer_billing_year_checkout( $fields ) { | |
$fields['billing']['billing_year'] = array( | |
'label' => 'I am over 18', | |
'type' => 'checkbox', | |
'required' => true, | |
'class' => array( 'form-row-wide' ), | |
'priority' => 26, | |
); | |
return $fields; | |
} | |
add_action( 'woocommerce_admin_order_data_after_shipping_address', 'bbloomer_billing_year_checkout_display' ); | |
function bbloomer_billing_year_checkout_display( $order ){ | |
echo '<p><b>Billing Year:</b> ' . get_post_meta( $order->get_id(), '_billing_year', true ) . '</p>'; | |
} | |
// Organization | |
add_filter( 'woocommerce_checkout_fields', 'bbloomer_billing_org_checkout' ); | |
function bbloomer_billing_org_checkout( $fields ) { | |
$fields['billing']['billing_org'] = array( | |
'label' => 'Organization', | |
'type' => 'text', | |
'required' => true, | |
'class' => array( 'form-row-wide' ), | |
'priority' => 27, | |
); | |
return $fields; | |
} | |
add_action( 'woocommerce_admin_order_data_after_shipping_address', 'bbloomer_billing_org_checkout_display' ); | |
function bbloomer_billing_org_checkout_display( $order ){ | |
echo '<p><b>Billing Year:</b> ' . get_post_meta( $order->get_id(), '_billing_org', true ) . '</p>'; | |
} | |
// Sales | |
add_filter( 'woocommerce_checkout_fields', 'bbloomer_billing_sales_checkout' ); | |
function bbloomer_billing_sales_checkout( $fields ) { | |
$fields['billing']['billing_sales'] = array( | |
'label' => 'How many will sell these products?', | |
'type' => 'text', | |
'required' => true, | |
'class' => array( 'form-row-wide' ), | |
'priority' => 28, | |
); | |
return $fields; | |
} | |
add_action( 'woocommerce_admin_order_data_after_billing_address', 'bbloomer_billing_sales_checkout_display' ); | |
function bbloomer_billing_sales_checkout_display( $order ){ | |
echo '<p><b>How many will sell these products?</b> ' . get_post_meta( $order->get_id(), '_billing_sales', true ) . '</p>'; | |
} | |
// Contact person | |
add_filter( 'woocommerce_checkout_fields', 'bbloomer_billing_contact_checkout' ); | |
function bbloomer_billing_contact_checkout( $fields ) { | |
$fields['billing']['billing_contact'] = array( | |
'label' => 'Contact person from our company?', | |
'required' => true, | |
'class' => array( 'form-row-wide' ), | |
'priority' => 28, | |
'type' => 'select', | |
'options' => array( // options for <select> or <input type="radio" /> | |
'' => 'Please select', // empty values means that field is not selected | |
'ingen_kontakt_person' => 'No contact person', // 'value'=>'Name' | |
'Regine' => 'Employee 1', | |
'mei_mei' => 'Employee 2' | |
) | |
); | |
return $fields; | |
} | |
add_action( 'woocommerce_admin_order_data_after_billing_address', 'bbloomer_billing_contact_checkout_display' ); | |
function bbloomer_billing_contact_checkout_display( $order ){ | |
echo '<p><b>Contact person from our company?</b> ' . get_post_meta( $order->get_id(), '_billing_contact', true ) . '</p>'; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment