1

In my product pages I've added many custom taxonomies. One of these is the taxonomy called "colecciones". As you can see for instance in this URL:https://www.editorialufv.es/catalogo/comunicacion-clinica/ every book is part of a collection (colección in Spanish).

I'd like that the link that appears in the product page would redirect to the page that I've done of every collection and not to the shop page filter. In this case the colección is called "relación clínica" and his URL is this: https://www.editorialufv.es/coleccionesufv/relacion-clinica/

Thanks to one of you I've done something similar for the name of the authors: now they link to the member page and not to the shop filter page. In order to do that I've modified the function.php this way:

add_action( 'woocommerce_single_product_summary', 'show_product_autor', 24 );
function show_product_autor(){

// get this woo-comm's product author
$authors = wp_get_post_terms( get_the_ID(), 'autor' );

// we know it'll just be one author, so use first object of array
$author = array_pop($authors);

// knowing the authors name, lets find the TEAM page
$authorTeamPg = get_page_by_title( $author->name, 'OBJECT', 'team' );

// now we know the authors page
$authorTeamPgLink = get_permalink( $authorTeamPg->ID);

// output
echo "<b>AUTOR: </b><a href='{$authorTeamPgLink}'>{$author->name}</a>",'<br />';
}

Now, I've tried to do the same for the taxonomy of the collection with no result. Here my attempt:

add_action( 'woocommerce_single_product_summary', 'show_product_colecciones', 25 );

function show_product_colecciones(){

$collections = wp_get_post_terms( get_the_ID(), ‘Colecciones’ );

$collection = array_pop($collections);

$collectionPg = get_page_by_title ( $collection->name, ‘OBJECT’, ‘page’ );

$collectionPgLink = get_permalink( $collectionPg->ID);

echo “<b>COLECCIÓN: </b><a href=‘{$collectionPgLink}’>{$collection->name}</a>”, ‘<br />’;
}

The code of the taxonomy is this:

$labels = array(
'name' => _x( 'Colecciones', 'taxonomy general name' ),
'singular_name' => _x( 'Colección', 'taxonomy singular name' ),
'search_items' =>  __( 'Buscar colecciones' ),
'all_items' => __( 'Todas las colecciones' ),
'parent_item' => __( 'Colección padre' ),
'parent_item_colon' => __( 'Colección padre:' ),
'edit_item' => __( 'Editar colección' ), 
'update_item' => __( 'Actualizar colección' ),
'add_new_item' => __( 'Añadir nueva colección' ),
'new_item_name' => __( 'Nombre de la nueva colección' ),
'menu_name' => __( 'Colecciones' ),
);     

register_taxonomy('colecciones',array('product'), array(
'hierarchical' => true,
'labels' => $labels,
'show_ui' => true,
'show_admin_column' => true,
'query_var' => true,
'rewrite' => array( 'slug' => 'colecciones' ),
));
}

Is there anyone that could help me?

  • post your code for the taxonomy link – inarilo Dec 22 '17 at 20:22
  • Done! I've post my attempt – Stefano Dec 22 '17 at 20:38
  • 1
    both your double and single quotes are not the correct kind in this block of code. also make sure the taxonomy name matches exactly, it is case sensitive. – inarilo Dec 22 '17 at 21:04
  • Ha, you're completely right! I'm feel I'm very near to find the solution. With the right quotes the web works but the name of the collections don't appear on my product page. Take a look: editorialufv.es/catalogo/claves-de-seguridad Do you have an idea why? – Stefano Dec 22 '17 at 21:10
  • 2
    you registered it as 'coleccions', with small 'c' – inarilo Dec 22 '17 at 21:28
1

Both your double and single quotes are not the correct kind in this block of code. Also, the taxonomy name is 'colecciones' with a small 'c', but you used 'Coleccions' with a capital 'C'. The match is case sensitive. Thus your function code should be:

function show_product_colecciones(){

  $collections = wp_get_post_terms( get_the_ID(), 'colecciones' );

  $collection = array_pop($collections);

  $collectionPg = get_page_by_title ( $collection->name, 'OBJECT', 'page' );

  $collectionPgLink = get_permalink( $collectionPg->ID);

  echo "<b>COLECCIÓN: </b><a href='{$collectionPgLink}'>{$collection->name}</a>", '<br />';

}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.