In WooCommerce, I would like to display variable products with my own custom design as a carousel of product variations. I got the code by which I can display the regular price of the product in array but I stuck in getting attribute name and value in that.
Based on "WooCommerce variable products: Display some variations values in an HTML table" answer code, here is my actual code:
add_action( 'woocommerce_before_single_product_summary', 'custom_table_after_single_product' );
function custom_table_after_single_product(){
global $product;
// Only for variable products
if( ! $product->is_type('variable')) return;
$available_variations = $product->get_available_variations();
// Get product attributes
$attributes = $product->get_attributes();
if( count($available_variations) > 0 ){
$output = ' <section class="boxes">
<div class="container">
<div class="row">
<div class="owl-carousel packed_sections">';
// Get product attributes
foreach( $available_variations as $variation ){
// Get an instance of the WC_Product_Variation object
$product_variation = wc_get_product($variation['variation_id']);
$sale_price = $product_variation->get_sale_price();
if( empty( $sale_price ) ) $sale_price = __( '<em>(empty)</em>', 'woocommerce' );
$output .= '
<div class="col-sm-12 package_box">
<div class="inside">
<div class="number">1000</div>
<div class="number_text">Followers</div>
<div class="price"><sup>$</sup> <span>'.$product_variation->get_regular_price().'</span></div>
<div class="services">
<ul>
<li><i class="fa fa-video-camera"></i> Include Video Views</li>
<li><i class="fa fa-star"></i> High quality likes</li>
<li><i class="fa fa-lock"></i> no password required</li>
<li><i class="fa fa-clock-o"></i> order start in 60 seconds</li>
<li><i class="fa fa-clock-o"></i> fast deliver 10 minutes</li>
<li><i class="fa fa-commenting"></i> 24/7 support</li>
</ul>
</div>
<div class="buy"><a href="#">buy now</a></div>
</div>
</div>';
}
echo $output;
}
}
This code gives the correct output, but I want attribute value and name with that also here is the output screenshot: