function test() {
global $product;
if($product->is_type('variable')) {
$variations = $product->get_available_variations();
echo '<div class="custom-variations-wrapper">';
foreach($variations as $variation) {
if(isset($variation['display_price'])) {
$variation_id = $variation['variation_id'];
$variation_price = $variation['display_price']; // or 'display_regular_price'
echo '<form action="' . esc_url($product->add_to_cart_url()) . '" method="post" enctype="multipart/form-data">';
echo '<div class="variation" data-variation-id="' . esc_attr($variation_id) . '">';
echo '<p class="price">' . sprintf(__('%s'), wc_price($variation_price)) . '</p>';
echo '<input type="hidden" name="product_id" value="' . esc_attr($product->get_id()) . '" />';
echo '<input type="hidden" name="variation_id" value="' . esc_attr($variation_id) . '" />';
foreach($variation['attributes'] as $attribute => $value) {
echo '<input type="hidden" name="' . esc_attr($attribute) . '" value="' . esc_attr($value) . '">';
}
echo '<button type="submit">' . __('В корзину') . '</button>';
echo '</div>';
echo '</form>';
}
}
echo '</div>';
}
}
add_action('woocommerce_after_shop_loop_item', 'test', 20);