add_action( 'woocommerce_after_shop_loop_item_title', 'custom_show_product_cat', 7 );
function custom_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>' );
}
function wpq_after_subcategory( $category ) {
$queried_object = get_queried_object();
if( is_product_category() && $queried_object->parent !== 0 ){
if ( function_exists( 'wpq_get_min_price_per_product_cat' ) ) {
echo 'от ' . wpq_get_min_price_per_product_cat( $category->term_id ) . ' ₽/м2';
}
}
}
add_action( 'woocommerce_after_subcategory', 'wpq_after_subcategory' );
function wpq_get_min_price_per_product_cat( $term_id ) {
global $wpdb;
$sql = "
SELECT MIN( meta_value+0 ) as minprice
FROM {$wpdb->posts}
INNER JOIN {$wpdb->term_relationships} ON ({$wpdb->posts}.ID = {$wpdb->term_relationships}.object_id)
INNER JOIN {$wpdb->postmeta} ON ({$wpdb->posts}.ID = {$wpdb->postmeta}.post_id)
WHERE
( {$wpdb->term_relationships}.term_taxonomy_id IN (%d) )
AND {$wpdb->posts}.post_type = 'product'
AND {$wpdb->posts}.post_status = 'publish'
AND {$wpdb->postmeta}.meta_key = '_price'
";
return $wpdb->get_var( $wpdb->prepare( $sql, $term_id ) );
}
function wpq_after_subcategory( $category ) {
if( function_exists( 'wpq_get_min_price_per_product_cat' ) ) {
printf( "%s pricing starts at %s ", $category->name, wpq_get_min_price_per_product_cat( $category->term_id ) );
}
}
add_action( 'woocommerce_after_subcategory', 'wpq_after_subcategory' );
/**
* Add quantity field on the shop page.
*/
function ace_shop_page_add_quantity_field() {
/** @var WC_Product $product */
$product = wc_get_product( get_the_ID() );
if ( ! $product->is_sold_individually() && 'variable' != $product->get_type() && $product->is_purchasable() ) {
woocommerce_quantity_input( array( 'min_value' => 1, 'max_value' => $product->backorders_allowed() ? '' : $product->get_stock_quantity() ) );
}
}
add_action( 'woocommerce_after_shop_loop_item', 'ace_shop_page_add_quantity_field', 12 );
/**
* Add required JavaScript.
*/
function ace_shop_page_quantity_add_to_cart_handler() {
wc_enqueue_js( '
$(".woocommerce .products").on("click", ".quantity input", function() {
return false;
});
$(".woocommerce .products").on("change input", ".quantity .qty", function() {
var add_to_cart_button = $(this).parents( ".product" ).find(".add_to_cart_button");
// For AJAX add-to-cart actions
add_to_cart_button.attr("data-quantity", $(this).val());
// For non-AJAX add-to-cart actions
add_to_cart_button.attr("href", "?add-to-cart=" + add_to_cart_button.attr("data-product_id") + "&quantity=" + $(this).val());
});
// Trigger on Enter press
$(".woocommerce .products").on("keypress", ".quantity .qty", function(e) {
if ((e.which||e.keyCode) === 13) {
$( this ).parents(".product").find(".add_to_cart_button").trigger("click");
}
});
' );
}
add_action( 'init', 'ace_shop_page_quantity_add_to_cart_handler' );
remove_action( 'woocommerce_after_single_product_summary','woocommerce_output_related_products', 20 );
add_action( 'woocommerce_single_product_summary','woocommerce_output_related_products', 15 );
remove_action( 'woocommerce_after_single_product_summary','woocommerce_upsell_display', 15 );
add_action( 'woocommerce_single_product_summary','woocommerce_upsell_display', 16 );
remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_add_to_cart', 30 );
add_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_add_to_cart', 15 );
[products limit="48" category="petli, ruchki, furnitura, zamki" cat_operator="NOT IN" orderby="rand" paginate="true"]
<?php
$current = absint( max( 1, get_query_var( 'paged' ) ? get_query_var( 'paged' ) : get_query_var( 'page' ) ) );
$args = array(
'post_type' => 'product',
'posts_per_page' => 8,
'paged' => $current,
'order' => 'rand',
'tax_query' => array(
array(
'taxonomy' => 'product_cat',
'field' => 'slug', // Or 'name' or 'term_id'
'terms' => array('hoodies'),
'operator' => 'NOT IN', // Excluded
)
)
);
$query = new WP_Query($args);
?>
<?php if( $query->have_posts() ) : ?>
<?php while( $query->have_posts() ) : $query->the_post(); ?>
<div class="product">
<!-- тут вывод карточки продукта -->
</div>
<?php endwhile; ?>
<nav class="navigation pagination">
<div class="nav-links">
<?php
echo wp_kses_post(
paginate_links( [
'total' => $query->max_num_pages, // количество берем из дефолтной опции запроса
'current' => $current, // текущая страница
] )
);
?>
</div>
</nav>
<?php else: ?>
<div class="post">
<h2><?php _e( 'Posts not found', 'basic' ); ?></h2>
<?php get_search_form(); ?>
</div>
<?php endif; ?>
<?php wp_reset_query(); ?>
function your_theme_widgets_init() {
register_sidebar(
array(
'name' => esc_html__( 'Sidebar Shop', 'your_theme' ),
'id' => 'sidebar-shop',
'description' => esc_html__( 'Sidebar for shop', 'your_theme' ),
'before_widget' => '<section id="%1$s" class="widget %2$s">',
'after_widget' => '</section>',
'before_title' => '<h3 class="widget-title">',
'after_title' => '</h3>',
)
);
}
add_action( 'widgets_init', 'your_theme_widgets_init' );
add_filter( 'woocommerce_shop_loop_subcategory_title', 'add_text_before_cat_title', 15 );
function add_text_before_cat_title( $category ) {
$slug = $category->slug;
if ( $slug === 'decor' ) {
echo 'from 10500 $';
} elseif ( $slug === 'music' ) {
echo 'from 5600 $';
} else {
return;
}
}
add_filter( 'woocommerce_get_price_html', 'cw_change_product_price_display' );
add_filter( 'woocommerce_cart_item_price', 'cw_change_product_price_display' );
function cw_change_product_price_display( $price ) {
// Your additional text in a translatable string
$text = __('от');
// returning the text before the price
return $text . ' ' . $price;
}