add_filter( 'woocommerce_output_related_products_args', 'change_number_of_related_products' );
function change_number_of_related_products( $args ) {
$args['posts_per_page'] = 3; // количество выводимых похожих товаров
$args['columns'] = 3; // количесто столбцов
return $args;
}
global $wp_query;
global $wpdb;
$current_category_id = $wp_query->queried_object->term_id;
$min_price = $wpdb->get_var($wpdb->prepare("SELECT MIN(CAST(m.meta_value AS UNSIGNED INTEGER)) FROM wp_posts p INNER JOIN wp_term_relationships r ON (p.ID = r.object_id) INNER JOIN wp_term_taxonomy t ON (r.term_taxonomy_id = t.term_taxonomy_id) INNER JOIN wp_postmeta m ON (p.ID = m.post_id) WHERE t.term_id = %s AND t.taxonomy = 'product_cat' AND p.post_type = 'product' AND p.post_status = 'publish' AND m.meta_key = '_price'", $current_category_id));
$max_price = $wpdb->get_var($wpdb->prepare("SELECT MAX(CAST(m.meta_value AS UNSIGNED INTEGER)) FROM wp_posts p INNER JOIN wp_term_relationships r ON (p.ID = r.object_id) INNER JOIN wp_term_taxonomy t ON (r.term_taxonomy_id = t.term_taxonomy_id) INNER JOIN wp_postmeta m ON (p.ID = m.post_id) WHERE t.term_id = %s AND t.taxonomy = 'product_cat' AND p.post_type = 'product' AND p.post_status = 'publish' AND m.meta_key = '_price'", $current_category_id));
function woa_add_full_slider() { ?>
<?php
if ( is_home() ) {
echo do_shortcode("[huge_it_slider id=2 percentwidth=100 restrict_to_home ]");
}
?>
function search_by_title_only( $search, &$wp_query )
{
global $wpdb;
$q = $wp_query->query_vars;
$search = '';
$and = '';
foreach ( (array) $q['search_terms'] as $term ) {
$search .= "{$and}($wpdb->posts.post_title LIKE '%{$term}%')";
$and = ' AND ';
}
if ( ! empty( $search ) ) {
$search = " AND ({$search}) ";
}
return $search;
}
add_filter( 'posts_search', 'search_by_title_only', 500, 2 );
// удаляем кнопку "В корзину" если нужно
add_filter('woocommerce_is_purchasable', 'remove_add_to_cart_button');
function remove_add_to_cart_button($purchaseable_product, $product) {
return ($product->is_in_stock() ? false : $purchaseable_product);
}
//выводим надпись "Нет в наличии"
add_filter( 'woocommerce_get_availability', 'check_availability', 1, 2);
function check_availability( $availability, $product ) {
if ( !$product->is_in_stock() ) {
$availability['availability'] = 'Нет в наличии';
}
return $availability;
}
$prod_cat_args = array(
'taxonomy' => 'product_cat',
'orderby' => 'id', // здесь по какому полю сортировать
'hide_empty' => false, // скрывать категории без товаров или нет
'parent' => 0 // id родительской категории
);
$woo_categories = get_categories( $prod_cat_args );
foreach ( $woo_categories as $woo_cat ) {
$woo_cat_id = $woo_cat->term_id; //category ID
$woo_cat_name = $woo_cat->name; //category name
$woo_cat_slug = $woo_cat->slug; //category slug
echo '<div class="main-cat-item">';
$category_thumbnail_id = get_woocommerce_term_meta($woo_cat_id, 'thumbnail_id', true);
$thumbnail_image_url = wp_get_attachment_url($category_thumbnail_id);
echo '<img src="' . $thumbnail_image_url . '"/>';
echo '<h2>';
echo '<a href="' . get_term_link( $woo_cat_id, 'product_cat' ) . '">' . $woo_cat_name . '</a>;
echo '</h2>';
echo "</div>\n";
}
SCSS:
.main-cat-item {
padding: 1em;
position: relative;
h2 {
font-size: 2em;
position: absolute;
bottom: 0;
right: 0;
padding: 1.5em 1.5em;
text-shadow: 0 1px 8px black;
a {
color: white;
}
}
}