Woo snippets
-
Hi,
I created a Brand taxonomy related to woocommerce products,
I also added in more fields a Thumbnail,
Can you please share a snippet to show the taxonomy in single product plus in taxonomy pages like categories and tags? I like to show the thumbnail only in single product page. In additional i like to choose the position eg after title etc.
Regards,
Stathis
-
Update:
I found the snippet to display the pod in woo taxonomies and in single product loop.
The issue is that it doesn’t display the thumbnail in single product. (i don’t want to display the thumbnail in taxonomies).
The snippet:
/* Show brand custom post type on single product loop */ function brandposttype_woocommerce_before_add_to_cart_form() { $terms = the_terms( $post->ID, 'brand' ); echo $terms; }; add_action( 'woocommerce_before_add_to_cart_form', 'brandposttype_woocommerce_before_add_to_cart_form', 1, 0 );-
This reply was modified 2 years, 2 months ago by
stathis_k91.
-
This reply was modified 2 years, 2 months ago by
stathis_k91.
-
This reply was modified 2 years, 2 months ago by
stathis_k91.
Hi @stathis_k91
This is more a WordPress core question than specificaly Pods related. All fields are stored as metadata so you can load it in with WordPress core functions and then show the images by the attachment ID:
– https://developer.ww.wp.xz.cn/reference/functions/get_term_meta/
– https://developer.ww.wp.xz.cn/reference/functions/wp_get_attachment_image/The
the_termsfunction is meant for display and this will output HTML. You will need the functionget_termsto fetch the actual term objects instead.I don’t know of any code snippets for this as this is highly dependent on how you want to display these images. There are many ways to display images so you would need to get familiar with the various PHP functions and ways to display information in your theme.
Alternatively you could hook a Pods template in there and use our magic tags for the same purpose!
Cheers, Jory
- This visual guide will show available default hooks for displaying custom content on a Woo single product page.
- Displaying custom content on a taxonomy archive page is sometimes dependent on the theme structure. Pods auto templates in the user interface hooks into get_the_archive_description, but check the templates or documentation for your theme if you are looking for other placements.
- As Jory noted, the_terms() will output HTML links to the brand terms, but it doesn’t return anything. So the shared code is working because output occurs at
$terms = the_terms(..., whileecho $termsis outputting nothing. So justthe_terms( get_the_ID(), 'brand' );is sufficient to output term links. - If you have saved the brand thumbnail or logo to a field with the name
μικρογραφία_μάρκας, then here is a full example which would add a brand thumbnail and band name as a linked figure and figcaption for the first brand of the product on the single product page:
<?php /** * Display a Woo product brand term and thumbnail with Pods. * Εμφανίστε έναν όρο και μια μικρογραφία της επωνυμίας προϊόντος Woo με Pods * * @see https://www.businessbloomer.com/woocommerce-visual-hook-guide-single-product-page/ */ add_action( 'woocommerce_before_single_product', function() { /** * If the 'brand' taxonomy is not connected to the product post type, this will cause an error. * * Εάν η ταξινόμηση της «μάρκας» δεν είναι συνδεδεμένη με τον τύπο ανάρτησης προϊόντος, * αυτό θα προκαλέσει σφάλμα. */ foreach( (array) get_the_terms( get_the_ID(), 'brand' ) as $brand_term ) { /** * Start a link to the term taxonomy page. * * Ξεκινήστε έναν σύνδεσμο προς τη σελίδα ταξινόμησης όρου. */ printf( '<figure><a href="%s">', esc_url( get_term_link( $brand_term->term_id ) ) ); /** * For the first matching brand, display images stored in field "μικρογραφία_μάρκας", then stop. * * Για την πρώτη μάρκα που ταιριάζει, εμφανίστε τις εικόνες που είναι αποθηκευμένες στο πεδίο "μικρογραφία_μάρκας" και μετά σταματήστε. */ pods( 'brand', $brand_term->term_id )->display( 'μικρογραφία_μάρκας' ); /** * Display the term name and close the link. * * Εμφανίστε το όνομα του όρου και κλείστε τον σύνδεσμο. */ printf( '<figcaption>%s</figcaption></a></figure>', esc_html( $brand_term->name ) ); /** * Removing 'break;' will cause more than one brand to display; * * Αφαίρεση του «break;» θα προκαλέσει την εμφάνιση περισσότερων από μία επωνυμιών. */ break; } } );Great support! Thank you very much!
-
This reply was modified 2 years, 2 months ago by
The topic ‘Woo snippets’ is closed to new replies.