Tidied taxonomys
This commit is contained in:
parent
fd46600c7f
commit
4b74f6a52d
|
@ -10,123 +10,22 @@
|
|||
*/
|
||||
|
||||
/**
|
||||
* Custom Post Types
|
||||
* Custom Post Types and taxonomies
|
||||
**/
|
||||
function woocommerce_post_type() {
|
||||
|
||||
global $wpdb, $woocommerce;
|
||||
|
||||
$shop_page_id = get_option('woocommerce_shop_page_id');
|
||||
|
||||
$base_slug = ($shop_page_id > 0 && get_page( $shop_page_id )) ? get_page_uri( $shop_page_id ) : 'shop';
|
||||
|
||||
$product_base = '';
|
||||
$category_base = '';
|
||||
|
||||
if (get_option('woocommerce_prepend_shop_page_to_urls')=="yes") :
|
||||
$category_base = trailingslashit($base_slug);
|
||||
endif;
|
||||
|
||||
if (get_option('woocommerce_prepend_shop_page_to_products')=='yes') :
|
||||
$product_base = trailingslashit($base_slug);
|
||||
else :
|
||||
$product_base = trailingslashit(__('product', 'woothemes'));
|
||||
endif;
|
||||
|
||||
if (get_option('woocommerce_prepend_category_to_products')=='yes') :
|
||||
$product_base .= trailingslashit('%product_cat%');
|
||||
endif;
|
||||
$category_base = (get_option('woocommerce_prepend_shop_page_to_urls')=="yes") ? trailingslashit($base_slug) : '';
|
||||
|
||||
$product_base = (get_option('woocommerce_prepend_shop_page_to_products')=='yes') ? trailingslashit($base_slug) : trailingslashit(__('product', 'woothemes'));
|
||||
if (get_option('woocommerce_prepend_category_to_products')=='yes') $product_base .= trailingslashit('%product_cat%');
|
||||
$product_base = untrailingslashit($product_base);
|
||||
|
||||
if (current_user_can('manage_woocommerce')) $show_in_menu = 'woocommerce'; else $show_in_menu = true;
|
||||
|
||||
register_taxonomy( 'product_cat',
|
||||
array('product'),
|
||||
array(
|
||||
'hierarchical' => true,
|
||||
'update_count_callback' => '_update_post_term_count',
|
||||
'label' => __( 'Categories', 'woothemes'),
|
||||
'labels' => array(
|
||||
'name' => __( 'Categories', 'woothemes'),
|
||||
'singular_name' => __( 'Product Category', 'woothemes'),
|
||||
'search_items' => __( 'Search Product Categories', 'woothemes'),
|
||||
'all_items' => __( 'All Product Categories', 'woothemes'),
|
||||
'parent_item' => __( 'Parent Product Category', 'woothemes'),
|
||||
'parent_item_colon' => __( 'Parent Product Category:', 'woothemes'),
|
||||
'edit_item' => __( 'Edit Product Category', 'woothemes'),
|
||||
'update_item' => __( 'Update Product Category', 'woothemes'),
|
||||
'add_new_item' => __( 'Add New Product Category', 'woothemes'),
|
||||
'new_item_name' => __( 'New Product Category Name', 'woothemes')
|
||||
),
|
||||
'show_ui' => true,
|
||||
'query_var' => true,
|
||||
'rewrite' => array( 'slug' => $category_base . _x('product-category', 'slug', 'woothemes'), 'with_front' => false ),
|
||||
)
|
||||
);
|
||||
|
||||
register_taxonomy( 'product_tag',
|
||||
array('product'),
|
||||
array(
|
||||
'hierarchical' => false,
|
||||
'label' => __( 'Tags', 'woothemes'),
|
||||
'labels' => array(
|
||||
'name' => __( 'Tags', 'woothemes'),
|
||||
'singular_name' => __( 'Product Tag', 'woothemes'),
|
||||
'search_items' => __( 'Search Product Tags', 'woothemes'),
|
||||
'all_items' => __( 'All Product Tags', 'woothemes'),
|
||||
'parent_item' => __( 'Parent Product Tag', 'woothemes'),
|
||||
'parent_item_colon' => __( 'Parent Product Tag:', 'woothemes'),
|
||||
'edit_item' => __( 'Edit Product Tag', 'woothemes'),
|
||||
'update_item' => __( 'Update Product Tag', 'woothemes'),
|
||||
'add_new_item' => __( 'Add New Product Tag', 'woothemes'),
|
||||
'new_item_name' => __( 'New Product Tag Name', 'woothemes')
|
||||
),
|
||||
'show_ui' => true,
|
||||
'query_var' => true,
|
||||
'rewrite' => array( 'slug' => $category_base . _x('product-tag', 'slug', 'woothemes'), 'with_front' => false ),
|
||||
)
|
||||
);
|
||||
|
||||
$attribute_taxonomies = $woocommerce->get_attribute_taxonomies();
|
||||
if ( $attribute_taxonomies ) :
|
||||
foreach ($attribute_taxonomies as $tax) :
|
||||
|
||||
$name = $woocommerce->attribute_taxonomy_name($tax->attribute_name);
|
||||
$hierarchical = true;
|
||||
if ($name) :
|
||||
|
||||
$label = ( isset( $tax->attribute_label ) && $tax->attribute_label ) ? $tax->attribute_label : $tax->attribute_name;
|
||||
|
||||
$show_in_nav_menus = apply_filters('woocommerce_attribute_show_in_nav_menus', false, $name);
|
||||
|
||||
register_taxonomy( $name,
|
||||
array('product'),
|
||||
array(
|
||||
'hierarchical' => $hierarchical,
|
||||
'labels' => array(
|
||||
'name' => $label,
|
||||
'singular_name' => $label,
|
||||
'search_items' => __( 'Search', 'woothemes') . ' ' . $label,
|
||||
'all_items' => __( 'All', 'woothemes') . ' ' . $label,
|
||||
'parent_item' => __( 'Parent', 'woothemes') . ' ' . $label,
|
||||
'parent_item_colon' => __( 'Parent', 'woothemes') . ' ' . $label . ':',
|
||||
'edit_item' => __( 'Edit', 'woothemes') . ' ' . $label,
|
||||
'update_item' => __( 'Update', 'woothemes') . ' ' . $label,
|
||||
'add_new_item' => __( 'Add New', 'woothemes') . ' ' . $label,
|
||||
'new_item_name' => __( 'New', 'woothemes') . ' ' . $label
|
||||
),
|
||||
'show_ui' => false,
|
||||
'query_var' => true,
|
||||
'show_in_nav_menus' => $show_in_nav_menus,
|
||||
'rewrite' => array( 'slug' => $category_base . strtolower(sanitize_title($tax->attribute_name)), 'with_front' => false, 'hierarchical' => $hierarchical ),
|
||||
)
|
||||
);
|
||||
|
||||
endif;
|
||||
endforeach;
|
||||
endif;
|
||||
|
||||
register_post_type( "product",
|
||||
array(
|
||||
'labels' => array(
|
||||
|
@ -185,18 +84,7 @@ function woocommerce_post_type() {
|
|||
'rewrite' => false,
|
||||
'query_var' => true,
|
||||
'supports' => array( 'title', 'editor', 'custom-fields', 'page-attributes', 'thumbnail' ),
|
||||
'show_in_nav_menus' => false,
|
||||
//'show_in_menu' => 'edit.php?post_type=product'
|
||||
)
|
||||
);
|
||||
|
||||
register_taxonomy( 'product_type',
|
||||
array('product'),
|
||||
array(
|
||||
'hierarchical' => false,
|
||||
'show_ui' => false,
|
||||
'query_var' => true,
|
||||
'show_in_nav_menus' => false,
|
||||
'show_in_nav_menus' => false
|
||||
)
|
||||
);
|
||||
|
||||
|
@ -233,30 +121,6 @@ function woocommerce_post_type() {
|
|||
)
|
||||
);
|
||||
|
||||
register_taxonomy( 'shop_order_status',
|
||||
array('shop_order'),
|
||||
array(
|
||||
'hierarchical' => true,
|
||||
'update_count_callback' => '_update_post_term_count',
|
||||
'labels' => array(
|
||||
'name' => __( 'Order statuses', 'woothemes'),
|
||||
'singular_name' => __( 'Order status', 'woothemes'),
|
||||
'search_items' => __( 'Search Order statuses', 'woothemes'),
|
||||
'all_items' => __( 'All Order statuses', 'woothemes'),
|
||||
'parent_item' => __( 'Parent Order status', 'woothemes'),
|
||||
'parent_item_colon' => __( 'Parent Order status:', 'woothemes'),
|
||||
'edit_item' => __( 'Edit Order status', 'woothemes'),
|
||||
'update_item' => __( 'Update Order status', 'woothemes'),
|
||||
'add_new_item' => __( 'Add New Order status', 'woothemes'),
|
||||
'new_item_name' => __( 'New Order status Name', 'woothemes')
|
||||
),
|
||||
'show_ui' => false,
|
||||
'show_in_nav_menus' => false,
|
||||
'query_var' => true,
|
||||
'rewrite' => false,
|
||||
)
|
||||
);
|
||||
|
||||
register_post_type( "shop_coupon",
|
||||
array(
|
||||
'labels' => array(
|
||||
|
@ -288,6 +152,131 @@ function woocommerce_post_type() {
|
|||
'show_in_nav_menus' => false,
|
||||
)
|
||||
);
|
||||
|
||||
/**
|
||||
* Taxonomies
|
||||
**/
|
||||
$product_type_query_var = (is_admin()) ? true : false;
|
||||
|
||||
register_taxonomy( 'product_type',
|
||||
array('product'),
|
||||
array(
|
||||
'hierarchical' => false,
|
||||
'show_ui' => false,
|
||||
'show_in_nav_menus' => false,
|
||||
'query_var' => $product_type_query_var,
|
||||
'rewrite' => false
|
||||
)
|
||||
);
|
||||
register_taxonomy( 'product_cat',
|
||||
array('product'),
|
||||
array(
|
||||
'hierarchical' => true,
|
||||
'update_count_callback' => '_update_post_term_count',
|
||||
'label' => __( 'Categories', 'woothemes'),
|
||||
'labels' => array(
|
||||
'name' => __( 'Categories', 'woothemes'),
|
||||
'singular_name' => __( 'Product Category', 'woothemes'),
|
||||
'search_items' => __( 'Search Product Categories', 'woothemes'),
|
||||
'all_items' => __( 'All Product Categories', 'woothemes'),
|
||||
'parent_item' => __( 'Parent Product Category', 'woothemes'),
|
||||
'parent_item_colon' => __( 'Parent Product Category:', 'woothemes'),
|
||||
'edit_item' => __( 'Edit Product Category', 'woothemes'),
|
||||
'update_item' => __( 'Update Product Category', 'woothemes'),
|
||||
'add_new_item' => __( 'Add New Product Category', 'woothemes'),
|
||||
'new_item_name' => __( 'New Product Category Name', 'woothemes')
|
||||
),
|
||||
'show_ui' => true,
|
||||
'query_var' => true,
|
||||
'rewrite' => array( 'slug' => $category_base . _x('product-category', 'slug', 'woothemes'), 'with_front' => false ),
|
||||
)
|
||||
);
|
||||
|
||||
register_taxonomy( 'product_tag',
|
||||
array('product'),
|
||||
array(
|
||||
'hierarchical' => false,
|
||||
'label' => __( 'Tags', 'woothemes'),
|
||||
'labels' => array(
|
||||
'name' => __( 'Tags', 'woothemes'),
|
||||
'singular_name' => __( 'Product Tag', 'woothemes'),
|
||||
'search_items' => __( 'Search Product Tags', 'woothemes'),
|
||||
'all_items' => __( 'All Product Tags', 'woothemes'),
|
||||
'parent_item' => __( 'Parent Product Tag', 'woothemes'),
|
||||
'parent_item_colon' => __( 'Parent Product Tag:', 'woothemes'),
|
||||
'edit_item' => __( 'Edit Product Tag', 'woothemes'),
|
||||
'update_item' => __( 'Update Product Tag', 'woothemes'),
|
||||
'add_new_item' => __( 'Add New Product Tag', 'woothemes'),
|
||||
'new_item_name' => __( 'New Product Tag Name', 'woothemes')
|
||||
),
|
||||
'show_ui' => true,
|
||||
'query_var' => true,
|
||||
'rewrite' => array( 'slug' => $category_base . _x('product-tag', 'slug', 'woothemes'), 'with_front' => false ),
|
||||
)
|
||||
);
|
||||
|
||||
register_taxonomy( 'shop_order_status',
|
||||
array('shop_order'),
|
||||
array(
|
||||
'hierarchical' => true,
|
||||
'update_count_callback' => '_update_post_term_count',
|
||||
'labels' => array(
|
||||
'name' => __( 'Order statuses', 'woothemes'),
|
||||
'singular_name' => __( 'Order status', 'woothemes'),
|
||||
'search_items' => __( 'Search Order statuses', 'woothemes'),
|
||||
'all_items' => __( 'All Order statuses', 'woothemes'),
|
||||
'parent_item' => __( 'Parent Order status', 'woothemes'),
|
||||
'parent_item_colon' => __( 'Parent Order status:', 'woothemes'),
|
||||
'edit_item' => __( 'Edit Order status', 'woothemes'),
|
||||
'update_item' => __( 'Update Order status', 'woothemes'),
|
||||
'add_new_item' => __( 'Add New Order status', 'woothemes'),
|
||||
'new_item_name' => __( 'New Order status Name', 'woothemes')
|
||||
),
|
||||
'show_ui' => false,
|
||||
'show_in_nav_menus' => false,
|
||||
'query_var' => false,
|
||||
'rewrite' => false,
|
||||
)
|
||||
);
|
||||
|
||||
$attribute_taxonomies = $woocommerce->get_attribute_taxonomies();
|
||||
if ( $attribute_taxonomies ) :
|
||||
foreach ($attribute_taxonomies as $tax) :
|
||||
|
||||
$name = $woocommerce->attribute_taxonomy_name($tax->attribute_name);
|
||||
$hierarchical = true;
|
||||
if ($name) :
|
||||
|
||||
$label = ( isset( $tax->attribute_label ) && $tax->attribute_label ) ? $tax->attribute_label : $tax->attribute_name;
|
||||
|
||||
$show_in_nav_menus = apply_filters('woocommerce_attribute_show_in_nav_menus', false, $name);
|
||||
|
||||
register_taxonomy( $name,
|
||||
array('product'),
|
||||
array(
|
||||
'hierarchical' => $hierarchical,
|
||||
'labels' => array(
|
||||
'name' => $label,
|
||||
'singular_name' => $label,
|
||||
'search_items' => __( 'Search', 'woothemes') . ' ' . $label,
|
||||
'all_items' => __( 'All', 'woothemes') . ' ' . $label,
|
||||
'parent_item' => __( 'Parent', 'woothemes') . ' ' . $label,
|
||||
'parent_item_colon' => __( 'Parent', 'woothemes') . ' ' . $label . ':',
|
||||
'edit_item' => __( 'Edit', 'woothemes') . ' ' . $label,
|
||||
'update_item' => __( 'Update', 'woothemes') . ' ' . $label,
|
||||
'add_new_item' => __( 'Add New', 'woothemes') . ' ' . $label,
|
||||
'new_item_name' => __( 'New', 'woothemes') . ' ' . $label
|
||||
),
|
||||
'show_ui' => false,
|
||||
'query_var' => true,
|
||||
'show_in_nav_menus' => $show_in_nav_menus,
|
||||
'rewrite' => array( 'slug' => $category_base . strtolower(sanitize_title($tax->attribute_name)), 'with_front' => false, 'hierarchical' => $hierarchical ),
|
||||
)
|
||||
);
|
||||
|
||||
endif;
|
||||
endforeach;
|
||||
endif;
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue