<?php
switch ( $product->product_type ) {
case "variable" :
$link = apply_filters( 'variable_add_to_cart_url', get_permalink( $product->id ) );
$label = apply_filters( 'variable_add_to_cart_text', __('Select options', 'woocommerce') );
break;
case "grouped" :
$link = apply_filters( 'grouped_add_to_cart_url', get_permalink( $product->id ) );
$label = apply_filters( 'grouped_add_to_cart_text', __('View options', 'woocommerce') );
break;
case "external" :
$link = apply_filters( 'external_add_to_cart_url', get_permalink( $product->id ) );
$label = apply_filters( 'external_add_to_cart_text', __('Read More', 'woocommerce') );
break;
default :
$link = apply_filters( 'add_to_cart_url', esc_url( $product->add_to_cart_url() ) );
$label = apply_filters( 'add_to_cart_text', __('Add to cart', 'woocommerce') );
break;
}
printf('<a href="%s" rel="nofollow" data-product_id="%s" class="add_to_cart_button button product_type_%s">%s</a>', $link, $product->id, $product->product_type, $label);
?>
I’m trying to get variations to display inside the loop so customers can add variable products to their cart from the shop page (please see screenshot below)…
http://cl.ly/image/42401k0X0X2I
I know I need to include the function-
get_available_variations();
And i’m pretty sure this already returns an array, it’s just putting that array into a select dropdown + listing the variations (S,M,L,XL) and having a link to add that variation to the basket.
Cheers!
I found your post while trying to solve the same problem. I finally found…
in
woocommerce-template.php
This works for me in loop/add-to-cart.php
Let me know if this helps 🙂
The variations dropdown template file for single post pages is located here:
woocommercetemplatessingle-productadd-to-cartvariable.php
Which requires the following script to pass the product variable information:
as well as the following hidden field:
I hope that is a start others can help build upon.
I found on Remi Corson’s blog a simple way to do that.
Change the
href
value of the cart button with the following:Example:
With the
get_available_variations();
function is easy to get the variation values. For the product ID, you can useget_the_ID();
function.