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.
Related
I have multiple product attributes with the same name and same terms but different slugs. That's a result of a migration from Shopify to Woocommerce. For example, attribute 'Μέγεθος'('Size' in Greek) entered 2000 times for each product. Now i don't know how to combine those to one attribute with all terms like S,M,L,XL,44,45,56 etc.
Unless i edit product attributes one by one, is there a most sufficient option? Any suggestion?
Screenshot
For example, the grouped product container will have a generic name like (Car engine set) and then its SKU, product image, and taxonomy are to be pulled from the first linked product.
Struggling to find any examples online, any help would be appreciated :)
I am using the WooCommerce CLI to import a CSV with products into WooCommerce. That works, except that I can't figure out how to create the new categories for the imported products.
my products are stored in the $product array. The $product['category‘] is a string with the category name.
wp wc product create --sku="'.$product['sku'].'" --type="simple" --name="'.$product['name'].'" --regular_price="'.$product['price'].'" --categories="'.$catid.'" --images="{'.$product['image'].'}" --user="'.$user.'"
At first I tried to use the category name unless I figured out that the --categories param needs an integer (or maybe a JSON-Object, according to another post).
Because of that I am using the following code to save the current category id into a variable to use in product create (the categories and articles are in an loop). But it does not work as integer (--categories=12) or as JSON-Object [{"id" : 12}].
$cat = shell_exec('wp wc product_cat create --name="'.$product['category'].'" --porcelain --user="'.$user.'"');
Just to wrap it up. At the moment the order is like that:
Create categories and save the current category id to $cat (works)
Create a new product (works) except, that the category is not set. It's marked as "uncategorized".
I know, I could load the article afterwards to set the category. But I think that's a bit messy.
Got it! The problem was the quotes. Escaping the double quotes in the object did the job.
[{\"id\" : 12}]
I'm looking for a way to show a custom page with products on it. This is the case:
In an older version of the webshop there were 2 pages. The first one was 'promoties.html' for Dutch and 'promotions.html' for English. They were in the table pp_core_url_rewrite like this:
The category 13 was a category named promotion and all linked products to this category where promotion products.
The categories in the new version are changed and we don't have promotion category anymore. We can now set an attribute named promotion of an article to true or false.
But now I would like to know how I can make the promotion pages work again with selecting all the products where the attribute promotion is true. But I don't really know how to start with this, can anybody help me on my way?
As i think you know how to create product attribute using admin panel in magento. Create a promotion attribute of a product first .Then Using the query update the product attribute to true or false in previously created products as required .Then you can show the products on the basis of that attribute in promotion pages store wise.
I am currently creating a store using WooCommerce, and as part of that I have set up a function to add a 'New In' category to every new product that is added (this is so that i can use WooCommerces built in category listing page to display items that have been added most recently, setting this page to automatically sort by newest item).
I have also added a function that hides this category to all users, as they have no need to know that this category has been added, however, it does not remove it from the category column in the product listings. It is removed everywhere else, and all works. I wondered if there was a way to get the information from the column and filter it prior to display? So that I could remove the unwanted category. As you can see from the picture below, the 'New In' category is displaying here. It does not display anywhere else.
Cheers
Andy