Cannot place add to cart woocommerce button inside a custom div class in product categories

Viewed 83

I have ratings and add to cart button next to each other. But I need to place add to cart button in the parent of ratings div class. In order to align the button to the right using flex css. Because I have

enter image description here

I did the following with no result

echo '<div class ="mywrapper">'. woocommerce_template_loop_add_to_cart() . '<div class="star-rating"><span style="width:'.( ( $average / 5 ) * 100 ) . '%"><strong itemprop="ratingValue" class="rating">'.$average.'</strong> '.__( 'out of 5', 'woocommerce' );
echo '</div></div>';

echo '<div class ="mywrapper">'. <? php echo woocommerce_template_loop_add_to_cart() ?> . '<div class="star-rating"><span style="width:'.( ( $average / 5 ) * 100 ) . '%"><strong itemprop="ratingValue" class="rating">'.$average.'</strong> '.__( 'out of 5', 'woocommerce' );
echo '</div></div>';

The add to cart always is outside class "mywrapper"

enter image description here

While I need to have the following

enter image description here

Is there any way to achieve this? thank you

1 Answers

Well I think I did it by doing the following

echo '<div class ="mywrapper">'. '<div class="star-rating"><span style="width:'.( ( $average / 5 ) * 100 ) . '%"><strong itemprop="ratingValue" class="rating">'.$average.'</strong> '.__( 'out of 5', 'woocommerce' );
echo '</div>';
echo woocommerce_template_loop_add_to_cart(); 
echo '</div>';

instead of one echo

Related