How to get the value of Template Layout File of product using handlebars on bigcommerce stencil theme? - handlebars.js

I want to get the value of "Template Layout File" in my product template. Based on this value, I have to print different values for the products.
I tried to get the value like this:
{{product.template_layout_file}}
I did not get any output.
As reference, kindly see the picture below:

A product's template layout file can be accessed in Handlebars with {{template}} while you're on that product's display page, note that "product" should be excluded since the template object isn't a subresource. Find more info about the template object on the dev docs here.

Related

Single product page with dynamic content according to product category

I need to update our product template with a new one. In this template, I have two sections whose contents will depend on the product category. My plan is to create different "Elementor Section Templates" for each category and then connect these templates to the product category and somehow display these sections on the single product page. I have created a child theme and can edit the theme's product template and put the demo sections to the page. However, there is a need for logic that I could not figure out. So in this context, my questions are the following:
How can I connect these "section templates" to "woocommerce categories/products"?
How can I use Elementor Pro's editor to create this dynamic logic?
How can I get $product php object when I use the elementor template builder? Is there a way to import this template into another php file to serve as single product template?
Is there an easier/more efficient way to create the templates and connect them to products/categories?
ps: I have elementor pro.
I created the template and import it to singelproduct.php file of the child theme. I can display the template however, the "category" object that I get from $product object is an array of different categories hence no clear way to use this data in an if/else statement.

Shortcode display product custom field value

In WooCommerce, I would like to display a table on a custom page with a list of (downloadable) products with their title and attribute / custom field values.
For the product title in the first column of my table I'm using the following shortcode:
[product _name id="9"]
The code in my funcions.php file
function displayProductName($item) {
$productName = get_the_title($item['id']);
return $productName;
}
add_shortcode('product_name', 'displayProductName');
In the second column I'd like to display the value of a custom added field (with advanced custom fields): field is File Version (slug file-version), value is 1.22
I can't seem to figure out how to translate this into a working function.
So what I would like is to display the value of a custom field based on a single product ID on a random page with a shortcode.
Any ideas would be very appreciated.
After doing more research, I managed to find the solution, which was much easier than I thought.
Since I'm using Advanced custom Fields, I could use their shortcode.
So for example, I have custom field Download Version (slug: download_version) that I use for downloadable products.
To display the value of Download Version for a specific product, on a random page, I used the shortcode
[acf field="download_version" post_id="9"]
Where the product ID is 9.
Maybe useful for other users who want to do the same...

Display all custom attributes Woocommerce

I'm working on a project where I want to display product's image and customs attributes from Woocommerce.
I already set attributes like this
I want in my php code display all the attributes (title et terms).
I already try <?php $product->list_attributes(); ?>. It works fine but data are displaying in <table>. I want to customize the display.
Thanks for your help !
Whenever I get stuck with a custom method like this in WooCommerce, I try to resort to the docs to see what is going on.
If you inspect the source for this method, you'll find that it's actually using a custom template single-product/product-attributes.php to output this table you're seeing.
In order to change the output, you have two options:
Override the template via your theme
Observe single-product/product-attributes.php and use the information there to write your own custom loop in your original template.
The second option means that you'll likely use the get_attributes() method, instead of list_attributes().

Wordpress getting template for post category type to work

Hiall,
In my wordpress site I have a Category called “meetings”, and it’s slug is “meeting”, also its ID is 27.
I create a default post article and then select “Meeting” from the categories panel and then publish etc.
Reading here
http://codex.wordpress.org/Template_Hierarchy#Custom_Taxonomies_display
If I create a template file called category-meetings.php or category-27.php then it should pick those files up and use them for a template layout for my selected Meeting category posts etc???
But for whatever reason I can not get it to do this.
I have also tried changing the permalinks settings from “post name” to custom structre with /%category%/%postname%/
but again no luck.
Am I missing something here?
Any help would be great!
I think you're trying to target a single post, whereas your template is targeting the category archive pages. For example, look at this diagram of the template hierarchy.
You could:
1) Create that post as a page and then create a template just for that page.
2) Create a custom post type and create a custom template for that custom post type.
The naming has to match your slug. I would change
category-meetings.php
to
category-meeting.php
And make sure the category-customname.php files are in the same directory as the default category.php file.
Addition/Revision
For a custom page for a single post -- find the post number, let's say 999, then create a single page with the past number appended to the file name in the same directory where the single.php file exists. This worked up to WP ver 3.2-ish. Unless it's been deprecated, it should still work.
single-999.php

How do I display individual fields in a custom block?

A have a view created with Drupal's Views module, and have given it a Block display. It has the following fields:
first_name
last_name
professional_title
I understand that I can create a "[viewname]-block.tpl.php" file to provide a custom theme for this particular block, overriding the generic block.tpl.php template file. Within this [viewname]-block.tpl.php file, how can I pull out individual fields (eg, First name) so that I may theme them individually, giving them different classes? I've taken a look at $block, which yields $block-content, containing all fields, but this is as granular as I have managed to go so far.
Any help is appreciated.
Go into the Views UI and navigate to the block view you're trying to theme.
Under basic settings (at the bottom of it in fact) you'll see a Theme Information link. Click it.
I'm copying and pasting the official description of what that does:
"This section lists all possible templates for the display plugin and for the style plugins, ordered roughly from the least specific to the most specific. The active template for each plugin -- which is the most specific template found on the system -- is highlighted in bold."
So find the template for the field you want to theme and click the link for it - you'll get code to copy and paste. The code will be really generic, but there are notes in the generated tpl file about how to pull more specific object data.
Hope that helps

Resources