• Resolved ryandesigned

    (@ryandesigned)


    I have created custom taxonomy for “color” and was wondering if it was possible to display this info on singe product pages, and as a widget on the Shop page?

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author WC Lovers

    (@wclovers)

    Off course possible. Hope you have created that custom taxonomy using a plugin, definitely that has such option/widgets/short codes.

    Thread Starter ryandesigned

    (@ryandesigned)

    I haven’t used a plugin, but have added this snippet to my functions.php…

    add_action( ‘init’, ‘custom_taxonomy_Color’ );
    function custom_taxonomy_Color() {
    $labels = array(
    ‘name’ => ‘Colors’,
    ‘singular_name’ => ‘Color’,
    ‘menu_name’ => ‘Color’,
    ‘all_items’ => ‘All Colors’,
    ‘parent_item’ => ‘Parent Color’,
    ‘parent_item_colon’ => ‘Parent Color:’,
    ‘new_item_name’ => ‘New Color Name’,
    ‘add_new_item’ => ‘Add New Color’,
    ‘edit_item’ => ‘Edit Color’,
    ‘update_item’ => ‘Update Color’,
    ‘separate_items_with_commas’ => ‘Separate Color with commas’,
    ‘search_items’ => ‘Search Colors’,
    ‘add_or_remove_items’ => ‘Add or remove Colors’,
    ‘choose_from_most_used’ => ‘Choose from the most used Colors’,
    );
    $args = array(
    ‘labels’ => $labels,
    ‘hierarchical’ => true,
    ‘public’ => true,
    ‘show_ui’ => true,
    ‘show_admin_column’ => true,
    ‘show_in_nav_menus’ => true,
    ‘show_tagcloud’ => true,
    );
    register_taxonomy( ‘color’, ‘product’, $args );
    register_taxonomy_for_object_type( ‘color’, ‘product’ );
    }

    Wondering how to turn this into a filter widget in my shop! Thanks

    Plugin Author WC Lovers

    (@wclovers)

    Well, this is code for registering a custom taxonomy to WP.

    Use this code to show this under single product page –

    add_action( 'woocommerce_product_meta_end', 'action_product_meta_end' );
    function action_product_meta_end() {
        global $product;
    
        $term_ids = wp_get_post_terms( $product->get_id(), 'color', array('fields' => 'ids') );
    
        echo get_the_term_list( $product->get_id(), 'color', '<span class="posted_in">' . _n( 'Color:', 'Colors:', count( $term_ids ), 'woocommerce' ) . ' ', ', ', '</span>' );
    }

    Thank You

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Custom Taxonomies and Products’ is closed to new replies.