• Resolved raha1988ab

    (@raha1988ab)


    Hello

    In WooCommerce plugin of WordPress, as you know there is one taxonomy called “Attributes” that let us add some filters (attributes) for products and assign them to products. Each attributes can have multiple items like a category with multiple sub-categories that called “Attribute terms”. When we want add or edit attribute terms, we have a “Description” textarea.

    I have WoodMart theme so I would like to display these descriptions in Front-End of their pages.

    the URL of the attribute’s page in front-end is like this:

    example.com/product-category/sofas/?filter_brand=4mariani

    And this is code I’m using but doesn’t add nothing to these pages:

    function display_attribute_term_description() {
        // Get the current attribute term
        $term = get_queried_object();
    
        // Check if the term exists and has a description
        if ($term && !empty($term->description)) {
            echo '<div class="attribute-description">' . wpautop($term->description) . '</div>';
        }
    }
    add_action('woocommerce_before_main_content', 'display_attribute_term_description');

    I’m also trying to make a category page with Elementor Plugin, but there isn’t any dynamic widget for the term’s description. so I’ve added a text widget and tried to inject the term’s description into it and still doesn’t work:

    function inject_term_description_into_archive_description( $content ) {
        if ( is_category() ) {
            $term_description = term_description();
            $content = $term_description . $content;
        }
        return $content;
    }
    add_filter( 'get_the_archive_description', 'inject_term_description_into_archive_description' );

    After this way, I’ve tried to add a custom widget in Elementor for showing term’s description and still doesn’t work.

    <?php
    use Elementor\Widget_Base;
    
    class Custom_Term_Description_Widget extends Widget_Base {
    
        public function get_name() {
            return 'custom-term-description-widget';
        }
    
        public function get_title() {
            return __( 'Custom Term Description', 'your-text-domain' );
        }
    
        public function get_icon() {
            return 'eicon-text-area';
        }
    
        public function get_categories() {
            return [ 'general' ];
        }
    
        protected function _register_controls() {
            $this->start_controls_section(
                'section_content',
                [
                    'label' => __( 'Content', 'your-text-domain' ),
                ]
            );
    
            $this->add_control(
                'term_description',
                [
                    'label' => __( 'Term Description', 'your-text-domain' ),
                    'type' => \Elementor\Controls_Manager::WYSIWYG,
                    'dynamic' => [
                        'active' => true,
                        'categories' => [
                            \Elementor\Modules\DynamicTags\Module::POST_META_CATEGORY,
                        ],
                        'default' => \Elementor\Modules\DynamicTags\ACF\Module::TEXT_CATEGORY,
                    ],
                ]
            );
    
            $this->end_controls_section();
        }
    
        protected function render() {
            $settings = $this->get_settings_for_display();
            echo wpautop( $settings['term_description'] );
        }
    
    }

    and then i just added this to my?functions.php?child-theme file.

    function register_custom_term_description_widget() {
        require_once get_template_directory() . '/custom-term-description-widget.php';
        \Elementor\Plugin::instance()->widgets_manager->register_widget_type( new Custom_Term_Description_Widget() );
    }
    add_action( 'elementor/widgets/widgets_registered', 'register_custom_term_description_widget' );

    Any idea what should I do?

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

Viewing 5 replies - 1 through 5 (of 5 total)
  • Hey there, @raha1988ab! Thanks for contacting us.

    Please note that we can’t provide support for code customization as per our support policy. Still, if you need customization, we do our best to offer advice and direct you to appropriate resources.

    You can visit the WooCommerce Facebook group or the #developers channel of the WooCommerce Community Slack. We’re lucky to have a great community of open-source developers for WooCommerce, and many of our developers hang out there too.

    Since you are using a third-party theme and Elementor, it is possible you can also get help on its forums if you want to try ??

    I’m going to leave it open for a bit to see if anyone is able to chime in and help you out further.

    Have a wonderful day!

    Thread Starter raha1988ab

    (@raha1988ab)

    Hi @carolm29

    Ok , Let me talk another way

    We all know that in woocommerce we have attributes and each attributes have Terms and each terms have descriptions, How can I show this description on the front end of the site?

    For example, my address is https://example.com/shop/?filter_brand=sony

    I want to show the description of Sony in the front end, is it possible?

    *Note: I’m not going to enable Archives, I want my url to be dynamically or query strings not static urls

    Plugin Support Shameem a11n

    (@shameemreza)

    Hi @raha1988ab,

    Yes, displaying the description of your attributes like ‘Sony’ on the front end is possible. You would need to add a bit of custom code. This code would call the term description based on the query string and display it on your shop page.

    However, as we mentioned earlier, writing or providing custom code is not within the scope of our support policy. For development and custom coding questions, it’s best to ask for insight related to those on either the WooCommerce Advanced Facebook group or the WooCommerce Community Slack.

    You can also seek help from the following:

    I wish I could help more, but hopefully, this gets you going in the right direction to get the job done.

    Thread Starter raha1988ab

    (@raha1988ab)

    Hi, I fixed it with the snippet got in FB group

    function display_attribute_term_description() {
    // Get the current attribute term
    $slug = get_query_var('filter_brand');
    $term = get_term_by('slug',$slug, 'pa_brand');
    // Check if the term exists and has a description
    if ($term && !empty($term->description)) {
    echo '<div class="attribute-description">' . wpautop($term->description) . '</div>';
    }
    }
    add_action('woocommerce_before_main_content', 'display_attribute_term_description');

    I have a new question, is it possible to have this filter page canonical and meta description?

    Hey, @raha1988ab!

    I’m glad you were able to achieve your goal.

    Thank you for sharing the code here so it can help other users in the future. This is really helpful to the community.

    I have a new question, is it possible to have this filter page canonical and meta description?

    You might be able to do this with custom code or by using a SEO plugin such as Yoast SEO, for example.

    But to know more about it it would be best to reach out to them directly so they can guide you to the right direction.

    If you choose the custom code path, you can reach out on the channels we mentioned for community help.

    I’m going to leave it open for a bit to see if anyone is able to chime in and help you out further.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘WordPress: How to show product term’s description in Front-End?’ is closed to new replies.