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' );
$terms_array = array(
'taxonomy' => 'services', // you can change it according to your taxonomy
'parent' => 0 // If parent => 0 is passed, only top-level terms will be returned
);
$services_terms = get_terms($terms_array);
foreach($services_terms as $service): ?>
<h4><?php echo $service->name; ?></h4>
<?php
$post_args = array(
'posts_per_page' => -1,
'post_type' => 'service', // you can change it according to your custom post type
'tax_query' => array(
array(
'taxonomy' => 'services', // you can change it according to your taxonomy
'field' => 'term_id', // this can be 'term_id', 'slug' & 'name'
'terms' => $service->term_id,
)
)
);
$myposts = get_posts($post_args); ?>
<ul>
<?php foreach ( $myposts as $post ) : setup_postdata( $post ); ?>
<li>
<a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
</li>
<?php endforeach; // Term Post foreach ?>
</ul>
<?php wp_reset_postdata(); ?>
<?php endforeach; // End Term foreach; ?>
$newsLoop = new WP_Query(array(
'posts_per_page' => 10,
'post_type' => 'post',
'orderby' => 'date',
'order' => 'DESC',
'meta_query' => array(
array(
'key' => 'post_delete',
'value' => '0',
'compare' => 'LIKE',
)
),
));
if ( $newsLoop->have_posts() ) : ?>
<div class="news-wrapper">
<?php while ( $newsLoop->have_posts() ) : $newsLoop->the_post();
$post_delete = get_post_meta( $post->ID, 'post_delete' );
?>
<?php if ( !$post_delete ): ?>
<?php get_template_part( 'template-parts/loop', get_post_format() ? : 'video' ); ?>
<?php endif ?>
<?php endwhile;?>
</div>
<?php endif; wp_reset_query(); ?>
$(window).on('resize', function(e){
// Переменная, по которой узнаем запущен слайдер или нет.
var initLib = $('.library-slider').data('init-slider');
if(window.innerWidth < 768){
// Если слайдер не запущен
if(initLib != 1){
// Запускаем слайдер и записываем в data init-slider = 1
$('.library-slider').slick({
arrows: false,
dots: true,
slidesToShow: 3,
slidesToScroll: 1,
responsive: [
{
breakpoint: 576,
settings: {
slidesToShow: 2,
slidesToScroll: 1,
}
},
{
breakpoint: 480,
settings: {
slidesToShow: 1,
slidesToScroll: 1,
}
}
]
}).data({'init-slider': 1});
}
}
// Если десктоп
else {
// Если слайдер запущен
if(initLib == 1){
// Разрушаем слайдер и записываем в data init-slider = 0
$('.library-slider').slick('unslick').data({'init-slider': 0});
}
}
}).trigger('resize')
<?php
$paged = ( get_query_var( 'paged' ) ) ? get_query_var( 'paged' ) : 1;
$args = array(
'post_type' => 'custom_post_type_name',
'posts_per_page' => 10,
'paged' => $paged
);
$loop = new WP_Query( $args );
while ( $loop->have_posts() ) : $loop->the_post();
// CPT content
endwhile;
?>
<div class="pagination">
<?php
$big = 999999999;
echo paginate_links( array(
'base' => str_replace( $big, '%#%', get_pagenum_link( $big ) ),
'format' => '?paged=%#%',
'current' => max( 1, get_query_var('paged') ),
'total' => $loop->max_num_pages,
'prev_text' => '«',
'next_text' => '»'
) );
?>
</div>
<?php wp_reset_postdata(); ?>
/**
* 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' );
<?php
$prod_cat_args = array(
'taxonomy' => 'product_cat',
'hide_empty' => false,
'parent' => 0
);
$woo_categories = get_categories( $prod_cat_args );
?>
<?php foreach ( $woo_categories as $woo_cat ) :
$woo_cat_id = $woo_cat->term_id;
$woo_cat_name = $woo_cat->name;
$woo_cat_slug = $woo_cat->slug;
$woo_cat_descr = $woo_cat->description;
$category_thumbnail_id = get_term_meta($woo_cat_id, 'thumbnail_id', true);
$thumbnail_image_url = wp_get_attachment_url($category_thumbnail_id);
$cat_link = get_term_link( $woo_cat_id, 'product_cat' );
?>
<div class="product-cat-item">
<a href="<?php echo $cat_link ?>"><?php echo $woo_cat_name ?></a>
<?php if ($thumbnail_image_url) : ?>
<img src="<?php echo $thumbnail_image_url ?>" alt="<?php echo $woo_cat_name ?>">
<?php endif; ?>
<p><?php echo $woo_cat_descr ?></p>
</div>
<?php endforeach; ?>
$('.open-modal-btn').on('click', function (e) {
e.preventDefault();
var $content = $(this).parents('.cf7-section').find('.cf7-content').html();//получаем родителя и ищем в нем контент
$('#call-to-action').find('.modal-content-wrapper').html($content); //в модалке ищем место для вставки
var $target = $(this).attr('data-target');
openModal($target);
});