Below code should be added in theme's functions.php file to add an extra Filed in Billing Address Form on checkout page , below code sample is to add 'Land-line Phone' Filed .
// Hook in*/
add_filter( 'woocommerce_checkout_fields' , 'custom_override_checkout_fields' );
// Our hooked in function - $fields is passed via the filter!
function custom_override_checkout_fields( $fields ) {
$fields['billing']['shipping_Landlinephone'] = array(
'label' => __('Landline Phone', 'woocommerce'),
'placeholder' => _x('Landline Phone', 'placeholder', 'woocommerce'),
'required' => false,
'class' => array('form-row-wide'),
'clear' => true
);
return $fields;
}
function display_shipping_Landlinephone($order){
echo "<p><strong>Landline Phone:</strong> " . $order->order_custom_fields['_shipping_Landlinephone'][0] . "</p>";
}
add_action( 'woocommerce_admin_order_data_after_billing_address', 'display_shipping_Landlinephone', 10, 1 );
//validate Field */
add_action('woocommerce_checkout_process', 'billing_phone_checkout_field_process');
function billing_phone_checkout_field_process() {
global $woocommerce;
// Check if set, if its not set add an error.
if (!$_POST['billing_phone'])
$woocommerce->add_error( __('Please enter something into Land-line Phone field.') );
}
No comments:
Post a Comment