How to add brands (Manufacturers) for Products in WooCommerce wordpress plugin

brand-manufacturers-products-woocommerceHow to

add brands (Manufacturers) for Products in WooCommerce wordpress plugin

WooCommerce to power their online shop. Selling blends of unique coffee flavors, from the Methow Valley to coffee lovers around the world.

Open your functions.php with Notepad++ editor

add

function create_product_taxonomies()
{
// Add new taxonomy, make it hierarchical (like categories)
$labels = array(
‘name’ => _x( ‘Brands’, ‘taxonomy general name’ ),
‘singular_name’ => _x( ‘Brand’, ‘taxonomy singular name’ ),
‘search_items’ =>  __( ‘Search Brands’ ),
‘all_items’ => __( ‘All Brands’ ),
‘parent_item’ => __( ‘Parent Brand’ ),
‘parent_item_colon’ => __( ‘Parent Brands:’ ),
‘edit_item’ => __( ‘Edit Brands’ ),
‘update_item’ => __( ‘Update Brands’ ),
‘add_new_item’ => __( ‘Add New Brand’ ),
‘new_item_name’ => __( ‘New Brand Name’ ),
‘menu_name’ => __( ‘Brands’ ),
);

register_taxonomy(‘product_brand’,array(‘product’), array(
‘hierarchical’ => true,
‘labels’ => $labels,
‘show_ui’ => true,
‘query_var’ => true,
//’rewrite’ => true,
‘rewrite’ => array( ‘slug’ => ‘brands’, ‘with_front’ => true ),
));
}

function filter_post_type_link($link, $post)
{
if ($post->post_type != ‘product’)
return $link;
if ($cats = get_the_terms($post->ID, ‘product_brand’))
if ($cats = get_the_terms($post->ID, ‘product_brand’))
$link = str_replace(‘%product_brand%’, array_pop($cats)->slug, $link);
return $link;
}
add_filter(‘post_type_link’, ‘filter_post_type_link’, 10, 2);

function get_brands( $sep = ‘, ‘, $before = ”, $after = ” ) {
global $product;
return get_the_term_list( $product->ID, ‘product_brand’, $before, $sep, $after );
}

and then Login your Dashboard, add your Brands – Manufacturers

Add your Products to your catergories and order to Brands – Manufacturers

———————————————

Open your template to display with Notepad++ editor 

to add code:

$term             = get_queried_object();

//$parent_id         = empty( $term->term_id ) ? 0 : $term->term_id;

if(!empty( $term->term_id )){

$args = apply_filters( ‘woocommerce_product_subcategories_args’, array(
‘child_of’        => $term->term_id,
‘menu_order’    => ‘ASC’,
‘hide_empty’    => 1,
‘hierarchical’    => 1,
‘taxonomy’        => ‘product_brand’,
‘pad_counts’    => 1
) );

$product_categories     = get_categories( $args );

if ( $product_categories ) {

foreach ( $product_categories as $category ) {

wc_get_template( ‘content-product_cat.php’, array(
‘category’ => $category
) );

}

}

}

Open your meta.php  with Notepad++ editor 

$brand_count = sizeof( get_the_terms( $post->ID, ‘product_brand’ ) );

 

and

<?php echo get_brands( ‘, ‘, ‘<span class=”posted_in”>’ . _n( ‘Brand:’, ‘Brands:’, $brand_count, ‘woocommerce’ ) . ‘ ‘, ‘.</span>’ ); ?>

Need help? http://joomquery.com/contact-us/

Good luck

Be Sociable, Share!

Leave a comment