https://cdnjs.cloudflare.com/ajax/libs/crypto-js/4.0.0/core.min.js
https://cdnjs.cloudflare.com/ajax/libs/crypto-js/4.0.0/x64-core.min.js
https://cdnjs.cloudflare.com/ajax/libs/crypto-js/4.0.0/sha3.min.js
https://cdnjs.cloudflare.com/ajax/libs/crypto-js/4.0.0/crypto-js.min.js
<?php
function add_to_id()
{
if(isset($_POST['variation_id']) && !empty($_POST['variation_id']))
{
$value = intval($_POST['variation_id']);
}
elseif(isset($_POST['product_id']) && !empty($_POST['product_id']))
{
$value = intval($_POST['product_id']);
}
else
{
wp_send_json_error();
}
$data = [];
if(isset($_COOKIE['wp_id']))
{
foreach(explode(',', $_COOKIE['wp_id']) as $val)
{
if(!empty($val))
{
$data[$val] = $val;
}
}
}
//удаляем value если оно было среди значение в cookie
if(isset($data[$value]))
{
unset($data[$value]);
}
else
{
$data[$value] = $value;
}
setcookie("wp_id", implode(',', $data), time() + 86400 * 30, COOKIEPATH, COOKIE_DOMAIN);
//если человек кликнул - $data: 1, а при повторном клике (по той же иконке) - $data: 0
wp_send_json_success(count($data));
}
$id = "1,2,3,4,5"; или $id = "1|2|3|4|5";
<?php
/**
* Template Name: Бла бла бла
*/
get_header();
$args = [
'post_type' => 'product',
'tax_query' => [
[
'taxonomy' => 'product_cat',
'field' => 'name',
'terms' => 'Tem Name',
],
],
'posts_per_page' => - 1,
];
global $wp_query;
$wp_query = new WP_Query( $args );
if ( $wp_query->have_posts() ) :
woocommerce_product_loop_start();
?>
<?php while ( $wp_query->have_posts() ) : $wp_query->the_post();
?>
<?php wc_get_template_part( 'content', 'product' ); ?>
<?php endwhile;
woocommerce_product_loop_end();
?>
<?php else : ?>
<div>Товаров не найдено</div>
<?php endif;
get_footer();