Я создаю магазин на WooCommerce и не могу понять одну вещь. Некоторые изделия имеют вариации цвета и размера. Я установил плагин Variation Swatches for WooCommerce и смог отобразить цвета и размеры на одной странице продукта. Однако мне нужно отображать только цвета в списке продуктов.
Я нашел решение для создания функции добавления в корзину прямо из списка продуктов. Он отображает доступные цвета и размеры для каждого продукта, так что пользователь может выбрать их и добавить продукт в корзину, даже не посещая страницу с отдельным продуктом. Это выглядит так:
That's all nice, but I don't want user to be able to add product to cart from products list. I only want to display available colours (without sizes) on the products list. And below colours rings I want to display a regular woocommerce Select options button that user will click to go to single-product page and add it to cart from there after selecting colour and size variation.
Here is the code for the functionality that I already have. It's from functions.php file:
/**
* 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( 'woocommerce_after_shop_loop_item', 'iconic_template_loop_add_to_cart', 10 );
}
add_action( 'init', 'iconic_change_loop_add_to_cart', 10 );
/**
* Use single add to cart button for variable products.
*/
function iconic_template_loop_add_to_cart() {
global $product;
if ( ! $product->is_type( 'variable' ) ) {
woocommerce_template_loop_add_to_cart();
return;
}
remove_action( 'woocommerce_single_variation', 'woocommerce_single_variation_add_to_cart_button', 20 );
add_action( 'woocommerce_single_variation', 'iconic_loop_variation_add_to_cart_button', 20 );
woocommerce_template_single_add_to_cart();
}
/**
* Customise variable add to cart button for loop.
*
* Remove qty selector and simplify.
*/
function iconic_loop_variation_add_to_cart_button() {
global $product;
?>
single_add_to_cart_text ()); ?>