Skip to content

Instantly share code, notes, and snippets.

@paaljoachim
Last active September 2, 2019 19:27
Show Gist options
  • Save paaljoachim/ac7b85c0adbbee506ab2327e37379182 to your computer and use it in GitHub Desktop.
Save paaljoachim/ac7b85c0adbbee506ab2327e37379182 to your computer and use it in GitHub Desktop.
WooCommerce Checkout: Add multiple custom fields to billing area - PART 2
// 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,
);
$fields['billing']['billing_org'] = array(
'label' => 'Organization',
'type' => 'text',
'required' => true,
'class' => array( 'form-row-wide' ),
'priority' => 27,
);
$fields['billing']['billing_sales'] = array(
'label' => 'How many will sell these products?',
'type' => 'text',
'required' => true,
'class' => array( 'form-row-wide' ),
'priority' => 28,
);
$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_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_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_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_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