function ahirwp_add_location_number() {
$args_1 = array(
'label' => __( 'location number', 'woocommerce' ),
'placeholder' => __( 'Enter location number here', 'woocommerce' ),
'id' => 'location_number',
'desc_tip' => true,
'description' => __( 'This location number is for internal use only.', 'woocommerce' ),
);
woocommerce_wp_text_input( $args_1 );
}
add_action( 'woocommerce_product_options_sku', 'ahirwp_add_location_number' );
// Save
function ahirwp_save_custom_meta( $product ){
if( isset($_POST['location_number']) ) {
$product->update_meta_data( 'location_number', sanitize_text_field( $_POST['location_number'] ) );
}
}
add_action( 'woocommerce_admin_process_product_object', 'ahirwp_save_custom_meta', 10, 1 );
Add above code in function.php of your active theme.
Okay so this code will help you to add one custom fields to each products in backend. but for sending this number to cart/checkout/order emails and invoice you need more custom code. I hope that helps.
Thanks
Ahir
-
This reply was modified 5 years, 2 months ago by
Ahir Hemant.
Thanks for this. I have added the code but how do I access the custom field to edit it on products? I have checked the product page and there is no option eg in the price or SKU area – would it be somewhere else that I’m missing?
I am planning on using a plugin to send this number to my invoices but it’s implementing it onto my products to begin with that I’m finding difficult.
It’s fixed now, thanks for your time 🙂