Code get list brand plugin Perfect Brands for WooCommerce

4.3/5 – (116 bình chọn)

Khi các bạn sử dụng plugin Perfect Brands for WooCommerce để làm brand sản phẩm, chắc hẳn sẽ cần list toàn bộ các brand của nó ra. Nhưng nó không có shortcode để hiện ra cái list đó.

Hôm nay mình xin chia sẻ đoạn code sau, các bạn bỏ nó vô functions.php của theme đang dùng. Rồi chèn shortcode [brand_list] vào nơi muốn hiện nhé.

function brand_list() {
	ob_start();
	//code get slider taxonomy
	$args_tax = array(
		'taxonomy'   => 'pwb-brand',
        	'hide_empty' => false,
		'orderby' => 'name',
		'order'   => 'ASC'
	);
	$cats = get_categories($args_tax);
	if($cats) {
		echo '<ul class="list-brand-menu">';
		foreach($cats as $cat) {
			echo '
				<li>
					<a href="'.%20get_category_link($cat->term_id)%20.%20'"><span>'. $cat->name .'</span></a>       	  
				</li>
			';	
		}
		echo '</ul>';
	}
	$brand_list = ob_get_contents();
	ob_end_clean();
	wp_reset_postdata();
	return $brand_list;
}
add_shortcode('brand_list','brand_list');

 

Comments

No comments yet. Why don’t you start the discussion?

Leave a Reply

Your email address will not be published. Required fields are marked *