• Resolved Mitchell Ellingson

    (@ettermanenterprises)


    Is their a way to add the variation description in the product page. Here is a link to the description I am talking about. Variation Description.

    And I want it added into the drop down box that shows the sku number.
    Link to drop down box with sku.
    You helped me earlier with showing the sku number. I think it would be easier for customers if they also saw the description as well.
    Thanks for the great support and help!

Viewing 5 replies - 1 through 5 (of 5 total)
  • con

    (@conschneider)

    Engineer

    Hi again,

    Yes, I remember your previous thread, welcome back :).

    So the trouble with variation description is that you:

    * first need the parent product ID.
    * With that you get the variations / variation ID.
    * And then you loop over all variations and get the description.

    Or something like this. Just thinking out loud.

    Your previous code:

    foreach ($results as $key => $result) {
                $variation_id = $result->product_id;
    }

    Do the $results also contain the descriptions so that you could do something like this or similar:

    $variation_id = $result->product_id;
    $variation_desc = $result->description;

    ?

    Kind regards,

    Thread Starter Mitchell Ellingson

    (@ettermanenterprises)

    I added the $variation_desc = $result->description; and that did not make it show up…
    Here is the code I have now.

    function display_price_in_variation_option_name( $term ) {
        global $wpdb, $product;
    
        if( isset( $product ) ) {
            $query = sprintf( "SELECT postmeta.post_id AS product_id
                FROM {$wpdb->prefix}postmeta postmeta
                LEFT JOIN {$wpdb->prefix}posts products ON ( products.id = postmeta.post_id )
                WHERE postmeta.meta_key LIKE 'attribute_%%'
                AND postmeta.meta_value = '%s'
                AND products.post_parent = %d", $term, $product->get_id() );
    
            $results = $wpdb->get_results( $query );
    
            foreach ($results as $key => $result) {
                $variation_id = $result->product_id;
    			$variation_desc = $result->description;
            }
    
            $variation_sku = get_post_meta( $variation_id , '_sku', TRUE );
    
            $term = $variation_sku;
        }
    
        return $term;
    }
    add_filter( 'woocommerce_variation_option_name', 'display_price_in_variation_option_name', 10, 1 );
    Mirko P.

    (@rainfallnixfig)

    Hi @ettermanenterprises,

    This is a fairly complex development topic. I’m going to leave it open for a bit to see if anyone is able to chime in to help you out.

    You can also visit the WooCommerce Facebook Community 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, as well.

    Cheers!

    Thread Starter Mitchell Ellingson

    (@ettermanenterprises)

    Thanks I will check them out

    Mirko P.

    (@rainfallnixfig)

    Hi there,

    We’ve not seen any activity on this thread for a while, so I’m marking this thread as resolved.

    Hopefully, you were able to come up with a solution! If you have further questions, please feel free to open a new topic.

    Cheers.

Viewing 5 replies - 1 through 5 (of 5 total)

The topic ‘Show Variation Description’ is closed to new replies.