با سلام
دوست عزیز
یه مشکلی که در کد هست اینه که برای وردپرس خوب کار می کنه ولی برای ووکامرس کمی نادرست میشه چون ساختار خروجی ووکامرس باید توش لحاظ بشه که هنوز دوستان هیچگونه راهنمایی در موردش نداشتن
<?php
function exclude_category_home( $query ) { if ( $query->is_home ) { $query->set( 'cat', '-9050,-9166' ); } return $query;}add_filter( 'pre_get_posts', 'exclude_category_home' );?>
این چند تا کد رو پیدا کردم ولی نمیدونم چقدر درست باشند کد اول کل محصولات رو نشون نمیده
add_action( 'pre_get_posts', 'custom_pre_get_posts_query' );
function custom_pre_get_posts_query( $q ) {
if ( ! $q->is_main_query() ) return;
if ( ! $q->is_post_type_archive() ) return;
if ( ! is_admin() && is_shop() ) {
$q->set( 'tax_query', array(array(
'taxonomy' => 'product_cat',
'field' => 'slug',
'terms' => array( 'knives' ), // Don't display products in the knives category on the shop page
'operator' => 'NOT IN'
)));
}
remove_action( 'pre_get_posts', 'custom_pre_get_posts_query' );
}
کد دوم قسمت ساب منو رو نشون نمیده
/* Exclude Category from Shop*/
add_filter( 'get_terms', 'get_subcategory_terms', 9166, 3 );
function get_subcategory_terms( $terms, $taxonomies, $args ) {
$new_terms = array();
// if a product category and on the shop page
if ( in_array( 'product_cat', $taxonomies ) && ! is_admin() && is_shop() ) {
foreach ( $terms as $key => $term ) {
if ( ! in_array( $term->slug, array( 'project1', 'susan' ) ) ) {
$new_terms[] = $term;
}
}
$terms = $new_terms;
}
return $terms;
}
قسمت سوم نوشتن که یه دسته بندی رو حذف می کنه ولی محل قرارگیریش مشخص نبود
.widget_product_categories .cat-item-16 {display:none}
این کدها رو تو قسمت پشتیبانی وردپرس می تونی جستجو کنی و نتایج بیشتری رو ببینی و اگر به نتیجه مناسب رسیدی حتما همینجا منتشر کن که دوستان زیادی مشتاق دیدنش هستن
موفق باشی