shopp_register_taxonomy()

register a Shopp product taxonomy

shopp_register_taxonomy ( $taxonomy, $args )

@param string $taxonomy The taxonomy name
@param array (optional) $args register_taxonomy arguments
@return void

Description

register a Shopp product taxonomy

This function uses the WordPress function register_taxonomy(). It is recommended that you call your taxonomy registration on the shopp_init action.

Arguments

The $taxonomy parameter is a string used to name your Shopp product taxonomy. The WordPress taxonomy name will be prefixed with shopp_. For example, the following could be used to register a shopp_brand taxonomy:

shopp_register_taxonomy('brand');

The $args parameter is an array passed to register_taxonomy().

If $args[‘rewrite’][‘slug’] is not specified, it will default to the storefront_slug/taxonomy_name. Say, for instance, your storefront url is http://example.com/store, you have registered the below brand taxonomy, created two brands (terms) Sam Adams and Michelob, and have assigned products to both terms. You should be able to view those products at:

  • http://example.com/store/brand/sam-adams
  • http://example.com/store/brand/michelob

Example

Register your taxonomies

add_action('shopp_init','register_shopp_taxonomies');

function register_shopp_taxonomies () {
    // register all shopp taxonomies here
    shopp_register_taxonomy('brand', array(
        'hierarchical' => true,
        'labels' => array(
            'name' => 'Brands',
            'singular_name' => 'Brand',
            'search_items' => 'Search Brands',
            'popular_items' => 'Popular Brands',
            'all_items' => 'Show All Brands',
            'parent_item' => 'Parent Brand',
            'parent_item_colon' => 'Parent Brand:',
            'edit_item' => 'Edit Brand',
            'update_item' => 'Update Brand',
            'add_new_item' => 'New Brand',
            'new_item_name' => 'New Brand Name',
            'separate_items_with_commas' => 'Separate brands with commas',
            'add_or_remove_items' => 'Add or remove brands',
            'choose_from_most_used' => 'Choose from the most used brands'
        ),
        'show_ui' => true,
        'query_var' => true,
        'rewrite' => array( 'slug' => 'brand' ),
    ));
}

You can programmatically add a brand taxonomy to a product

// Create two brands
// domestic brands (parent taxonomy)
$beerdomestic = shopp_add_product_term("Domestic Beers", 'shopp_brand');

// Budweiser (parent Domestic Beers)
$budweiser = shopp_add_product_term("Budweiser", 'shopp_brand', $term);

// assign product 5 to the domestic beers brand and the Budweiser brand
shopp_product_add_terms(5, array($beerdomestic,$budweiser), 'shopp_brand');

See Also

You must be logged in to post a comment.

© Ingenesis Limited. Shopp™ is a registered trademark of Ingenesis Limited.

Skip to toolbar