• Resolved jason9j

    (@jason9j)


    Hi

    In my quest to reject the bloat of page builders by no longer using them, Iā€™m making some manual customizations to WooCommerce PHP theme pages instead.

    Iā€™m trying to keep the customizations confined to one file: content-single-product.php.

    Iā€™ve put the file in the appropriate file structure within my child theme. All good.

    Iā€™m using a combination of calling on native WordPress code, and also embedding ACF fields with PHP, inside my own HTML structures.

    I know some code, but I donā€™t know PHP.

    Iā€™ve been searching all day, but I canā€™t for the life of me figure out how to do the most fundamental thing:

    What is the syntax to simply call the following sections:
    * Product Reviews
    * Recommended Products, or Featured Products, etc.

    Looking at the first one, product reviews, I can clearly see which primary templates are involved with rendering product reviews (review.php and single-product-reviews.php).

    But my issue is this: What is the exact code for calling the product reviews to display in my custom HTML div inside content-single-product.php? I have no idea, and was not able to find any help relating to this. I imagine it is super short and simple, but I just donā€™t know it.

    I removed the product tabs (which usually houses the reviews) altogether, which is why I am adding the reviews separately as per my design, in my own custom HTML section. (The really odd thing to me is that when I view the template code for the Tabs, there is seemingly no reference to reviews at allā€¦..so there was no hint to be found there).

    I donā€™t want to do this in functions.php. I am happy to customize this one file, content-single-product.php, as it needs to be customized for many reasons.

    So, what is the syntax for achieving what I need to? And can I use the same syntax anytime I need to call other sections in content-single-product.php that have their own php file (like product recommendations/related products, etc?

    Iā€™d greatly appreciate some assistance hereā€¦

Viewing 8 replies - 1 through 8 (of 8 total)
  • Stef

    (@serafinnyc)

    Everything you need is inside the template files. This is your best spot for template structure and code to call to specific things.

    WooCommerce 4.9

    Depending on what theme you are using you can either use hooks or echo template parts

    Thread Starter jason9j

    (@jason9j)

    Hi Stef – thanks for your reply. It led me to the get_template_part() documentation, which I’m reading about now.

    There seem to be different levels of implementation, and similar related functions, and various opinions on it (upvotes/downvotes): https://developer.www.ads-software.com/reference/functions/get_template_part/

    I need a base point for my understanding. To use a real-life, specific example, do you know what the syntax would look like to show product reviews inside my own div in the file content-single-product.php?

    Stef

    (@serafinnyc)

    I wouldn’t use any kind of code on the page. I would use a hook before doing any copying of files over to your child theme. You’re just making more work for yourself.

    Read up on how to hook for WooCommerce

    With hooks all you do is add them to your child’s function file and control everything that way. If these don’t work for you then you’ll need to copy the file and add the code you need to add, but that wouldn’t be something we could help you here with. That’s custom work.

    This is a great resource for how to move things around and add them

    To echo the review file you’d do something like

    
     <?php
          woocommerce_get_template_part( 'single-product-reviews' );
     ?>
    
    

    And the same for the others

    Thread Starter jason9j

    (@jason9j)

    Hi Stef – noted. I think in a lot of cases, you’re right. If I need to append something to a general place (eg. Related Products appended to the bottom of the page), then you’re right. And I’m actually glad you reminded me and made me think about whether hardcoding every element is even necessary. You’ve definitely helped me out here.

    But if I need to create Bootstrap HTML structures so as to arrange parts for certain pages (single product, single post, etc), then I don’t see how hooks can help….but that could just be my inexperience.

    To take a standard WordPress example:
    Say I need a custom single blog post template. The top section of the page will have a feature image, a title, excerpt, meta, etc. To arrange that into the desired design and layout, that requires removing those elements from the template file copied to my child theme, and re-adding them within my desired structure. So editing the template file is the only way, I assume. Though I’d like to be wrong about this.

    So my biggest issue is actually how to call on those elements from the file, because although I know some coding, I am not familiar with PHP. I’ve just been trying to figure out the basic call syntax.

    Using that basic WP example again, I need syntax/snippets to:
    – Call on the post featured image
    – Call on the post title
    – Call on the post excerpt

    I can’t seem to find a simple answer (ie. code snippets) to put these in my theme file (ie. paste it into my own Bootstrap column according to my design) etc.

    Thread Starter jason9j

    (@jason9j)

    EDIT: I missed the code at the end of your post, sorry. Let me play around with that for a while…maybe that is the key. Thanks Stef.

    Stef

    (@serafinnyc)

    For that kind of layout you’ll be creating single page layout templates. You’ll need to learn how to layout those using a few different lines of code.

    That’s why I gave you the first link. If you study the native WC single template you’ll be able to create your very own single product page templates.

    Thread Starter jason9j

    (@jason9j)

    Excellent. You’ve been a huge help Stef. I’ll do some exploring and close the ticket after I’ve had a look around at the docs.

    Stef

    (@serafinnyc)

    You’re welcome. Enjoy ??

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘Custom single product page ā€“ syntax to call on other WC sections?’ is closed to new replies.