Adding custom taxonomy for product fpr wp4.3

hi how i can Add custom taxonomy for product ?
i googed but no success!

Did you try the WordPress Codex? https://codex.wordpress.org/Taxonomies

When you mention product, are you using one of the e-commerce plugins that WordPress has?

1 Like

yes,i use woocommerce plugin…i wana add toxonomy for products not for posts

Products in WooCommerce is just a WordPress custom post type. You can make custom taxonomies for custom post types from scratch, or you can use a plugin: see https://wp-types.com/learn/create-an-ecommerce-wordpress-site/create-custom-fields-and-taxonomies/ and https://wp-types.com/home/types-manage-post-types-taxonomy-and-custom-fields/

Let me know if you want to code it from scratch instead of using a plugin and I can give you a start.

1 Like

i wana code from scratch and i did this i searched in google and found some thing on this site then i changed the code to catch text instead of price then tadaaa Worked!

and i saw wp-types.com but that was for older vergen of wordpress was not good for me,

thanks in advance for giving your time to me!

But i have one more problem, i wana delete add to cart from main page of products… i wana this button just appear on detail page of produts not in main page,

For starters, in order to make any changes to the woocommerce plugin, you need to add a woocommerce folder in your theme directory and copythe files from woocommerce that you want to change to the new folder, and make the changes there. Don’t edit the original plugin.

To delete the add to cart button from the main page of products, why don’t you just give it display:none in the css specifially for that page. If you give us a site url, we could give you more specific help here.

As for the custom taxonomy, here is some sample code for setting up a custom taxonomy for a custom post type called ‘product’. It goes in the functions.php file.

 /**
         * Create custom taxonomy for products
         */    
        function create_product_taxonomy() {
            $labels = array(
                'name'              => _x( 'Product Categories', 'taxonomy general name' ),
                'singular_name'     => _x( 'Product Category', 'taxonomy singular name' ),
                'search_items'      => __( 'Search Product Categories' ),
                'all_items'         => __( 'All Product Categories' ),
                'parent_item'       => __( 'Parent Product Category' ),
                'parent_item_colon' => __( 'Parent Product Category:' ),
                'edit_item'         => __( 'Edit Product Category' ), 
                'update_item'       => __( 'Update Product Category' ),
                'add_new_item'      => __( 'Add New Product Category' ),
                'new_item_name'     => __( 'New Product Category' ),
                'menu_name'         => __( 'Product Categories' ),
            );
        
        $args = array(
            'labels' => $labels,
            'hierarchical' => true,
            'query_var' => true,
            'rewrite' => true,
            'show_admin_column' => true
        );
        
        register_taxonomy( 'product_category', 'product', $args );
                
    }
    add_action( 'init', 'create_product_taxonomy', 0 );

Hope that will get you started in the right direction.

In register_taxonomy( 'product_category', 'product', $args ); the second argument, ‘product’ is the name of the custom post type.

1 Like

its my site

thanks so much for your help

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.