Skip Navigation

[Closed] Showing an icon for selected checkbox

This support ticket is created 9 years, 9 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Hong_Kong (GMT+08:00)

Tagged: 

This topic contains 10 replies, has 2 voices.

Last updated by Luo Yang 9 years, 8 months ago.

Assigned support staff: Luo Yang.

Author
Posts
#88739

Hi,

I run my online shop with Woocommerce. I have created several checkboxes on the product level (specific custom post type).
Bio, Upcycling, Swiss Made, Handmade, Fair & Social

If I enter a new product or if I modify an existing product I can maintain this checkboxes.

Now I'd like to display for each selected checkbox a specific Icon on the single product page, in the area of product description.
Even I have a licence for "View" I think this could be done with some code directly in the template.

Can you give me an example how the code has to look like?

Thanks a lot!
Serge

#90064

Luo Yang
Supporter

Languages: English (English ) Chinese (Simplified) (简体中文 )

Timezone: Asia/Hong_Kong (GMT+08:00)

Hi Serge,

Are we talking about display your custom checkboxes as an icon in front-end?

If it is, you can try Views shortcode wpv-if, for example:

[wpv-if evaluate="'[types field='product-level' separator=''][/types]' = 'Bio'"]
    here display an icon for Bio
[/wpv-if]

More help: https://toolset.com/documentation/user-guides/conditional-html-output-in-views/#Checking%20for%20Types%20checkboxes%20field

#91485

Hi luoy

Thanks for your help!

Where do I have to enter this code? In my woocommerce template?

Many thanks!
Serge

#92163
views2.jpg
views1.jpg

I added the shortcode to my singel product page template and in the post (post type prodcut). But the icon is not displayed.

#92632

Luo Yang
Supporter

Languages: English (English ) Chinese (Simplified) (简体中文 )

Timezone: Asia/Hong_Kong (GMT+08:00)

Serge, since your custom checkboxes field is storing multiple options, it is not possible with Views shortcode wpv-if, I suggest try create a custom shortcode for it, like this:

1) add codes in your theme/functions.php:

function icon_for_checkboxes_func( $atts ) {
     extract( shortcode_atts( array(
	      'field' => 'test-checkboxes',
	      'option' => ''
     ), $atts ) );
	 $res = '';
	 $value = types_render_field($field, array());
	 $field_value = explode(',', $value);
	 if(in_array($option, $field_value))
	 {
		$res = $option . '.icon';
	 }
     return $res;
}
add_shortcode( 'icon_for_checkboxes', 'icon_for_checkboxes_func' );

Please replace "test-checkboxes" with your custom field checkboxes slug,

2) put the shortcode into your content, like this:

[icon_for_checkboxes option="Bio"]
[icon_for_checkboxes option="Upcycling"]
....
#92696
custom_fields1.jpg
custom_fields2.jpg
custom_fields3.jpg

Hi luoy

Please see the attachements.
What have I done wrong?

Thanks
Serge

#93133

Luo Yang
Supporter

Languages: English (English ) Chinese (Simplified) (简体中文 )

Timezone: Asia/Hong_Kong (GMT+08:00)

Serge, please modify your codes in first screenshot:
hidden link

as this:

<?php
do_shortcode('[icon_for_checkboxes option="Bio"]');
....
?>

More help: http://codex.wordpress.org/Function_Reference/do_shortcode

#93556
custom_fields4.jpg

hi luoy,

the icons are still not displayed.
please see the attachment.

Thanks for your support!
Serge

#93685

Luo Yang
Supporter

Languages: English (English ) Chinese (Simplified) (简体中文 )

Timezone: Asia/Hong_Kong (GMT+08:00)

Serge, I tested the codes in my localhost, it works for me, could you try modify the PHP codes in your theme files as this:

<?php
print_r($value = types_render_field($field, array())); 
do_shortcode('[icon_for_checkboxes option="Bio"]');
....
?>

Check what output in the first line.
it should output something like this:
array(Bio, Upcycling ...)

#93694
custom_fields5.jpg

hi luoy

nothing is displayed. Did I setup the custom field correctly (please see attachment)? I also tried with the value "hallo" instead of the path of the icon.

Thanks
Serge

#93697

Luo Yang
Supporter

Languages: English (English ) Chinese (Simplified) (简体中文 )

Timezone: Asia/Hong_Kong (GMT+08:00)

Could you send the login details of your website to my email: luo.y@onthegosystems.com, also point out the problem page URL and where I can edit theme files, thanks

The topic ‘[Closed] Showing an icon for selected checkbox’ is closed to new replies.