Change checkbox display on single product page

We're shifting our Forum based support to a more dedicated support system!

We'll be closing our Forum support from 10th June, 2020 and move to Email Support assistance.

  • If you are a WCFM premium add-ons user, contact us- here
  • Want to know more before buying our add-ons? Send Pre sale queries- here
  • If you are a WCFM free user, please open a support ticket at WordPress.org
  • For WCFM App related queries, reach us- here
From now the forum will be read-only!

Viewing 9 reply threads
  • Author
    Posts
    • #84764
      cartaclaudio
      Participant

      Hi,

      I have 2 custom check boxes, one called pre-order and the other explicit. I would like to modify their display so that it does not show when left empty. I would also like to display it in a different way which will show the universal explicit image instead of just a checkbox.

      I am trying to figure out a way of doing this through functions.php, yet I have encountered a brick wall.

      How can this be achieved please?

      Attachments:
      You must be logged in to view attached files.
    • #86170
      WCFM Forum
      Keymaster

      HI,

      Please use this line to your site –

      add_filter( 'wcfm_is_allow_custom_field_display_by_icon', '__return_false' );

      Add this code to your child theme’s functions.php
      In case you do not have child theme then add code using this plugin –¬†https://wordpress.org/plugins/code-snippets/

      Thank You

    • #86793
      cartaclaudio
      Participant

      Thank you so much. with this code it displays the word no instead of an icon. is it possible to not display the field at all if left unchecked?

      Regards,
      Claudio

    • #87077
      WCFM Forum
      Keymaster

      Hi,

      Please add this code to your site –

      add_filter( 'wcfm_custom_field_value', function( $field_value, $field_name, $product_id, $field_type ) {
      	if( $field_type == 'checkbox' ) {
      		if( $field_value == 'no' ) {
      			$field_value = '';
      		} else {
      			$field_value = get_post_meta( $product_id, $field_name.'_checkbox', true );
      		}
      	}
      	return $field_value;
      }, 50, 4 );

      Thank You

    • #89011
      cartaclaudio
      Participant

      Hi,

      I have added this code to functions.php, the function is getting in but when the field_values are no(tested by var_dump) they are still producing the checkbox post meta.

    • #90868
      WCFM Forum
      Keymaster

      HI,

      This code will hide label if checkbox is not checked!

      Thank You

    • #93283
      cartaclaudio
      Participant

      Hi,

      I have been testing a playing around with this one, however it does not work. When the field_value is ” its returning everything as checked instead of hiding the value.

    • #93583
      WCFM Forum
      Keymaster

      Well, this code only works for checkbox type fields.

    • #97545
      cartaclaudio
      Participant

      Thanks this works great like this

      add_filter( 'wcfm_custom_field_value', function( $field_value, $field_name, $product_id, $field_type ) {
      	if( $field_type == 'checkbox' ) {
      		if( $field_value == 'no' ) {
      			add_filter( 'wcfm_is_allow_custom_field_display_by_icon', '__return_false' );
      			$field_value = '';
      		} else {
      			if( $field_name == 'explicit' ) {
      				add_filter( 'wcfm_is_allow_custom_field_display_by_icon', '__return_false' );
      				$field_value = '<img src="http://XXXXXXX/wp-content/themes/themify-music-child/images/explicit.png" width="64px" />';
      			}else {
      				$field_value = get_post_meta( $product_id, $field_name.'_checkbox', true );		
      			}
      		}
      	}
      	return $field_value;
      }, 50, 4 );
      

      is there a filter I can use to hide the checkboxes name from appearing in a label?

    • #98875
      WCFM Forum
      Keymaster

      HI,

      is there a filter I can use to hide the checkboxes name from appearing in a label?

      – Sorry, don’t get this. Please show me scree shot for this.

      Thank You

Viewing 9 reply threads
  • The topic ‘Change checkbox display on single product page’ is closed to new replies.