0964.058.102

SHOW DANH MỤC CON + LINK QUA LIST DANH SÁCH HÀNG HÓA TRONG FLATSOME

// HIỆN THỊ LIST SUB CATEGORY
function list_sub_product_category(){
if( !is_product() ): ;?>
<div class="list_sub_product_category">
<?php 	  
if ( is_product_category() ) {

    $term_id  = get_queried_object_id();
    $taxonomy = 'product_cat';

    // Get subcategories of the current category
    $terms    = get_terms([
        'taxonomy'    => $taxonomy,
        'hide_empty'  => true,
        'parent'      => get_queried_object_id()
    ]);
    $output = '<ul class="subcategories-list">';

    // Loop through product subcategories WP_Term Objects
    foreach ( $terms as $term ) {
        $term_link = get_term_link( $term, $taxonomy );

        $output .= '<li class="'. $term->slug .'"><a href="'. $term_link .'">'. $term->name .'</a></li>';
    }

    echo $output . '</ul>';
}	  ?>
  </div>
<?php if(!wp_is_mobile()){;?>
<style>	  
ul.subcategories-list {
    display: flex;
    list-style: none;
}
ul.subcategories-list li {
    margin-right: 15px;
    background-color: #7d7d7d3d;
    padding: 3px 8px;
    border-radius: 7px;
}
ul.subcategories-list li:hover {
    background-color: #ff4200;
    color: #fff !important;
}
</style>	  

<?php }else{
    echo '
<style>	  
ul.subcategories-list {
    display: block;
    list-style: none;
}
ul.subcategories-list li {
    margin-right: 15px;
    background-color: #7d7d7d3d;
    padding: 3px 8px;
    border-radius: 7px;
}
ul.subcategories-list li:hover {
    background-color: #ff4200;
    color: #fff !important;
}
</style>	
    ';};
endif;
};
add_action('woocommerce_before_main_content','list_sub_product_category');

 

 

5/5 - (1 bình chọn)

Trả lời

Email của bạn sẽ không được hiển thị công khai.