Home › Forums › Backend Issues (wp-admin) › Adding PHP to a Meta Box
Hi,
I’m trying to create a simplified interface for WooCommerce so that the site owner can easily enter the few fields they will be using for products in one place. I need to create a meta box that displays fields generated by WooCommerce.
The code that comes from WooCommerce looks like this:
woocommerce_wp_text_input( array( ‘id’ => ‘_regular_price’, ‘label’ => __( ‘Regular Price’, ‘woocommerce’ ) . ‘ (‘ . get_woocommerce_currency_symbol() . ‘)’, ‘data_type’ => ‘price’ ) );
I generated a field group with ACF that displays only on product pages and it shows up fine. I also exported it so that I could get to the PHP in my functions file. It looks like this:
if(function_exists(“register_field_group”))
{
register_field_group(array (
‘id’ => ‘acf_streamlined-product-entry’,
‘title’ => ‘Streamlined Product Entry’,
‘fields’ => array (
array (
‘key’ => ‘field_556d8d41fdf81’,
‘label’ => ‘Streamlined Product Entry’,
‘name’ => ”,
‘type’ => ‘message’,
‘message’ => ‘This will hopefully be the area where streamlined product entry can happen.’,
),
),
‘location’ => array (
array (
array (
‘param’ => ‘post_type’,
‘operator’ => ‘==’,
‘value’ => ‘product’,
‘order_no’ => 0,
‘group_no’ => 0,
),
),
),
‘options’ => array (
‘position’ => ‘side’,
‘layout’ => ‘default’,
‘hide_on_screen’ => array (
),
),
‘menu_order’ => 0,
));
}
Now I’d like to add the WooCommerce to that ACF code so that it shows up as a part of the ACF Meta Box.
I have verified that the WooCommerce code works in my functions file by inserting it into a widget on the main dashboard screen.
Can you tell me how to insert the WooCommerce PHP into the ACF PHP to get the metabox to simply run the PHP within the box?
Thank you.
If I understand correctly, what you want to do is to show the woocommerce fields in the ACF field group when it is show on a post or page and to run PHP code.
I would probably use this add on plugin: https://wordpress.org/plugins/acf-enhanced-message-field/
The topic ‘Adding PHP to a Meta Box’ is closed to new replies.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.