WC_Brands::init_taxonomy
Initializes brand taxonomy.
Method of the class: WC_Brands{}
Hooks from the method
Returns
null. Nothing (null).
Usage
$result = WC_Brands::init_taxonomy();
WC_Brands::init_taxonomy() WC Brands::init taxonomy code WC 10.3.5
public static function init_taxonomy() {
$shop_page_id = wc_get_page_id( 'shop' );
$base_slug = $shop_page_id > 0 && get_page( $shop_page_id ) ? get_page_uri( $shop_page_id ) : 'shop';
$category_base = get_option( 'woocommerce_prepend_shop_page_to_urls' ) === 'yes' ? trailingslashit( $base_slug ) : '';
$slug = $category_base . __( 'brand', 'woocommerce' );
if ( '' === $category_base ) {
$slug = get_option( 'woocommerce_brand_permalink', '' );
}
// Can't provide transatable string as get_option default.
if ( '' === $slug ) {
$slug = __( 'brand', 'woocommerce' );
}
register_taxonomy(
'product_brand',
array( 'product' ),
/**
* Filter the brand taxonomy.
*
* @since 9.4.0
*
* @param array $args Args.
*/
apply_filters(
'register_taxonomy_product_brand',
array(
'hierarchical' => true,
'update_count_callback' => '_wc_term_recount',
'label' => __( 'Brands', 'woocommerce' ),
'labels' => array(
'name' => __( 'Brands', 'woocommerce' ),
'singular_name' => __( 'Brand', 'woocommerce' ),
'template_name' => _x( 'Products by Brand', 'Template name', 'woocommerce' ),
'search_items' => __( 'Search Brands', 'woocommerce' ),
'all_items' => __( 'All Brands', 'woocommerce' ),
'parent_item' => __( 'Parent Brand', 'woocommerce' ),
'parent_item_colon' => __( 'Parent Brand:', 'woocommerce' ),
'edit_item' => __( 'Edit Brand', 'woocommerce' ),
'update_item' => __( 'Update Brand', 'woocommerce' ),
'add_new_item' => __( 'Add New Brand', 'woocommerce' ),
'new_item_name' => __( 'New Brand Name', 'woocommerce' ),
'not_found' => __( 'No Brands Found', 'woocommerce' ),
'no_terms' => __( 'No brands', 'woocommerce' ),
'back_to_items' => __( '← Go to Brands', 'woocommerce' ),
),
'show_ui' => true,
'show_admin_column' => true,
'show_in_nav_menus' => true,
'show_in_rest' => true,
'capabilities' => array(
'manage_terms' => 'manage_product_terms',
'edit_terms' => 'edit_product_terms',
'delete_terms' => 'delete_product_terms',
'assign_terms' => 'assign_product_terms',
),
'rewrite' => array(
'slug' => $slug,
'with_front' => false,
'hierarchical' => true,
),
)
)
);
}