Home Forums Backend Issues (wp-admin) Adding PHP to a Meta Box


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:

    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:

Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.