I have manage to get product variations to display on the shop page using the code below:
/**
* Replace add to cart button in the loop.
*/
function iconic_change_loop_add_to_cart() {
remove_action( 'woocommerce_after_shop_loop_item', 'woocommerce_template_loop_add_to_cart', 10 );
add_action( 'init', 'iconic_change_loop_add_to_cart', 10 );
function iconic_loop_variation_add_to_cart_button() {
global $product;
?>
<div class="woocommerce-variation-add-to-cart variations_button">
<button type="submit" class="single_add_to_cart_button button"><?php echo esc_html( $product->single_add_to_cart_text() ); ?></button>
<input type="hidden" name="add-to-cart" value="<?php echo absint( $product->get_id() ); ?>" />
<input type="hidden" name="product_id" value="<?php echo absint( $product->get_id() ); ?>" />
<input type="hidden" name="variation_id" class="variation_id" value="0" />
</div>
<?php
}
The shop page looks like this currently:
However, I have two issues I require help with:
Issue 1: I want to style the variations (move it to the center and create some spacing). However, I noticed that the whole object is the same as variations found in the main product page, so if I change the css there, it will affect the other. Is there a way I can inject my own class for products found in shop and category to help create that seperation?
Issue 2: It would be good to add a custom button "Quick Shop" where when the user selects it, then it will reveal the variations, quantity and add to cart button. Also the "Quick shop" button will change to "hide" and if selected, will hide the variations, quantity and add to cart. This is to save space.
Any help will be appreciated.
Thank you