Last active
July 31, 2022 23:37
-
-
Save MogulChris/c4b34d655657bfaac1cc038d6d05956f to your computer and use it in GitHub Desktop.
Hooking into the native WooCommerce product import
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
//Since 3.x WooCommerce has had an excellent native product import/export. | |
//You can do a huge amount just by tweaking your CSV to load meta values into the correct meta fields for your destination site. | |
//It'll even import images from the source site by URL if possible, and upload them to the destination site. | |
//If you need to do something a little fancier for every product you import, check out the woocommerce_product_import_* hooks here https://woocommerce.github.io/code-reference/hooks/hooks.html | |
//You can modify the CSV data before it's used, and modify the resulting WC_Product during and after creation | |
//eg do something to every product after it's created | |
function mytheme_add_product_content($product, $data){ | |
//$product is a WC_Product | |
//$data is an array of data pulled from the CSV | |
}//mytheme_add_product_content() | |
add_action('woocommerce_product_import_inserted_product_object', 'mytheme_add_product_content',10,2); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment