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,
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 );
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!
Thanks I will check them out
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.