Created
March 8, 2021 17:48
-
-
Save scottopolis/102b35955313fafb4bf0b8b98674b666 to your computer and use it in GitHub Desktop.
WooCommerce add shipping phone number
This file contains hidden or 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
<?php | |
// add this code to a theme functions.php or custom plugin | |
add_filter( 'woocommerce_checkout_fields' , 'sb_override_checkout_fields' ); | |
// Our hooked in function - $fields is passed via the filter! | |
function sb_override_checkout_fields( $fields ) { | |
$fields['shipping']['shipping_phone'] = array( | |
'label' => __('Phone', 'woocommerce'), | |
'placeholder'=> _x('Phone', 'placeholder', 'woocommerce'), | |
'required' => false, | |
'class' => array('form-row-wide'), | |
'clear' => true | |
); | |
return $fields; | |
} | |
/** | |
* Optionally display field value on the order edit page | |
*/ | |
add_action( 'woocommerce_admin_order_data_after_shipping_address', 'sb_checkout_field_display_admin_order_meta', 10, 1 ); | |
function sb_checkout_field_display_admin_order_meta($order){ | |
global $post_id; | |
$order = new WC_Order( $post_id ); | |
echo '<p><strong>'.__('Field Value').':</strong> ' . get_post_meta($order->get_id(), '_shipping_field_value', true ) . '</p>'; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment