• So I read the post on the hook woocommerce_subcategory_thumbnail()
    doesn’t work with the plugin.

    I have a code something like this below. to get the child category from the current category archive page.

    $parentid = get_queried_object_id();
    $args = array(
    	'parent' => $parentid
    );
    $terms = get_terms( 'product_cat', $args );
    if ( $terms ) {
    	echo '<ul class="product-cat-items">';
    	foreach ( $terms as $term ) {
    		echo '<li class="product-cat-item">';  
    		woocommerce_subcategory_thumbnail( $term );
    		echo $term->name;
    		echo '</li>';	
    	}
    	echo '</ul>';
    }

    The above code does not work
    Then I change it to the below code And it doesn’t work either.

    $parentid = get_queried_object_id();
    $args = array(
    	'parent' => $parentid
    );
    $terms = get_terms( 'product_cat', $args );
    if ( $terms ) {
    	echo '<ul class="product-cat-items">';
    	foreach ( $terms as $term ) {
    
    		$size = 'thumbnail';
    		$thumbnail_id = get_woocommerce_term_meta( $term->term_id, 'thumbnail_id', $size );
    		$image = wp_get_attachment_url( $thumbnail_id );
    
    		echo '<li class="product-cat-item">';  
    		echo '<img src="'. $image . '">';
    		echo $term->name;
    		echo '</li>';	
    	}
    	echo '</ul>';
    }

    Any idea how it may work?

    Thanks

Viewing 3 replies - 1 through 3 (of 3 total)
  • Thread Starter theblueli

    (@theblueli)

    I’m seeing more and more reports of incompatibilities with specific themes, which suggests to me that more and more themes are doing things “their own way” rather than using the standard WooCommerce hook for outputting the category thumbnail.

    Just saw your reply from another thread. Would you care to share which one is the standard WooCommerce hook, so I can try it?

    Thanks

    Plugin Author gazchap

    (@gazchap)

    Currently my plugin deals entirely with the woocommerce_before_subcategory_title hook.

    First of all it removes the default action that WooCommerce uses in its templates:

    remove_action( 'woocommerce_before_subcategory_title', 'woocommerce_subcategory_thumbnail', 10 );

    And then it adds in its own replacement, which is what handles the random selection for categories:

    add_action( 'woocommerce_before_subcategory_title', array( $this, 'auto_subcategory_thumbnail' ) );

    So if your theme isn’t using woocommerce_before_subcategory_title, or is doing its own thing with that hook, it won’t work.

    Thread Starter theblueli

    (@theblueli)

    Hello, I am using Oxygen Builder for the site. So there is no Theme using. I build the template myself. I can modify the PHP as needed.

    I don’t really understand. In my case, I am using

    $thumbnail_id = get_woocommerce_term_meta( $term->term_id, 'thumbnail_id', $size );
    $image = wp_get_attachment_url( $thumbnail_id );

    to get the product_cat thumbnail image. Should it not suppose to work?
    Any ideas about what I am missing?

    Many Thanks!!

    $parentid = get_queried_object_id();
    $args = array(
    	'parent' => $parentid
    );
    $terms = get_terms( 'product_cat', $args );
    if ( $terms ) {
    	echo '<ul class="product-cat-items">';
    	foreach ( $terms as $term ) {
    
    		$size = 'thumbnail';
    		$thumbnail_id = get_woocommerce_term_meta( $term->term_id, 'thumbnail_id', $size );
    		$image = wp_get_attachment_url( $thumbnail_id );
    
    		echo '<li class="product-cat-item">';  
    		echo '<img src="'. $image . '">';
    		echo $term->name;
    		echo '</li>';	
    	}
    	echo '</ul>';
    }
    • This reply was modified 2 years, 4 months ago by theblueli.
    • This reply was modified 2 years, 4 months ago by theblueli.
Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘woocommerce_subcategory_thumbnail() Hook question’ is closed to new replies.