
Woocommerce / WP All Import
- or -
Post a project like this€25/hr(approx. $29/hr)
- Posted:
- Proposals: 13
- Remote
- #3171022
- Expired
PPH Top 1% WordPress | Shopify | PHP | UI/UX | iOS/App | SEO |CRO| Webflow | Wix | Web Development

Top Service Provider Web Development|Wordpress|Shopify |Magento|Mobile App Development|Digital Marketing
UK'S No.1 - Wordpress|Magento|PHP| Responsive | PSD to responsive html | All Time Top Rated freelancer on PPH | 100% client satisfaction | Ecommerce | SEO




1460852227480429204851222431338350330000851184713114743333817113529955074061612431





Description
Experience Level: Intermediate
Woocommerce / WP All Import: automatically add product to category if product name contains the category name.
When import with wp all import from xml/csv/json file, i want to automatically add products to a category if their name contains the category (for example the product name is: iPhone X case, the product should automatically be added to the category iPhone->iPhone X case)
Example:
Load all product categories via get_product_categories( $fields );
https://woocommerce.wp-a2z.org/oik_api/wc_api_productsget_product_categories/
Use get the product name to find the name of the product
https://woocommerce.wp-a2z.org/oik_api/wc_productget_name/
Loop through the categories and compare (https://woocommerce.wp-a2z.org/oik_api/wc_productget_name) each of them to the product name. Depending on situation and what values are in product category title or product names, need to use a regex for this (https://medium.com/factory-mind/regex-tutorial-a-simple-cheatsheet-by-examples-649dc1c3f285)
When done, code should look something like this:
$product_category_list = $product->get_categories();
$product_name = $product->get_name();
$categories_to_put_product_in = array();
foreach($product_category_list as $current_category) {
if (strpos($product_name, $current_category->term_id) !== false) {
$categories_to_put_product_in[] = $current_category;
}
}
$product->set_category_ids($categories_to_put_product_in);
Do it via API: http://www.wpallimport.com/documentation/developers/action-reference/ (see the 'pmxi_saved_post' hook). Strongly suggest that cache the category list in an option (https://codex.wordpress.org/Options_API) so that not querying all of the product category terms every time a post is saved.
When import with wp all import from xml/csv/json file, i want to automatically add products to a category if their name contains the category (for example the product name is: iPhone X case, the product should automatically be added to the category iPhone->iPhone X case)
Example:
Load all product categories via get_product_categories( $fields );
https://woocommerce.wp-a2z.org/oik_api/wc_api_productsget_product_categories/
Use get the product name to find the name of the product
https://woocommerce.wp-a2z.org/oik_api/wc_productget_name/
Loop through the categories and compare (https://woocommerce.wp-a2z.org/oik_api/wc_productget_name) each of them to the product name. Depending on situation and what values are in product category title or product names, need to use a regex for this (https://medium.com/factory-mind/regex-tutorial-a-simple-cheatsheet-by-examples-649dc1c3f285)
When done, code should look something like this:
$product_category_list = $product->get_categories();
$product_name = $product->get_name();
$categories_to_put_product_in = array();
foreach($product_category_list as $current_category) {
if (strpos($product_name, $current_category->term_id) !== false) {
$categories_to_put_product_in[] = $current_category;
}
}
$product->set_category_ids($categories_to_put_product_in);
Do it via API: http://www.wpallimport.com/documentation/developers/action-reference/ (see the 'pmxi_saved_post' hook). Strongly suggest that cache the category list in an option (https://codex.wordpress.org/Options_API) so that not querying all of the product category terms every time a post is saved.

Milan B.
100% (1)Projects Completed
1
Freelancers worked with
1
Projects awarded
0%
Last project
25 Mar 2021
Serbia
New Proposal
Login to your account and send a proposal now to get this project.
Log inClarification Board Ask a Question
-
There are no clarification messages.
We collect cookies to enable the proper functioning and security of our website, and to enhance your experience. By clicking on 'Accept All Cookies', you consent to the use of these cookies. You can change your 'Cookies Settings' at any time. For more information, please read ourCookie Policy
Cookie Settings
Accept All Cookies