• Resolved Ivan Nugraha

    (@mangwp)


    Hi, how do we retrieve the image attribute URL? I use this code to display attribute term on current product.

    function get_product_brand_attribute() {
    global $product;
    if ( is_a( $product, 'WC_Product' ) ) {
        $brand_terms = wc_get_product_terms( $product->get_id(), 'pa_brand' );
    
        if ( ! empty( $brand_terms ) && ! is_wp_error( $brand_terms ) ) {
            $brand = reset( $brand_terms );
            return $brand->name;
            //return $brand->imagefromplugin//
        }
    }
    
    return '';
    }

Viewing 1 replies (of 1 total)
  • Plugin Support fizanzvai

    (@fizanzvai)

    @mangwp

    Thanks for reaching out to us. Unfortunately, I don’t know what is your goal. But I am giving you a hint here:

    add_action('woocommerce_single_product_summary', 'get_product_brand_attribute', 6);
    function get_product_brand_attribute() {
    	global $product;
    	if ( is_a( $product, 'WC_Product' ) ) {
    		$brand_terms = wc_get_product_terms( $product->get_id(), 'pa_image' ); 
    
    		//echo "<pre>"; print_r($meta_data); echo "</pre>";
    
    		if ( ! empty( $brand_terms ) && ! is_wp_error( $brand_terms ) ) {
    			$brand = $brand_terms;
    			if ( ! empty( $brand ) && ! is_wp_error( $brand ) ) {
    				foreach( $brand as $b ){
    					$meta_data = (object) get_term_meta( $b->term_id ); 
    					if ( ! empty( $meta_data ) && ! is_wp_error( $meta_data ) ) {
    						echo wp_get_attachment_image(reset($meta_data->product_attribute_image));
    					}
    				}
    			}
    		}
    	}
    }

    Please add it inside your child theme’s functions.php file or add it as a snippet using a plugin Code Snippets plugin. Then modify it as you want.

    After adding the above snippet I am getting this on the frontend: https://paste.pics/P15AV

    Thanks

Viewing 1 replies (of 1 total)
  • The topic ‘Retrive Image Attribute Link’ is closed to new replies.