Home › Forums › Backend Issues (wp-admin) › Dynamically set the value of a field › Reply To: Dynamically set the value of a field
I have this currently:
function whatis_single_product_type( $field ) {
$field['value'] = __('initialize', 'txtdomain');
global $post;
if( function_exists('get_product') ){
$product = get_product( $post->ID );
if( $product->is_type( 'variable' ) ){
$field['value'] = __('variable', 'txtdomain');
} elseif( $product->is_type( 'simple' ) ){
$field['value'] = __('simple', 'txtdomain');
}
}
return $field;
}
add_filter( 'acf/load_field/name=product_type_set', whatis_single_product_type );
Although this seems to work – saving the text, either ‘variable’ or ‘simple’ to the acf product_type_set (otherwise it stays set to ‘initialize’) – does anyone have a better way?
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!
Our guide looks into WordPress custom fields and how they stack up against the possibilities of ACF.
— Advanced Custom Fields (@wp_acf) July 18, 2022
https://t.co/hk3yibkHyk
© 2022 Advanced Custom Fields.
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 Cookie Policy. If you continue to use this site, you consent to our use of cookies.