In my admin for part i have additional fields (like price or brand - which is taxonomy). When i edit or create new part, i set up additional data.
and price saving is without any problem, but saving value from select list is something strange - it didn't save:
wp_set_object_terms($post_id, $_POST['part_brand'], 'brands', true);
according to wp doc: this function update value from taxonomy select. But for me it didn't work.
All code you could see here:
http://pastebin.com/N4gZL3uN
how to save value from select list (taxonomy) in wp?
i see that it didn't display selected value, why?
Related
I am trying to filter ~30,000 products in a WooCommerce store using WooCommerce's Layered Nav attribute filter sidebar widget. This requires the use of a pre-defined product attribute taxonomy, as opposed to using custom attributes on a per-product basis.
Each product in the store has an imported custom 'Brand' attribute. Prior to importing products, I created an attribute taxonomy called 'Brand' (pa_brand) in wp-admin. However, imported products have not had their Brand attribute (and term name) added to the Brand (pa_brand) taxonomy. Instead, all of the products have a custom attribute called 'Brand' not linked to the pa_brand taxonomy.
Does anyone know how to convert custom product attributes into defined attributes within the pre-defined taxonomy (with terms not yet created)?
I assume that I'd need to run a PHP script which does the following, but don't know if I've missed any steps out:
Obtain an array of ID's for all of the products in the database
Loop over each of the product ID's (foreach)
get_attributes() from each product ID - this will return the custom 'Brand' attribute (there are no pa_brand assignments yet)
Check: If the brand term already exists in the pa_brand taxonomy, do nothing; if it doesn't, add the term to the pa_brand taxonomy
Assign the product to the term within the pa_brand taxonomy
Delete the old custom Brand product attribute
I'm not sure how best to execute this, so any help would be very much appreciated.
PS: to illustrate the distinction between 'custom attributes' and attributes defined in a taxonomy, I have added 2 screenshots below of how they differ when editing a product in WooCommerce. Note how the name of the attribute can be altered if not from the defined taxonomy.
Attributes defined in taxonomy:
Custom attributes:
Thanks
It looks like someone has done this before - https://gist.github.com/birgire/0ed300ae4436fcaf508c
just to help anyone that comes to this page sharing the same problem. Custom attribute to global (taxonomy), variations, etc...
How we solved it easily:
We created the same name of the Custom Attribute as a Global Attribute (Brand => Brand). No need to add terms, just attribute Name.
Downloaded (Export) all the products as CSV file on the All Products table page.
On the CSV file (opened on Excel) make sure to set Attribute n global (n is the number of attribute, 1, 2, etc...) to 1 (when it's custom it will show 0). Do this on all rows that have the attribute you are converting.
To make sure Variations also saved and that attribute can be used make sure that Attribute n visible is also set to 1 on all rows.
Save the file.
Next go back to your All Products page and click on Import.
Choose the file and check the box that says "Existing products that match by ID or SKU will be updated. Products that do not exist will be skipped.".
Next click on Run the importer button.
This will convert all the custom attributes with their terms into global, and also keep all the variations. No need for any coding or hard work.
For the steps 3 and 4 you can use formula like this one =IF(AN2="Flavors","1","") for the first line and copy paste it to all rows to do it automatically for a specific attribute if needed.
Hopefully this will help you.
I have a Question regarding Product attributes.
Generally Products attributes display in a drop down, when you select attribute from the drop down it will show an add to cart button. This is the Woo-commerce default flow of attributes.
Now my question is that I don't like to display attributes in a select box. I would like to display as my layout.
For example, we have size attributes in Product and that will display in the select box, but I want to display in circle designs. I don't want to display as a drop down.
Yes you can do this. you can get all your product variations using
$product->get_available_variations() It'll return an array containing all your product variation data. When user selects an option woocommerce updating an input value with the selection. It's a hidden input in your source. You need to find that input field and update it's value. I normally use jquery for that.
Hope it'll help.
Thanks.
I add new custom field to load my Books genres (taxonomy) in to my "writer" page (category).
look at my settings:
http://awesomescreenshot.com/0df4qucud7
I need to show the checked genres on my writer page.
Of coure if theres no checked genres the code shows nothing (IF tag).
How can I get the values?
ACF Plugin: https://wordpress.org/plugins/advanced-custom-fields/
You are getting the term ID's of the selected genres.
With the ID you can get a field like so get_field('field_name', 'genre-cat');
In this situation the genre-cat can be replaced for the output of your field with the term IDs (you would have to do this for each term selected, so use the foreach statement).
See full documentation from ACF on how to get values from a taxonomy term: http://www.advancedcustomfields.com/resources/get-values-from-a-taxonomy-term/
I have a Magento based site and Products are limited to Set of Pin codes. These PIN differ from product to product. What I need is to get an option to input set of PIN Codes, while defining a product. And on every product page there must be a Text field to check whether the product is available for the PIN Code, which is entered by the visitor.
HI For this first of all
1 create a new product attribute with multi-select type
2 assign all pin codes in there values under attribute options
3 assign that attribute to the desired attribute set
4 than for assigning attributes you need to go to product section and assign a desired zip options for that particular product from the multi-select attribute
5 on product page you need to problematically get all the selected values of that attribute
6 create a array of that values
7 create a simple form and when user post some value in that form , match that value in the array you defined above.
8 if the value finds in array than show the cart button and if not do what you want.
i hope this will give you a very fair idea. Let me know if i can do any other thing for you.
I have a little question
I have already added an extra field to my product table and this is working very well.
What I want:
But now I want to add an extra field to the ps_product_attribute table and display it below the price depending on the attribute that is selected by the customer.
A little more info:
When you use the Prestashop combinations you can add a reference to every combination. When the customer changes the combination, the reference name is automatically changed (refreshed?) on the product page. So the displayed reference name is depending on the choice of combination the customer is making. This is working fine.
Now just like this I want to display my extra field from my ps_product_attribute table below the price. The extra field is containing a specific price unit that is depending on the attribute choice.
My problem:
I have already added the extra field to the database table (ps_product_attribute) but I do not know how I can display this on on the product page
and
how the value is refreshed (or changed) when the customer selects another combination.
I hope you understand my question. Any help would be grateful.