add_action( 'template_redirect', 'add_product_to_cart' );
function add_product_to_cart() {
if ( ! is_admin() ) {
$articles = array(157,158,159,160);
$found = false;
// check if product already in cart
if ( sizeof( WC()->cart->get_cart() ) > 0 ) {
foreach ( WC()->cart->get_cart() as $cart_item_key => $values ) {
$_product = $values['data'];
if (($key = array_search($_product->id, $articles)) !== false)
unset($articles[$key]);
}
// if product not found, add it
if ( count($articles) > 0 ) {
foreach ($articles as $article) {
WC()->cart->add_to_cart($article);
}
}
} else {
// if no products in cart, add it
foreach ($articles as $article) {
WC()->cart->add_to_cart( $article );
}
}
}
}
// отключение сайдбара
remove_action( 'woocommerce_sidebar', 'woocommerce_get_sidebar', 10 );
// отключить хлебные крошки
remove_action( 'woocommerce_before_main_content', 'woocommerce_breadcrumb', 20 );
// основной контейнер
remove_action( 'woocommerce_before_main_content', 'woocommerce_output_content_wrapper', 10);
add_action( 'woocommerce_before_main_content', 'storm_output_content_wrapper_start', 10 );
function storm_output_content_wrapper_start() {
?>
<div class="container-1000">
<?php
}
remove_action( 'woocommerce_after_main_content', 'woocommerce_output_content_wrapper_end', 10 );
add_action( 'woocommerce_after_main_content', 'storm_output_content_wrapper_end', 40 );
function storm_output_content_wrapper_end() {
?>
</div><!-- container-1000 -->
<?php
}
add_action( 'woocommerce_before_main_content', 'storm_archive_output_content_wrapper_start', 15 );
function storm_archive_output_content_wrapper_start() {
if( is_shop() || is_product_category() ) {
?>
<div class="category-content">
<?php
}
}
add_action( 'woocommerce_before_main_content', 'storm_catalog_wrapper_start', 20 );
function storm_catalog_wrapper_start() {
if( is_shop() || is_product_category() ) {
?>
<div class="catalog-list-wrapper">
<?php
}
}
//вывод хлебных крошек на странице архива
add_action( 'woocommerce_before_main_content', 'storm_catalog_breadcrumbs', 25 );
function storm_catalog_breadcrumbs() {
if( is_shop() || is_product_category() ) {
?>
<div class="breadcrumbs">
<?php woocommerce_breadcrumb() ?>
</div>
<?php
}
}
// Изменить стрелки пагинации
add_filter( 'woocommerce_pagination_args', 'custom_woo_pagination' );
function custom_woo_pagination( $args ) {
$args['prev_text'] = '<span class="fa fa-angle-left"></span><span class="sr-only">Previous page</span>';
$args['next_text'] = '<span class="fa fa-angle-right"></span><span class="sr-only">Next page</span>';
return $args;
}
// вывод пагинации
remove_action( 'woocommerce_after_shop_loop', 'woocommerce_pagination', 10 );
add_action('woocommerce_after_shop_loop', 'storm_pagination', 10);
function storm_pagination() {
?>
<div class="pagination-wrapper">
<?php woocommerce_pagination(); ?>
</div>
<?php
}
add_action( 'woocommerce_after_main_content', 'storm_catalog_wrapper_end', 15 );
function storm_catalog_wrapper_end() {
if( is_shop() || is_product_category() ) {
?>
</div> <!-- catalog-list-wrapper -->
<?php
}
}
// Вывод сайдбара на странице архива
add_action( 'woocommerce_after_main_content', 'storm_archive_get_sidebar', 20 );
function storm_archive_get_sidebar() {
if( is_shop() || is_product_category() ) {
woocommerce_get_sidebar();
}
}
add_action( 'woocommerce_after_main_content', 'storm_archive_output_content_wrapper_end', 30 );
function storm_archive_output_content_wrapper_end() {
if( is_shop() || is_product_category() ) {
?>
</div><!-- category-content -->
<?php
}
}
// Move WooCommerce subcategory list items into heir own <ul> separate from the product <ul>
add_action( 'init', 'move_subcat_lis' );
function move_subcat_lis() {
// Remove the subcat <li>s from the old location.
remove_filter( 'woocommerce_product_loop_start', 'woocommerce_maybe_show_product_subcategories' );
add_action( 'woocommerce_before_shop_loop', 'msc_product_loop_start', 40 );
add_action( 'woocommerce_before_shop_loop', 'msc_maybe_show_product_subcategories', 50 );
add_action( 'woocommerce_before_shop_loop', 'msc_product_loop_end', 60 );
}
//Conditonally start the product loop with a <ul> contaner if subcats exist.
function msc_product_loop_start() {
$subcategories = woocommerce_maybe_show_product_subcategories();
if ( $subcategories ) {
echo '<ul class="archive-category-wrapper">';
}
}
//Print the subcat <li>s in our new location.
function msc_maybe_show_product_subcategories() {
echo woocommerce_maybe_show_product_subcategories();
}
//Conditonally end the product loop with a </ul> if subcats exist.
function msc_product_loop_end() {
$subcategories = woocommerce_maybe_show_product_subcategories();
if ( $subcategories ) {
echo '</ul>';
}
}
// отключение сайдбара
remove_action( 'woocommerce_sidebar', 'woocommerce_get_sidebar', 10 );
// отключить хлебные крошки
remove_action( 'woocommerce_before_main_content', 'woocommerce_breadcrumb', 20 );
// добавить основной контейнер
remove_action( 'woocommerce_before_main_content', 'woocommerce_output_content_wrapper', 10);
add_action( 'woocommerce_before_main_content', 'storm_output_content_wrapper_start', 10 );
function storm_output_content_wrapper_start() {
?>
<div class="container-1000">
<?php
}
// закрыть основной контейнер
remove_action( 'woocommerce_after_main_content', 'woocommerce_output_content_wrapper_end', 10 );
add_action( 'woocommerce_after_main_content', 'storm_output_content_wrapper_end', 40 );
function storm_output_content_wrapper_end() {
?>
</div><!-- container-1000 -->
<?php
}
add_action( 'woocommerce_before_main_content', 'storm_archive_output_content_wrapper_start', 15 );
function storm_archive_output_content_wrapper_start() {
if( is_shop() || is_product_category() ) {
?>
<div class="category-content">
<?php
}
}
add_action( 'woocommerce_before_main_content', 'storm_catalog_wrapper_start', 20 );
function storm_catalog_wrapper_start() {
if( is_shop() || is_product_category() ) {
?>
<div class="catalog-list-wrapper">
<?php
}
}
//вывод хлебных крошек на странице архива
add_action( 'woocommerce_before_main_content', 'storm_catalog_breadcrumbs', 25 );
function storm_catalog_breadcrumbs() {
if( is_shop() || is_product_category() ) {
?>
<div class="breadcrumbs">
<?php woocommerce_breadcrumb() ?>
</div>
<?php
}
}
// вывод сортировки и кнопки переключателя фильтра
remove_action( 'woocommerce_before_shop_loop', 'woocommerce_catalog_ordering', 30 );
add_action('woocommerce_before_shop_loop', 'storm_catalog_ordering', 30);
function storm_catalog_ordering() {
?>
<div class="catalog-sorting-wrapper">
<button type="button" class="fixed-toggle filter-toggle" id="filter-toggle"><i class="fa fa-filter"></i><?php _e('Filter','storm-store') ?></button>
<div class="product-sorting">
<span class="product-sorting-label"><?php _e('Сортировать:','storm-store') ?></span>
<div class="select-wrapper">
<?php woocommerce_catalog_ordering() ?>
</div>
</div>
</div>
<?php
}
// Изменить стрелки пагинации
add_filter( 'woocommerce_pagination_args', 'custom_woo_pagination' );
function custom_woo_pagination( $args ) {
$args['prev_text'] = '<span class="fa fa-angle-left"></span><span class="sr-only">Previous page</span>';
$args['next_text'] = '<span class="fa fa-angle-right"></span><span class="sr-only">Next page</span>';
return $args;
}
// вывод пагинации
remove_action( 'woocommerce_after_shop_loop', 'woocommerce_pagination', 10 );
add_action('woocommerce_after_shop_loop', 'storm_pagination', 10);
function storm_pagination() {
?>
<div class="pagination-wrapper">
<?php woocommerce_pagination(); ?>
</div>
<?php
}
add_action( 'woocommerce_after_main_content', 'storm_catalog_wrapper_end', 15 );
function storm_catalog_wrapper_end() {
if( is_shop() || is_product_category() ) {
?>
</div> <!-- catalog-list-wrapper -->
<?php
}
}
add_action( 'woocommerce_after_main_content', 'storm_archive_output_content_wrapper_end', 30 );
function storm_archive_output_content_wrapper_end() {
if( is_shop() || is_product_category() ) {
?>
</div><!-- category-content -->
<?php
}
}
// Добавить класс к обертке с товарами
add_filter('woocommerce_product_loop_start', 'mytheme_product_loop_start');
function mytheme_product_loop_start() {
?>
<ul class="card-group products columns-<?php echo esc_attr( wc_get_loop_prop( 'columns' ) ); ?>">
<?php
}
// Вывод категории в карточках товара
add_action( 'woocommerce_before_shop_loop_item_title', 'storm_show_product_cat', 30 );
function storm_show_product_cat() {
global $product;
echo wc_get_product_category_list( $product->get_id(), ', ', '<div class="product-cat">' . _n( 'Category:', 'Categories:', count( $product->get_category_ids() ), 'woocommerce' ) . ' ', '</div>' );
}
do_action( 'woocommerce_before_shop_loop_item' );
woocommerce_template_loop_product_link_open()
if ( ! function_exists( 'woocommerce_template_loop_product_link_open' ) ) {
/**
* Insert the opening anchor tag for products in the loop.
*/
function woocommerce_template_loop_product_link_open() {
global $product;
$link = apply_filters( 'woocommerce_loop_product_link', get_the_permalink(), $product );
echo '<a href="' . esc_url( $link ) . '" class="woocommerce-LoopProduct-link woocommerce-loop-product__link">';
}
}
remove_action( 'woocommerce_before_shop_loop_item', 'woocommerce_template_loop_product_link_open', 10 );
add_action( 'woocommerce_before_shop_loop_item', 'custom_open_link', 10 );
function custom_open_link() {
?>
<a href="<?php the_permalink() ?>">
<?php
}
/**
* Display category image on category archive
*/
add_action( 'woocommerce_archive_description', 'woocommerce_category_image', 2 );
function woocommerce_category_image() {
if ( is_product_category() ){
global $wp_query;
$cat = $wp_query->get_queried_object();
$thumbnail_id = get_term_meta( $cat->term_id, 'thumbnail_id', true );
$image = wp_get_attachment_url( $thumbnail_id );
if ( $image ) {
echo '<img src="' . $image . '" alt="' . $cat->name . '" />';
}
}
}
// Вывод кнопки ВЕРНУТЬСЯ В КАТАЛОГ на странице товара
add_action( 'woocommerce_before_main_content', 'storm_add_back_to_btn', 25 );
function storm_add_back_to_btn() {
if( is_product() ) {
?>
<div class="back-to-catalog">
<a href="<?php echo wc_get_page_permalink( 'shop' ); ?>" class="back-to-btn"><i class="fa fa-long-arrow-left"></i><?php _e('Back to catalog', 'storm-store') ?></a>
</div>
<?php
}
}