I’ve the next code which provides the worth subsequent to every variation:
//Add costs to variations
add_filter( 'woocommerce_variation_option_name', 'display_price_in_variation_option_name' );
operate display_price_in_variation_option_name( $time period ) {
international $wpdb, $product;
$outcome = $wpdb->get_col( "SELECT slug FROM {$wpdb->prefix}phrases WHERE identify = '$time period'" );
$term_slug = ( !empty( $outcome ) ) ? $outcome[0] : $time period;
$question = "SELECT postmeta.post_id AS product_id
FROM {$wpdb->prefix}postmeta AS postmeta
LEFT JOIN {$wpdb->prefix}posts AS merchandise ON ( merchandise.ID = postmeta.post_id )
WHERE postmeta.meta_key LIKE 'attribute_%'
AND postmeta.meta_value = '$term_slug'
AND merchandise.post_parent = $product->id";
$variation_id = $wpdb->get_col( $question );
$mother or father = wp_get_post_parent_id( $variation_id[0] );
if ( $mother or father > 0 ) {
$_product = new WC_Product_Variation( $variation_id[0] );
//that is the place you'll be able to truly customise how the worth is displayed
return $time period . ' <span>(' . woocommerce_price( $_product->get_price() ) . ')</span>';
}
return $time period;
}
This code works completely. Nonetheless I want to have that code apply solely to a selected product attribute (the slug is training-level). Is that this attainable with a if assertion and conditional tags?
I additionally tried including the next simply bellow international $wpdb, $product;
however did not work:
$product_name = $product->get_attribute( 'training-level' );
Please assist.