Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author mjke87

    (@mjke87)

    Hi,

    It would certainly be possible to display the pictures from the plugin in the attributes in the tabs. However, some programming would be required.

    You could however, display pictures without the need of an additional plugin. Simply add the following HTML in the product tab description field to display a picture.

    <img src="URL-TO-YOUR-PICTURE" style="max-width:100% "/>

    You can use any HTML and even Shortcodes in the tab description field. You could therefore also use the WordPress native gallery shortcode:
    [gallery ids="729,732,731,720"]

    Cheers,
    Mike

    Thread Starter dsm1

    (@dsm1)

    Thanks Mike,

    As I’m programming the tabs from the functions.php file and putting a Attributes loop in place, are you able to assist me with what code I need to use for an image in the loop please?

    I have this so far:

    /**
     * Add a custom product data tab
     */
    add_filter( 'woocommerce_product_tabs', 'woo_new_product_tab' );
    function woo_new_product_tab( $tabs ) {
        
        // Adds the new tab
        
        $tabs['test_tab'] = array(
            'title'     => __( 'Ingredients', 'woocommerce' ),
            'priority'  => 50,
            'callback'  => 'woo_new_product_tab_content'
        );
    
        return $tabs;
    
    }
    /**
     * Remove product data tabs
     */
    add_filter( 'woocommerce_product_tabs', 'woo_remove_product_tabs', 98 );
    
    function woo_remove_product_tabs( $tabs ) {
    
        unset( $tabs['additional_information'] );   // Remove the additional information tab
    
        return $tabs;
    }
    function woo_new_product_tab_content() {
    
        // The new tab content
    
        echo '<h2>List of Ingredients in this product</h2>';
        echo '<p>Here\'s your new product tab.</p>';
        global $product;
    $ingredients_list = $product->get_attribute( 'ingredients' );
        print $ingredients_list;
    
    }
    Plugin Author mjke87

    (@mjke87)

    Hi,

    Check the readme from the term image plugin:

    you can use the following function into your templates to get category/term image:

    if (function_exists('get_wp_term_image'))
    {
        $meta_image = get_wp_term_image($term_id); 
    	//It will give category/term image url 
    }
    
    echo $meta_image; // category/term image url

    where $term_id is ‘category/term id’

    Something along these lines:

    $attributes = $product->get_attributes();
    foreach($attributes as $attribute) {
        $terms = wp_get_post_terms($product->get_id(), $attribute['name']);
        foreach ($terms as $term) {
            $meta_image = get_wp_term_image($term->term_id); 
        }
    }

    Kind regards,
    Mike

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘Return Attribute Image’ is closed to new replies.