Answer the question
In order to leave comments, you need to log in
"Adventures of Dunno in Wordpress", which does not understand - Why is the product added to the cart when choosing a category?
If you want to read only on the case, the water ends after the heading: THE ESSENCE OF THE QUESTION.
Hello advanced developers! I'm not speaking out of laziness, but out of stupidity. I searched everything, but my mind is not able to understand what is happening ( although I am sure that everything is very simple ).
I can only hope for the literacy of the users of this site.
I am making a website (yes, yes, you are not mistaken the 1st first site)).
ESSENCE OF THE QUESTION
Task
Displaying goods in a list and tiles, with the ability to switch the option for displaying goods.
Solution The
solution was found here
What did I do from the source
1. Copy file from "/wp-content/plugins/woocommerce/templates/content-product.php" to "/ChildTheme/woocommerce/content-product.php"
Created file "/ChildTheme/woocommerce/content-tables.php" and copied the following code into it:
<?php
/**
* Шаблон табличного отображения товаров в категории
*/
if (!defined('ABSPATH')) {
exit; // Exit if accessed directly
}
global $product;
// Ensure visibility
if (empty($product) || !$product->is_visible()) {
return;
}
if (stripos(woocommerce_get_product_thumbnail(), 'placeholder.png') !== FALSE) {
$styleImage = 'product-table-image-no';
} else {
$styleImage = 'product-table-image';
}
?>
<tr class="productDescription">
<td class="<?php echo $styleImage; ?>"><?php echo woocommerce_get_product_thumbnail(); ?></td>
<td class="product-table-title"><a href="<?php the_permalink() ?>" ><?php the_title(); ?></a></td>
<!-- <td class="product-table-manufactur"><?php echo ($product->get_attribute('manufacture')); ?></td> -->
<td class="product-table-price"><?php do_action('woocommerce_after_shop_loop_item_title'); ?></td>
<td class="product-table-button"><?php do_action('woocommerce_after_shop_loop_item'); ?></td>
</tr>
<?php
/**
* The Template for displaying product archives, including the main shop page which is a post type archive
*
* This template can be overridden by copying it to yourtheme/woocommerce/archive-product.php.
*
* HOWEVER, on occasion WooCommerce will need to update template files and you
* (the theme developer) will need to copy the new files to your theme to
* maintain compatibility. We try to do this as little as possible, but it does
* happen. When this occurs the version of the template file will be bumped and
* the readme will list any important changes.
*
* @see https://docs.woocommerce.com/document/template-structure/
* @author WooThemes
* @package WooCommerce/Templates
* @version 2.0.0
*/
if (!defined('ABSPATH')) {
exit; // Exit if accessed directly
}
get_header('shop');
?>
<?php
/**
* woocommerce_before_main_content hook.
*
* @hooked woocommerce_output_content_wrapper - 10 (outputs opening divs for the content)
* @hooked woocommerce_breadcrumb - 20
*/
do_action('woocommerce_before_main_content');
?>
<?php if (apply_filters('woocommerce_show_page_title', true)) : ?>
<h1 class="page-title"><?php woocommerce_page_title(); ?></h1>
<?php endif; ?>
<?php
/**
* woocommerce_archive_description hook.
*
* @hooked woocommerce_taxonomy_archive_description - 10
* @hooked woocommerce_product_archive_description - 10
*/
do_action('woocommerce_archive_description');
?>
<?php if (have_posts()) : ?>
<?php
/**
* woocommerce_before_shop_loop hook.
*
* @hooked woocommerce_result_count - 20
* @hooked woocommerce_catalog_ordering - 30
*/
do_action('woocommerce_before_shop_loop');
?>
<div class="templateBlockSelector">
<a href="<?php echo add_query_arg(array('cat_templete' => 'list')); ?>"><i class="fa fa-list fa-2x" aria-hidden="true"></i></a>
<a href="<?php echo add_query_arg(array('cat_templete' => 'table')); ?>"><i class="fa fa-table fa-2x" aria-hidden="true"></i></a>
</div>
<?php woocommerce_product_loop_start(); ?>
<?php woocommerce_product_subcategories(); ?>
<?php
global $VIEW_TEMPLATE;
?>
<?php if ($VIEW_TEMPLATE == 'table') { ?>
<?php while (have_posts()) : the_post(); ?>
<?php wc_get_template_part('content', 'product'); ?>
<?php endwhile; // end of the loop. ?>
<?php } else { ?>
<table class="productTemplateTables">
<?php while (have_posts()) : the_post(); ?>
<?php wc_get_template_part('content', 'tables'); ?>
<?php endwhile; // end of the loop. ?>
</table>
<?php } ?>
<?php woocommerce_product_loop_end(); ?>
<?php
/**
* woocommerce_after_shop_loop hook.
*
* @hooked woocommerce_pagination - 10
*/
remove_action('woocommerce_after_shop_loop', 'woocommerce_pagination', 10);
do_action('woocommerce_after_shop_loop');
?>
<?php elseif (!woocommerce_product_subcategories(array('before' => woocommerce_product_loop_start(false), 'after' => woocommerce_product_loop_end(false)))) : ?>
<?php wc_get_template('loop/no-products-found.php'); ?>
<?php endif; ?>
<?php
/**
* woocommerce_after_main_content hook.
*
* @hooked woocommerce_output_content_wrapper_end - 10 (outputs closing divs for the content)
*/
do_action('woocommerce_after_main_content');
?>
<?php
/**
* woocommerce_sidebar hook.
*
* @hooked woocommerce_get_sidebar - 10
*/
do_action('woocommerce_sidebar');
?>
<?php get_footer('shop'); ?>
add_action('woocommerce_before_shop_loop', 'setTempleteCategory');
/**
* Устанавливает режим просмотра категорий товаров
* @global type $VIEW_TEMPLATE
*/
function setTempleteCategory() {
global $VIEW_TEMPLATE;
if (isset($_REQUEST['cat_templete'])) {
if ($_REQUEST['cat_templete'] == 'list') {
$VIEW_TEMPLATE = 'list';
setcookie("view_template_product", "", time() - 3600);
setcookie('view_template_product', 'list', time() + 60 * 60 * 24 * 30);
} elseif ($_REQUEST['cat_templete'] == 'table') {
$VIEW_TEMPLATE = 'table';
setcookie("view_template_product", "", time() - 3600);
setcookie('view_template_product', 'table', time() + 60 * 60 * 24 * 30);
} else {
$VIEW_TEMPLATE = 'table';
}
} else {
if (isset($_COOKIE['view_template_product'])) {
if ($_COOKIE['view_template_product'] == 'list') {
$VIEW_TEMPLATE = 'list';
} elseif ($_COOKIE['view_template_product'] == 'table') {
$VIEW_TEMPLATE = 'table';
}
} else {
$VIEW_TEMPLATE = 'table';
}
}
}
setcookie("view_template_product", "", time() - 3600);
setcookie('view_template_product', 'list', time() + 60 * 60 * 24 * 30);
setcookie("view_template_product", "", time() - 3600);
setcookie('view_template_product', 'table', time() + 60 * 60 * 24 * 30);
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question