WordPress.org

Ready to get started?Download WordPress

Forums

WooCommerce - excelling eCommerce
Product Attribute Variation Description (7 posts)

  1. mydog8it
    Member
    Posted 1 year ago #

    Does anyone know of a way to get the description entered when you set up an attribute term (term_description) that's used as a variable to show up when someone selects that variable on the product page?

    Some variables have lengthy descriptions, and I'd like to show them near the price when different variables are selected, as well as on the checkout pages below the selected product variable name.

    I can't find any reference to this in the woocommerce docs. Best I've been able to do is pull the first term description using the lines below, but I can't get it to change to the selected one.

    <?php $my_taxonomy = 'pa_myterm';
    $terms = wp_get_post_terms( $post->ID, $my_taxonomy );
    echo term_description($terms[0]->term_id, $my_taxonomy); ?>

    http://wordpress.org/extend/plugins/woocommerce/

  2. John Hager
    Member
    Posted 1 year ago #

    mydog8it, I am interested in the same answer. What is the link to your site? My site is foryourcue.com

  3. rhristova
    Member
    Posted 1 year ago #

    mydog8it, John Hager, I don't know if you are still looking for a solution but in case anyone else needs one here is mine:

    if ( taxonomy_exists( sanitize_title( $name ) ) ) {
                                        $terms = get_terms( sanitize_title($name), array('menu_order' => 'ASC') );
                                        foreach ( $terms as $term ) {
                                            if ( ! in_array( $term->slug, $options ) ) continue;
                                            echo '<input type="radio" value="' . strtolower($term->slug) . '" ' . checked( strtolower ($selected_value), strtolower ($term->slug), false ) . ' id="'. esc_attr( sanitize_title($name) ) .'" name="attribute_'. sanitize_title($name).'">' . apply_filters( 'woocommerce_variation_option_name', $term->name ).'<br />';
    										echo '<div class="plans-description">' . strtolower($term->description) . '</div><br />';//this is the line you need to add to show the description. I wrapped it in a div.
                                        }
                                    } else {
                                        foreach ( $options as $option )
                                            echo '<input type="radio" value="' .strtolower($option) . '" ' . checked( strtolower ($selected_value), strtolower ($option), false ) . ' id="'. esc_attr( sanitize_title($name) ) .'" name="attribute_'. sanitize_title($name).'">' . apply_filters( 'woocommerce_variation_option_name', $option ) . '<br />';
    										echo '<div class="plans-description">' . strtolower($term->description) . '</div><br />';//this is the line you need to add to show the description. I wrapped it in a div.
                                    }

    Have in mind I am using the "Woo Radio Buttons" plugin.So I don't know how this handles with the default select, but it's a start

  4. rhristova
    Member
    Posted 1 year ago #

    This only shows the description if it exists:

    $term_desc = strtolower($term->description);
    if ( '' !== $term_desc ){
    echo "<div class='plans-description'>$term_desc</div><br />";
    }
  5. mydog8it
    Member
    Posted 1 year ago #

    Thanks rhristova. I'll give it a try and let you know if it works without the plugin.

  6. Sloth69
    Member
    Posted 9 months ago #

    hi, rhristova...
    where should I put your php code to make it work?

  7. RaviArt
    Member
    Posted 9 months ago #

    I can not get it to work ... can anyone tell me which php file and put this code in that line?

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic