In WooCommerce, when I submit, how to catch a custom select field added in the order edit admin pages?
I have added this custom select field in the file class-wc-meta-box-order-data.php
. I get this:
But I dont know how to catch or to save $_POST['vendor']
I have tried to add $_POST['vendor']
in wp-admin/post.php
,but it doesn't work.
This is the code that I have added:
<select class="wc-customer-search" id="customer_user" name="customer_user" data-placeholder="<?php esc_attr_e( 'Guest', 'woocommerce' ); ?>" data-allow_clear="true">
<option value="<?php echo esc_attr( $user_id ); ?>" selected="selected"><?php echo htmlspecialchars( $user_string ); ?></option>
</select>
<!--/email_off-->
</p>
<p> <label for="order_status">供應商: </label>
<select name="vendor">
<?php
global $wpdb;
$user_count = $wpdb->get_var( "SELECT COUNT(*) FROM $wpdb->users" );
for($i=1;$i<=$user_count;$i++){
$user_info = get_userdata($i);
if (implode(', ', $user_info->roles)=='vendor')
echo "<option value=".$user_info->user_login.">$user_info->user_login</option>";
}
?>
</select></p>
How can I get the submitted value and how can I save it?
Overriding core files is something prohibited for developers. So this is not the correct way to do it.
The way to do it is using the available hooks in the source code, instead of overriding this core files, as you will loose everything when the plugin will be updated.
Here is the replacement code + a hook to save the data to the order meta data:
Code goes in function.php file of your active child theme (or theme) or also in any plugin file.
This code is tested and works.