Skip to content

Instantly share code, notes, and snippets.

@webdev1001
Forked from lmartins/shame.php
Last active August 29, 2015 14:11
Show Gist options
  • Save webdev1001/83e32c99e816006c9cb7 to your computer and use it in GitHub Desktop.
Save webdev1001/83e32c99e816006c9cb7 to your computer and use it in GitHub Desktop.
<?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;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment