Check Selected Woocommerce Product Variation Name for String - woocommerce

Quick question, how can I check Woocommerce product variation name for specific string on a product page, so I could display custom message?
Let's say I have a product variation with a name "Stack Overflow", how on a product page can I check if the customer selects it to then display custom message?
I know I can have custom descriptions for each variation, but when you have 1000+ it takes forever to change all of those, so instead I would simply like to code it globally so a specific message would display when customer selects specific variation.
For example, let's say I have "large, medium, small", so when they select "large" it'll display my message.
I tried to use get_term_by with no luck.

Related

Make woocommerce product attribute unremovable?

I have a problem with my Woocommerce. I use my supplier's plugin which very regularly and automatically updates the stock and price of my products. I can, on my supplier's site, request that the product updates of their API linked to my site via their plugin do not erase the titles and descriptions of the products (I modified some of them after adding them ).
Problem: I must add to my products an attribute (example "Color") which is not assigned to them by default (they have two but it is not "Color".)
I can add this attribute to them and define a particular color for them, but when they are updated by my supplier, it overwrites the attributes that were not on my basic products (here the "Color" attribute) .
I wish I could tell their API not to overwrite it, like title or description, but they don't know how to do that..
Do you have an idea ?
I got a start of the trail thanks to this page: https://datafeedrapi.helpscoutdocs.com/article/44-prevent-attributes-from-being-overwritten-during-product-set-updates but the code is for THEIR API and so that the value of an attribute is not erased. For me, it's the ENTIRE attribute that I want to preserve..
Thank you !

Attributes not showing to choose in woocommerce

At my product page, when I go to Product Data, select “Variable product” and then click on “Variations” I get the message, “Before adding variations, add and save some attributes on the Attributes tab.”
enter image description here
So… I went to the Attributes tab, created an attribute titled ‘Colors’, and ‘Size’.
enter image description here
With those saved, I went back to my saved product, went back to “Product Data”, selected “Variable product” and clicked on, “Variations”
But there I again see that message "Before adding variations, add and save some attributes on the Attributes tab.".
After you've added your global attributes (Products › Attributes), you still need to select those attributes from the Attributes tab on the product edit page. You'll then be able to set up variations for a product.
Go to: Products › Add Product (or edit an existing one).
Select the Attributes tab in the Product Data. Use the dropdown menu to choose any of the global attributes that you’ve created.
Select Add to make the attribute type available for variations
Select the terms that you want to use for this product's variations (I've selected Black and White in the screenshot below).
Check Use for variations
Click Save attributes
You can now set up variations within the Variations tab

Woocommerce: Customizing the availability of a category

I have many products nested within parent categories in WooCommerce.
I want to be able to apply a custom field where I can specify a time availability for categories as a admin feature only in Back end.
Theory:
Back end - On each parent category I will have this custom field where I can type or choose a time frame: for example 11:00-17:00.
Front end:
During this time frame, users will be able to browse all the products within that category.
Outside of this time frame all the products within that category will stay visible (but inactive) and they will be displayed greyed out or with a 'closed' banner (something like that).
Where can I start with this?
THE BEGINNING
You can start adding 2 plugins to add a custom time picker on product categories admin pages:
Advanced custom fields (ACF) plugin
Date & Time Picker for Advanced Custom Fields or also Date and Time Picker Field
This is just he beginning (and I can't confirm that is the best way). So In ACF you create a group and you name it:
Then you set the location (It's going to be a "taxonomy term" for "Product categories"):
Then In options you can chose it like a Metabox on the side (on backend):
After you add a new field and name it. You chose the field type and time only option:
[
Then now you are going to compile all the other options to fit your needs. Then you can save and add, if you need a 2nd field…
Now if you go to the WooCommerce Products Menu, under categories submenu, you will get this:
Now you can read a little the ACF documentation and also the wooThemes/woocommerce dev. documentation too.
You can customize WooCommerce overriding the templates and use hook filter and actions.
You will find in here on Stack OverFlow and over internet a lot of code, examples and tutorials, to begin and try to achieve your project. When needed you will post questions to get helped, with the code you are using telling what is working and what not…

Use extra fields in ubercart add to cart form

I am trying to implement hotel booking functionality in a Drupal 7.26 website. Customers will choose hotels from a listing page and then they will select rooms within the hotel.
I decided to use UberCart 3 for my booking mechanism.
First I implemented 'Hotel' as a Ubercart product. But a hotel is connected to rooms, each type of room has a different price. Using product attributes, I designed room type as an attribute, with each room type having a different price. So far so good, but I could not select multiple instances of any single product attribute, so I abandoned using Product Attributes.
Then I decided on this different approach. I decided to keep the room type information inside the hotel product type, using field groups.
Here's how it looks in the add content page:
Using some view templating, I managed this look in my booking page. This look is exactly how my clients want (apart from the css anyway). I am getting to book multiple instances of a room.
However, when I click on any 'Add to cart' button, Drupal does not detect that which room type was selected. I modified the rendered markup of the Add to cart form (using tpl files), and added a hidden field called roomtype for each add to cart button. So for the first button, roomtype = 'double', and for the second button, roomtype = 'single'.
My idea was to
use hook_uc_add_to_cart,
then process this roomtype value, and
then compute the price of that roomtype,
then update the price of the cart item,
and then redirect to cart page.
But hook_uc_add_to_cart provides only quantity, node id and a data variable. None of these gives me the value of the roomtype hidden field.
How do I use my hidden fields in my uc_add_to_cart hook?
Try this:
http://drupaldeveloper.in/codelet/drupal-add-product-field-cart-ubercart
This code has similar solution.
Regards.

woocommerce: how to add new fields to variations form and show them on frontend

using last versions of wordpress, woocommerce and cheope (theme).
the question: how to
add some extra fields in variations form (text and image field types)
show them on frontend so that their values change accordingly on changing of attributes-select values.
e.g.: the site sells candles and uses variable products, for each kind of candle has several dimensions (with specific different prices), each of which has different duration.
The duration is an important element that I want the user to be informed about.
The same to show the available colors all together.
Unluckily in the standard variation form there is no field where I can insert these or other features.
some help please?
updated 07-August-2013
I succeeded in adding to variations form a new field displayed on back-end, as you can see here, by inserting the code you can find here (please see the comments too) in the function.php file of the theme.
Now, what I’m not able to do is get this field to display with each proper value on front-end (please take a look to the last comment in the above linked page).
Any tip or trick?
thanks
1)Add product attribute and check checkbox Used for variations and Visible on the product page
2)go to variations and add new and fill all fields price and stock must add on them
Your producr display variations and their data

Resources