Below is the WooCommerce Custom Product with custom field, custom tab and it's content:
I'm sampling the first text field at this tab. Goal is to get the "label" property of these fields.
function launch_product_tab_content() {
global $post;
?><div id='launch_contents' class='panel woocommerce_options_panel'><?php
?><div class='options_group'><?php
woocommerce_wp_text_input( array(
'id' => '_text_announced',
'label' => __( 'Announced(Global)', 'woocommerce' ),
'desc_tip' => 'true',
'description' => __( 'Year and Month it was announced global', 'woocommerce' ),
'type' => 'text',
) );
woocommerce_wp_text_input( array(
'id' => '_text_announced_ph',
'label' => __( 'Announced(Philippines)', 'woocommerce' ),
'desc_tip' => 'true',
'description' => __( 'Year and Month it was announced global', 'woocommerce' ),
'type' => 'text',
) );
woocommerce_wp_text_input( array(
'id' => '_text_availability_ph',
'label' => __( 'Availability(Philippines)', 'woocommerce'),
'desc_tip' => 'true',
'description' => __( 'Schedule date of availability in the Philippines', 'woocommerce' ),
'type' => 'text',
) );
?></div>
</div><?php
}
add_action( 'woocommerce_product_data_panels', 'launch_product_tab_content' );
This is what it looks like at the Product editor page, Custom Product at Wordpress:
Now, using ACF, I used this code:
<?php
$field_key = "_text_announced";
$post_id = $post->ID;
$field = get_field_object($field_key, $post_id);
echo $field['label'] . ': ' . $field['value'];
?>
tried also the echo var_dump($field);
Someone said that the WooCommerce project is not binded to ACF object? That's why I can't access the WooCommerce object via ACF? Your thoughts.
Thanks!
I Have make some changes In your code adding hidden imput fields with your label names. When saving/submitting the data, it will save also automatically the label names.
Here is the complete code:
Code goes in function.php file of your active child theme (or theme) or also in any plugin file.
Once submitted (SAVED) all the data is set in
wp_postmeta
table for the current product ID (even the label names), see bellow what you get in this database table (the ID of the product is 99 here):Here now a function that will automate that process and set those values in an array:
Code goes in function.php file of your active child theme (or theme) or also in any plugin file.
Now we can use this function in any PHP file:
And you will get:
So no need of ACF here
This code is tested and works...