• Resolved rashmirai

    (@rashmirai)


    hi everybody! is it possible to add more classes to catalog thumbnail images — like i am customising my own woocommerce theme with a referance to a html shop page which look like this—

    [ Moderator note: code fixed. Please wrap code in the backtick character or use the code button. ]

    <div class="product-wrap">
    <div class="col-xxs-12 col-xs-6 col-sm-4 col-md-3">
                <div class="product-box">
                <div class="product-img"><img src="images/product-09.jpg" alt="" title=""></div>
              <h2>LEATHER BLAZER JACKET WITH ZIP POCKETS</h2>
              <p>$230</p>
              <div class="overbox">
                <div class="cart-bag"></div>
                <div class="heart"></div>
                <button class="title overtext"> Quick View </button>
                <div class="tagline overtext"> $230 </div>
              </div>
            </div>
            </div></div>

    now i want to add all these classes to my catalog images in the archive-product.php in the product thumbnail loop according to the div structure as it is as in html code above. is it possible?? pls pls pls help!

    https://wordpress.org/plugins/woocommerce/

Viewing 6 replies - 1 through 6 (of 6 total)
  • Thread Starter rashmirai

    (@rashmirai)

    i have tried this snippet—–

    remove_action( 'woocommerce_before_shop_loop_item_title', 'woocommerce_template_loop_product_thumbnail', 10);
    add_action( 'woocommerce_before_shop_loop_item_title', 'woocommerce_template_loop_product_thumbnail', 10);
    
    if ( ! function_exists( 'woocommerce_template_loop_product_thumbnail' ) ) {
        function woocommerce_template_loop_product_thumbnail() {
            echo woocommerce_get_product_thumbnail();
        }
    }
    if ( ! function_exists( 'woocommerce_get_product_thumbnail' ) ) {
        function woocommerce_get_product_thumbnail( $size = 'shop_catalog', $placeholder_width = 0, $placeholder_height = 0  ) {
            global $post, $woocommerce;
            $output = '<div class="product-wrap">';
    
            if ( has_post_thumbnail() ) {
                $output .= get_the_post_thumbnail( $post->ID, $size );
            }
            $output .= '</div>';
            return $output;
        }
    }

    but it adds only a product wrapper, that is <div class=”product-wrap”>
    but i want all the div classes around my product thumbnails with the same div structure! thanks

    Plugin Author Mike Jolley (a11n)

    (@mikejolley)

    Thread Starter rashmirai

    (@rashmirai)

    sorry i am lay to code! can you please give me an example how to do that with reference to the below html example—

    <div class="product-wrap">
    <div class="col-xxs-12 col-xs-6 col-sm-4 col-md-3">
                <div class="product-box">
                <div class="product-img"><img src="images/product-09.jpg" alt="" title=""></div>
              <h2>LEATHER BLAZER JACKET WITH ZIP POCKETS</h2>
              <p>$230</p>
              <div class="overbox">
                <div class="cart-bag"></div>
                <div class="heart"></div>
                <button class="title overtext"> Quick View </button>
                <div class="tagline overtext"> $230 </div>
              </div>
            </div>
            </div></div>

    thank you so much

    Thread Starter rashmirai

    (@rashmirai)

    got it! i added the classes in content-product.php and wrapper at loop-start.php and closed it at loop-end.php

    added an image wrapper by using the following code:

    remove_action( 'woocommerce_before_shop_loop_item_title', 'woocommerce_template_loop_product_thumbnail', 10);
    add_action( 'woocommerce_before_shop_loop_item_title', 'woocommerce_template_loop_product_thumbnail', 10);
    
    if ( ! function_exists( 'woocommerce_template_loop_product_thumbnail' ) ) {
        function woocommerce_template_loop_product_thumbnail() {
            echo woocommerce_get_product_thumbnail();
        }
    }
    if ( ! function_exists( 'woocommerce_get_product_thumbnail' ) ) {
        function woocommerce_get_product_thumbnail( $size = 'shop_catalog', $placeholder_width = 0, $placeholder_height = 0  ) {
            global $post, $woocommerce;
            $output = '<div class="product-wrap">';
    
            if ( has_post_thumbnail() ) {
                $output .= get_the_post_thumbnail( $post->ID, $size );
            }
            $output .= '</div>';
            return $output;
        }
    }

    Exactly what I needed to set a minimum height for the area around product catalog images (with modified CSS, of course). Thank you!

    Hi, this isn’t working on the latest version of WooCommerce, it adds the DIV and removes the image!

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘WooCommerce insert div classes around catalog thumbnail images in loop’ is closed to new replies.