I am trying to edit an existing meta box that is being added by a plugin (WooCommerce) in WordPress, but I do not know how to do this.
The meta box is added with this line:
add_meta_box( 'woocommerce-product-data', __('Product Data', 'woocommerce'), 'woocommerce_product_data_box', 'product', 'normal', 'high' );
…so the function outputting the HTML to screen is woocommerce_product_data_box()
. Is there any way to edit this function without loosing it all? I only want to remove parts of it and without editing the original function.
Can I accomplish this with filters somehow? Or any other ideas?
Thanks!
You can find the actual function that writes the meta box for that in the
writepanel-product_data.php
file. At line 24:That lists everything in the product data. You can add text boxes or drop downs by using the WooCommerce API. Find the place you’d like to add, or delete, then-
For a text field –
For a drop down –
So, you give the input an ID, YOURCUSTOMID, and then label it whatever you want the admin to see when they are filling out the field, THELABELOFTHEFIELD.
The same with custom meta boxes in WordPress posts/pages, you still have to save it, though. Find the function
woocommerce_process_product_meta()
somewhere around line 600. The comments above will tell you it is saving the meta box data. Then, insert a line of code to save whatever custom ID you just gathered –and just change it for you custom ID. Just make sure you put that line of code anywhere after the
global
s are declared.Naturally, for removing fields, you can just comment out the fields that you don’t want gathered in both of those functions.
Hope that helps.