Support

Account

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?