• Resolved stathis_k91

    (@stathis_k91)


    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

Viewing 4 replies - 1 through 4 (of 4 total)
  • Thread Starter stathis_k91

    (@stathis_k91)

    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 8 months, 1 week ago by stathis_k91.
    • This reply was modified 8 months, 1 week ago by stathis_k91.
    • This reply was modified 8 months, 1 week ago by stathis_k91.
    Plugin Author Jory Hogeveen

    (@keraweb)

    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.www.ads-software.com/reference/functions/get_term_meta/
    https://developer.www.ads-software.com/reference/functions/wp_get_attachment_image/

    The the_terms function is meant for display and this will output HTML. You will need the function get_terms to 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

    Plugin Support Paul Clark

    (@pdclark)

    • 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(..., while echo $terms is outputting nothing. So just the_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;
    		}
    	}
    );
    
    Thread Starter stathis_k91

    (@stathis_k91)

    Great support! Thank you very much!

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Woo snippets’ is closed to new replies.