Print a product attribute in the product loop with {{post.attribute}} syntax - timber

I'm trying to print a product attribute in a WooCommerce products loop.
I'm currently doing it this way:
{{post.terms('pa_producer-name')|join(', ')}}
But I was wondering if there was a way to extend the PostQuery class so that I could have it available as
{{post.producer}}
Thanks!

Related

Differences between WooCommerce price filters

First of all, thank you for your support all those years.
I am building a role-based pricing plugin for a client and I am having an existential crisis over filters WooCommerce uses for prices. I made this post in hope someone can explain this so someone in the future can find this post.
I managed to understand how filters for simple products work but I don't have an idea how equivalent filters for variable products work
Simple products
As from what I understood, you can override price, regular price, and sale price for simple products returning some value inside filters woocommerce_product_get_price, woocommerce_product_get_regular_price, and woocommerce_product_get_sale_price. Those filters will save provided data into $product object and you can easily access them later in woocommerce_get_price_html filter by using $product->get_regular_price
Variable products
Looks like variable products work differently. For example, they dont save overriden price to $product or $variation object and you cannot fetch overriden prices by calling $variation->get_regular_price.
As I understood, following filters change price of the product on add-to-cart variation select, and in the cart and do not save them in $variation object.
woocommerce_product_variation_get_price
woocommerce_product_variation_get_regular_price
woocommerce_product_variation_get_sale_price
I didnt manage to fully understand what following filters do. But when I turn them on loop price changes and product price changes but prices are removed from add-to-cart select and cart prices are not changed.
woocommerce_variation_prices_price
woocommerce_variation_prices_regular_price
woocommerce_variation_prices_sale_price

show added to cart message in woocommerce

As mentioned above I want to display "product added to cart message" in woocommerce.
I know there is some kind of built in function
wc_add_to_cart_message()
If I paste it in index page together with
wc_print_notices();
Like this:
wc_add_to_cart_message('products');
wc_print_notices();
wc_add_to_cart_message('products');
wc_print_notices();
then my current output is:
“” has been added to your cart.
My desired output is that it would return that particular product name together with a message.
but what would be the proper way of using it?
Or is there some other way?
In that function you actually have to give product id or array of product ids, so your line should look like:
wc_add_to_cart_message($product_id);

Custom loop for getting products flagged as new

I was looking for a way to build a custom loop to get the products flagged with the "new" label.
I could use the sort from the insert time, but that would always include a certain number of products, my goal here is to get those products that conform to the WooCommerce setting that says the product is considered new for a given number of days.
i have a free plugin - WooCommerce Product Badge, it has your requested feature to display "New" label with certain days defined.

Drupal Commerce Products for printing company

I'm new to Commerce I hope some kind fellow could give me some directions here.
I am creating an ecommerce website for a printing company. I will give an example of what I require
For instance they will offer A6 flyers but these come in different specifications each with differing prices
Here is an example:
http://4frontdesigns.co.uk/Untitled-1.jpg
So down the left column are quantities of flyers and along thw top different speciifications of those flyers with the prices shown in the middle.
Any help much appreciated
Can I just add each variation of these one by one as it is not possible to just say that a certain additional attribute to the product will add so much $$ to the base price.
Would I just add each variation one by one then some how pull these all into one display?
You could use the commerce price table module like Flo suggested or look at the Price attributes Module https://www.drupal.org/project/commerce_pricing_attributes
It uses option sets and then add to (or subtract from) the price based on the selected attribute.
The answer for me was to create each product variation as its own product. So every variation gets added as a separate product.
If you are wondering how to add different variations to product such as paper size or colour, you would do this with taxonomy. Simply create a taxonomy term called colour and then add all the colours into this term that you would require.
Then when you create your product type in commerce, you would add this as an option to choose from when adding products by doing the following. Go to manange fields for the product type you want to add it for and add a new field, type of data = term reference. You will then select the desired taxonomy term and also there will be an option to 'Enable this field to function as an attribute field on Add to Cart forms.' - You want to select this!
Then what you do is create a product display and pull all these in to a single page, which then gives you drop down options to change, and the price changes accordingly in real time.
You can create a product display by creating a new content type first, call it product display... Then add a field to this content type which is a 'product reference'.
Now add new content, pick to create a product display (what we have just created) and choose the products that you want to appear on that page.
Then automatically Drupal Commerce will take care of the rest. Hope this helps someone!

Use Wordpress custom post in a contact form

I have created custom post type "Product" in Wordpress and I would like to use Products within my contact form. For example, I would like to have a drop down that is a list of all of my Products so users can select a Product name as the message's Subject. I have Contact Form 7 installed. Is there an easy way to do this?
Thanks !
I think the short answer is no. There is not an easy way to do this. The Contact Form 7 plugin uses shortcodes to construct the select lists. What you need to do is run a query on your Posts -> Products and generate your own select list. I suppose what I would do is write my own shortcode function. Then you can include it in your page.
[myProductsShortCode]
Then you can iterate through that result set and generate your own select list.
http://codex.wordpress.org/Shortcode_API
http://codex.wordpress.org/wpdb#query_-_Run_Any_Query_on_the_Database
People seem to be able to add custom information like that, from
function test_generator() {
/* need to produce html like this:
<span class="wpcf7-form-control-wrap menu-645"><select name="menu-645" class="wpcf7-select"><option value="one">one</option><option value="two">two</option></select></span>
so here we go: */
$list = "<span class=\"wpcf7-form-control-wrap menu-test\"><select name=\"menu-test\" class=\"wpcf7-select\"><option value=\"test1\">test-1</option><option value=\"test2\">test-2</option></select></span>";
return $list;
}
wpcf7_add_shortcode('test', 'test_generator');
and then just use [test] in the contactform

Resources