Woocommerce 카테고리에서 제품 개수가 0 인 경우 사용자 정의 페이지를 리디렉션해야합니다. 친절하게 도와주세요
분류 용어 페이지 중 하나를 통해 제품 범주에 액세스한다고 가정합니다.
이것을 functions.php
파일에 추가 하십시오. SOME_PATH . '/some-custom-file.php';
로드하려는 템플릿의 경로로 바꾸십시오 .
add_filter( 'template_include', 'redirect_on_empty_product_category' );
function redirect_on_empty_product_category( $template ){
if ( ( $taxonomy_id = get_query_var( 'taxonomy' ) ) && ( $term_id = get_query_var( 'term' ) ) && is_tax( $taxonomy_id, $term_id ) ){
$term = get_term_by( 'slug', $term_id, $taxonomy_id );
if ( $term->count === 0 ){
$page_url = get_permalink($some_post_id);
echo sprintf('<script type="text/javascript"> window.location = "%s" </script>', $page_url);
}
}
return $template;
}
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다