[Resolved] Get Template Part in Custom shortcode

Home Forums Support [Resolved] Get Template Part in Custom shortcode

Home Forums Support Get Template Part in Custom shortcode

Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
    Posts
  • #775396
    Shield one,

    Hi, i am calling:

    wc_get_template_part( 'content', 'product' );

    in my custom shortcode, and everything work correct, but only image wrapper (with class wc-product-image) which is normally added by GP Premium is missing.

    As image wrapper i think this:
    Sni-mka-obrazovky-2019-01-07-o-17-18-32

    My code:
    Sni-mka-obrazovky-2019-01-07-o-17-14-15

    can you help me?

    #775730
    Tom
    Lead Developer
    Lead Developer

    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
    #776594
    Shield one,

    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.

    #776729
    Tom
    Lead Developer
    Lead Developer

    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?

    #777005
    Shield one,

    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?)

    #777392
    Tom
    Lead Developer
    Lead Developer

    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.

    #779059
    Shield one,

    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 );
        } 
     }
    #779324
    Tom
    Lead Developer
    Lead Developer

    Glad you found a solution!

Viewing 8 posts - 1 through 8 (of 8 total)
  • You must be logged in to reply to this topic.