lmartins
10/17/2014 - 10:49 AM

Display Tags on product list

Display Tags on product list

<?php

if( !defined( 'ABSPATH' ) ) exit; // Exit if accessed directly


// Adicionar login/logout ao menu principal
// add_filter( 'wp_nav_menu_items', 'add_loginout_link', 10, 2 );
// function add_loginout_link( $items, $args ) {
//     if (is_user_logged_in() && $args->theme_location == 'primary') {
//         $items .= '<li><a href="'. wp_logout_url( get_permalink( woocommerce_get_page_id( 'myaccount' ) ) ) .'">Log Out</a></li>';
//     }
//     elseif (!is_user_logged_in() && $args->theme_location == 'primary') {
//         $items .= '<li><a href="' . get_permalink( woocommerce_get_page_id( 'myaccount' ) ) . '">Log In</a></li>';
//     }
//     return $items;
// }


/**
 * Adds the Customize page to the WordPress admin area
 */
// function example_customizer_menu() {
//     add_theme_page( 'Customize', 'Customize', 'edit_pages', 'customize.php' );
// }
// add_action( 'admin_menu', 'example_customizer_menu' );


// function mw_before_product(){
//   echo "teste";
// }
// add_action( 'woocommerce_before_shop_loop', 'mw_before_product' );
add_action( 'woocommerce_before_shop_loop_item', 'mw_before_product' );

// Esconde o título da págna na loja
// add_filter( 'woocommerce_show_page_title', false );


/**
 * Adiciona informação adicional ao loop de templates
 */
add_action( 'woocommerce_after_shop_loop_item_title', 'isa_woocommerce_all_pa' );
function isa_woocommerce_all_pa(){

    global $product;
    $attributes = $product->get_attributes();

    if ( ! $attributes ) {
        return;
    }

    $out = '<ul class="custom-attributes">';

    foreach ( $attributes as $attribute ) {

        // skip variations
        if ( $attribute['is_variation'] ) {
        continue;
        }

        if ( $attribute['is_taxonomy'] ) {

            $terms = wp_get_post_terms( $product->id, $attribute['name'], 'all' );

            // get the taxonomy
            $tax = $terms[0]->taxonomy;

            // get the tax object
            $tax_object = get_taxonomy($tax);

            // get tax label
            if ( isset ($tax_object->labels->name) ) {
                $tax_label = $tax_object->labels->name;
            } elseif ( isset( $tax_object->label ) ) {
                $tax_label = $tax_object->label;
            }

            foreach ( $terms as $term ) {

                $out .= '<li class="' . esc_attr( $attribute['name'] ) . ' ' . esc_attr( $term->slug ) . '">';
                $out .= '<span class="attribute-label">' . $tax_label . ': </span> ';
                $out .= '<span class="attribute-value">' . $term->name . '</span></li>';

            }

        } else {

            $out .= '<li class="' . sanitize_title($attribute['name']) . ' ' . sanitize_title($attribute['value']) . '">';
            $out .= '<span class="attribute-label">' . $attribute['name'] . ': </span> ';
            $out .= '<span class="attribute-value">' . $attribute['value'] . '</span></li>';
        }
    }

    $out .= '</ul>';

    echo $out;
}



add_action( 'woocommerce_after_shop_loop_item', 'woocommerce_product_loop_tags', 5 );

function woocommerce_product_loop_tags() {
    global $post, $product;

    $tag_count = sizeof( get_the_terms( $post->ID, 'product_tag' ) );

    echo $product->get_tags( ', ', '<span class="tagged_as">' . _n( 'Tag:', 'Tags:', $tag_count, 'woocommerce' ) . ' ', '.</span>' );
}