• Resolved hcoolj

    (@hcoolj)


    I would like to show attribute terms description.

    See my PDF here: [ redundant link removed ]

    • This topic was modified 4 years, 1 month ago by Jan Dembowski. Reason: Moved to Fixing WordPress, this is not an Everything else WordPress topic

    The page I need help with: [log in to see the link]

Viewing 12 replies - 1 through 12 (of 12 total)
  • Hallo there 🙂

    Sorry, I am not quite sure what you are asking?
    Do you want to add product attribute descriptions to a PDF?

    Moderator bcworkz

    (@bcworkz)

    It depends on what function is generating that dropdown. It’s reasonable to expect it to call get_terms() at some point. You can use the “get_terms” filter to alter the data returned, setting each description as the term’s name property. I don’t think doing so will affect any upstream functions, but this is an untested idea.

    Thread Starter hcoolj

    (@hcoolj)

    Hey carike

    There is a link to a PDF file which shows what I want.

    Hi bcworkz

    I have tried to look trough the files but not been able to find where to change the programming.

    Moderator bcworkz

    (@bcworkz)

    The filter’s docs page is https://developer.wordpress.org/reference/hooks/get_terms/
    It is applied here, but absolutely do not change that code. It’s just FYI.

    Filtered values are altered through filter hooks, whose code can be added to a child theme’s functions.php or added to a custom plugin. Creating a simple plugin is a bit easier than making a child theme. Neither are difficult to do.

    Thread Starter hcoolj

    (@hcoolj)

    Hi bcworkz

    Can you help me with a code for fuctions.php or a plugin.

    I am not that good at programming.

    Thanks

    Moderator bcworkz

    (@bcworkz)

    I don’t normally code for forum members like this, but I seem to have some extra time on my hands. Create a new plain text file and add this code:

    <?php
    /**
     * Plugin Name: Description to Name
     * Description: Copies term descriptions to the name field for display purposes
     * Author: bcworkz
     * Version: 0.10 beta
     */
    
    // Define targeted taxonomy here
    define('BCW_TAX', 'my-taxonomy');
    
    add_filter('get_terms', function( $terms, $tax, $args ) {
    	// check if $terms is in a format our code can work with
    	if ( BCW_TAX == $tax[0] && 'all'== $args['fields'] && NULL == $args['object_ids']) {
    		$copy = array();
    		foreach ( $terms as $term) {
    			$term->name = $term->description;
    			$copy[] = $term;
    		}
    		return $copy;
    	}
    	return $terms;
     }, 10, 3 );

    Change 'my-taxonomy' to whatever your taxonomy name is in the define() line. Save the file as “description-to-name.php”. Upload via FTP to /wp-content/plugins/ on your server. Log into your WP site and activate the “Description to Name” plugin.

    I did some very limited testing to ensure there are no blatant errors. There may be unanticipated side effects I’ve not anticipated.

    Thread Starter hcoolj

    (@hcoolj)

    Hello bzworkz

    Thanks a lot for your help.

    But I am not shurre what you mean by ‘my-taxonomy’?

    How or where do I find out what ‘my-taxonomy’ is?

    So it is not working yet.

    Best Regards

    Thread Starter hcoolj

    (@hcoolj)

    Can anyone help me the last step?

    Moderator bcworkz

    (@bcworkz)

    Hi hcoolj – sorry for the slow reply. The notification from a few days ago never got to me. Thanks for your patience.

    We need your taxonomy’s actual internal name (its “slug”), which will replace “my-taxonomy” in the previously posted code. The best way to determine what that is is by going to that taxonomy’s term listing screen in the admin area. Examine that screen’s URL in your browser’s address bar. It will in part be /wp-admin/edit-tags.php?taxonomy=. Whatever follows that but is before the subsequent &post_type= will be the internal name to use. If the related post type is the default post type, there will not be anything after the internal name.

    Thread Starter hcoolj

    (@hcoolj)

    Hello bcworkz

    Thanks a lot.

    I was almost there, the taxonomy was only missing a “pa_” so now it is working.

    Not exactly as i wanted but definitely usable. It is now showing instead of the value, which is also ok as long as it is the value that is send on.
    I was hoping to have both the value and the description showing next to each other.

    Moderator bcworkz

    (@bcworkz)

    On this line:
    $term->name = $term->description;

    make it like this:
    $term->name .= ' = '. $term->description;

    The dot operator . concatenates strings. You can join with something besides ' - '. This code should only affect display and not the underlying data. I’ve not tested too extensively though.

    Thread Starter hcoolj

    (@hcoolj)

    Yes this is perfect.

    Thank you so much

Viewing 12 replies - 1 through 12 (of 12 total)
  • The topic ‘Attribute terms description not showing’ is closed to new replies.