Archived topic
Get Template Part in Custom shortcode
7 replies · Started by Shield one, on January 7, 2019
Hi there,
Those elements are added using these hooks:
add_action( 'woocommerce_before_shop_loop_item_title' , 'generatepress_wc_image_wrapper_open', 8 );
add_action( 'woocommerce_shop_loop_item_title' , 'generatepress_wc_image_wrapper_close', 8 );
So make sure these hooks exist in your template:
woocommerce_before_shop_loop_item_title
woocommerce_shop_loop_item_title
I think that this should be part of template which i am calling - product content?
But i did not changed this template so default one should be called. So same as when i show shop page. And in shop page it is ( this html wrapper).
I saw this actions which you sended. But i don't understand, why it is not applied also when i am calling this template.
Yes, it should be: https://github.com/woocommerce/woocommerce/blob/d0491072e8a7d0a4535db0ec2bae4a6d43ff64fd/templates/content-product.php#L42
Just to confirm, is the archive image option checked in Customize > Layout > WooCommerce?
Sure, it's setted.
As I say, on most of the places it is showing properly. But in Category Page, I have custom filtering which will load produts through ajax. And on the server side there is called product content template part. So I think, that different template is loaded. Or your hooks are not applied.
So now i tried to make small test. I added some custom text to this content product template. And it is showing properly in both version (also in category page - where is also img wrapper included, and also after filtering with ajax). So same template is loaded, only hooks are not applied when i am calling template from php through ajax. (maybe ajax is problem?)
That could be the issue. You might need to manually add the HTML elements into the product template.
For example, this would be under the woocommerce_before_shop_loop_item_title hook:
echo '<div class="wc-product-image"><div class="inside-wc-product-image">';
And this would go under the woocommerce_shop_loop_item_title hook:
echo '</div></div>';
Of course, this means you'll want to pay attention to updates in case we change something that affects the markup.
This solved my problem:
add_action( 'woocommerce_before_shop_loop_item_title', 'woocommerce_remove_thump_wrapper', 1);
if ( ! function_exists( 'woocommerce_remove_thump_wrapper' ) ) {
function woocommerce_remove_thump_wrapper() {
remove_action( 'woocommerce_before_shop_loop_item_title' , 'generatepress_wc_image_wrapper_open', 8 );
remove_action( 'woocommerce_shop_loop_item_title' , 'generatepress_wc_image_wrapper_close', 8 );
remove_action( 'woocommerce_before_subcategory_title' , 'generatepress_wc_image_wrapper_open', 8 );
remove_action( 'woocommerce_before_subcategory_title' , 'generatepress_wc_image_wrapper_close', 20 );
add_action( 'woocommerce_before_shop_loop_item_title' , 'generatepress_wc_image_wrapper_open', 8 );
add_action( 'woocommerce_shop_loop_item_title' , 'generatepress_wc_image_wrapper_close', 8 );
add_action( 'woocommerce_before_subcategory_title' , 'generatepress_wc_image_wrapper_open', 8 );
add_action( 'woocommerce_before_subcategory_title' , 'generatepress_wc_image_wrapper_close', 20 );
}
}
Glad you found a solution!

