0

I am using advanced custom fields checkbox and have it set to return format "both label & value". I would like to display checkbox value on the frontend except if the page is woocommerce product category, then it should output the label. I have created a shortcode in order to output the checkbox value/label in the frontend. The only problem is, that it keeps outputting "array" and not label/value as I would like it to do.

function hello_shortcode() { 
 
// Load field settings and values.
$field = get_field_object('producent');

if( !is_product_category() ) {
    $checkbox = $field['value'];
} else {
 $checkbox = $field['label'];
}

return $checkbox;


} 
// register shortcode
add_shortcode('hello', 'hello_shortcode'); 
0

You have to return the output with the value. you can check the following code.


function hello_shortcode() { 
 
    // Load field settings and values.
    $field = get_field_object('producent');

    if( ! is_product_category() ) {
        $checkbox = $field['value'];
    } else {
        $checkbox = $field['label'];
    }

    $output = '‹p›'.$checkbox.'‹/p›';

    return $output;

} 

// register shortcode
add_shortcode('hello', 'hello_shortcode');  

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.