A lot of images break the plugin’s behavior
-
Hello. Tell me, I slightly improved the output of the image on the category page. In other words, I brought out 4 photos instead of one and connected a slider to them. But the problem is that the plugin did the same thing. I understand that I am to blame for this, but I would like to ask you – is it possible to solve this problem and how? I want your plugin to display the standard output of a single product image.
The page I need help with: [log in to see the link]
-
This is the code I used.
function woocommerce_feature_gallery() { global $product; $attachment_ids = $product->get_gallery_attachment_ids(); $count = 0; echo '<div class="brazzers-wrapper">'; echo '<i class="Brazzers-flaticon"><img src="https://ganzola.ru/wp-content/uploads/2020/09/swipe.png"></i>'; echo '<div class="Brazzers">'; echo '<div class="Brazzers__page"> <div class="Brazzers__image-wrapper">'; echo get_the_post_thumbnail( $post->ID, 'shop_single', $attributes ); echo '</div> <div class="point-line"></div> </div>'; foreach( $attachment_ids as $attachment_id ) { $count ++; if ($count < 4) { echo '<div class="Brazzers__page"> <div class="Brazzers__image-wrapper">'; echo wp_get_attachment_image( $attachment_id, 'shop_catalog' ); echo '</div> <div class="point-line"></div> </div>'; } } echo '</div>'; echo '</div>'; } remove_action( 'woocommerce_before_shop_loop_item_title', 'woocommerce_template_loop_product_thumbnail', 10 ); //Убираем вывод одиночного изображения add_action( 'woocommerce_shop_loop_item_title', 'woocommerce_feature_gallery', 8 );
I think I should delete my woocommerce_feature_gallery and display woocommerce_template_loop_product_thumbnail on the product card pages. I don’t quite understand how to do this. Can you help?))
- This reply was modified 4 years, 2 months ago by ilyapokrov.
- This reply was modified 4 years, 2 months ago by ilyapokrov.
Hello. Perhaps I do not understand you correctly. Please describe in more detail what you want. This is not a plugin element (featured products and upsales).
I improved the display of product cards on archive pages (categories). Now, instead of one image, my site displays four images.
I did it using this code:
function woocommerce_feature_gallery() { global $product; $attachment_ids = $product->get_gallery_attachment_ids(); $count = 0; echo '<div class="brazzers-wrapper">'; echo '<i class="Brazzers-flaticon"><img src="https://ganzola.ru/wp-content/uploads/2020/09/swipe.png"></i>'; echo '<div class="Brazzers">'; echo '<div class="Brazzers__page"> <div class="Brazzers__image-wrapper">'; echo get_the_post_thumbnail( $post->ID, 'shop_single', $attributes ); echo '</div> <div class="point-line"></div> </div>'; foreach( $attachment_ids as $attachment_id ) { $count ++; if ($count < 4) { echo '<div class="Brazzers__page"> <div class="Brazzers__image-wrapper">'; echo wp_get_attachment_image( $attachment_id, 'shop_catalog' ); echo '</div> <div class="point-line"></div> </div>'; } } echo '</div>'; echo '</div>'; } remove_action( 'woocommerce_before_shop_loop_item_title', 'woocommerce_template_loop_product_thumbnail', 10 ); //Убираем вывод одиночного изображения add_action( 'woocommerce_shop_loop_item_title', 'woocommerce_feature_gallery', 8 );
The problem is this: Related products inherited this code. And now on the pages of a single product, in the place where related products are displayed, the products are displayed incorrectly.
How can I make my code changes only apply to archive pages (categories)? Take a look at the link.
Hello, @ilyapokrov
I understood the problem. Again the problem has nothing to do with the plugin. The plugin always inherits the product selection.
Let’s move on to the solution …
You can use the Woocommerce hooks is_product_category () and is_shop (). That is, your work that you have done in relation to the display of goods, you can apply only to archives (categories) and the main page of the store. Set the condition … it looks like this:
function woocommerce_feature_gallery() { if ( is_product_category() ) { // check for category // If you want to apply your changes also on the main page of the store, use the condition "if ( is_product_category() || is_shop )" instead "if ( is_product_category() )" global $product; $attachment_ids = $product->get_gallery_attachment_ids(); $count = 0; echo '<div class="brazzers-wrapper">'; echo '<i class="Brazzers-flaticon"><img src="https://ganzola.ru/wp-content/uploads/2020/09/swipe.png"></i>'; echo '<div class="Brazzers">'; echo '<div class="Brazzers__page"> <div class="Brazzers__image-wrapper">'; echo get_the_post_thumbnail($post->ID, 'shop_single', $attributes); echo '</div> <div class="point-line"></div> </div>'; foreach ($attachment_ids as $attachment_id) { $count++; if ($count < 4) { echo '<div class="Brazzers__page"> <div class="Brazzers__image-wrapper">'; echo wp_get_attachment_image($attachment_id, 'shop_catalog'); echo '</div> <div class="point-line"></div> </div>'; } } echo '</div>'; echo '</div>'; } } remove_action('woocommerce_before_shop_loop_item_title', 'woocommerce_template_loop_product_thumbnail', 10); //Убираем вывод одиночного изображения add_action('woocommerce_shop_loop_item_title', 'woocommerce_feature_gallery', 8);
Be sure to write to us if it worked or not.
———–
Еще по-моему мы на русском разговариваем, у Вас же сайт на русском и ник. Быть может так проще будет)
Действительно, на русском будет проще))
Спасибо за предложенное решение. Я прекрасно понимаю, что эта проблема возникла не из-за плагина, а из-за моих “отличных” знаний кода.
Ваше предложенное решение практически помогло. Теперь не отображается вообще вывод картинки в похожих товарах. Но мы в правильном направлениии и на пути решения этой задачи)
Где тут допущена оплошность?
remove_action и add_action – вот в чем проблема. Они должны работать в этом условии. Пробовал положить их перед последними двумя закрывающимися }}, но это ломает структуру. Видимо я нарушаю синтаксис.
- This reply was modified 4 years, 2 months ago by ilyapokrov.
Попробуйте вот так
function woocommerce_feature_gallery() { if ( is_product_category() ) { // check for category // If you want to apply your changes also on the main page of the store, use the condition "if ( is_product_category() || is_shop )" instead "if ( is_product_category() )" global $product; $attachment_ids = $product->get_gallery_attachment_ids(); $count = 0; echo '<div class="brazzers-wrapper">'; echo '<i class="Brazzers-flaticon"><img src="https://ganzola.ru/wp-content/uploads/2020/09/swipe.png"></i>'; echo '<div class="Brazzers">'; echo '<div class="Brazzers__page"> <div class="Brazzers__image-wrapper">'; echo get_the_post_thumbnail($post->ID, 'shop_single', $attributes); echo '</div> <div class="point-line"></div> </div>'; foreach ($attachment_ids as $attachment_id) { $count++; if ($count < 4) { echo '<div class="Brazzers__page"> <div class="Brazzers__image-wrapper">'; echo wp_get_attachment_image($attachment_id, 'shop_catalog'); echo '</div> <div class="point-line"></div> </div>'; } } echo '</div>'; echo '</div>'; }else{ echo woocommerce_template_loop_product_thumbnail(); } } remove_action('woocommerce_before_shop_loop_item_title', 'woocommerce_template_loop_product_thumbnail', 10); //Убираем вывод одиночного изображения add_action('woocommerce_shop_loop_item_title', 'woocommerce_feature_gallery', 8);
Да не за что. Я думаю надо убрать “echo” в строчке
echo woocommerce_template_loop_product_thumbnail();
уберите и проверьте, так будет правильней.
Если вам понравился наш плагин, можете оставить отзыв тут, нам это очень поможет и мотивирует дальше развивать плагин.
Помечаю тему как решенную. Обращайтесь, если будут проблемы с плагином.
- The topic ‘A lot of images break the plugin’s behavior’ is closed to new replies.