Last active
March 1, 2021 09:42
-
-
Save AleStranieri/6317355 to your computer and use it in GitHub Desktop.
PROBLEM: Attribute's variation need to be activated manually after import
SOLUTION: This patch actives attribute's variation when you import generic product in WooCommerce usign WP Ultimate CSV Importer Plugin, so you can import all product's variations using the same plugin
This file contains 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 | |
/* | |
__/\\\\\\\\\\\\\______/\\\\\\\\\______/\\\________/\\\_____/\\\\\\\\\_____/\\\\\_____/\\\_ | |
_\/\\\/////////\\\__/\\\///////\\\___\///\\\____/\\\/____/\\\\\\\\\\\\\__\/\\\\\\___\/\\\_ | |
_\/\\\_______\/\\\_\/\\\_____\/\\\_____\///\\\/\\\/_____/\\\/////////\\\_\/\\\/\\\__\/\\\_ | |
_\/\\\\\\\\\\\\\\__\/\\\\\\\\\\\/________\///\\\/______\/\\\_______\/\\\_\/\\\//\\\_\/\\\_ | |
_\/\\\/////////\\\_\/\\\//////\\\__________\/\\\_______\/\\\\\\\\\\\\\\\_\/\\\\//\\\\/\\\_ | |
_\/\\\_______\/\\\_\/\\\____\//\\\_________\/\\\_______\/\\\/////////\\\_\/\\\_\//\\\/\\\_ | |
_\/\\\_______\/\\\_\/\\\_____\//\\\________\/\\\_______\/\\\_______\/\\\_\/\\\__\//\\\\\\_ | |
_\/\\\\\\\\\\\\\/__\/\\\______\//\\\_______\/\\\_______\/\\\_______\/\\\_\/\\\___\//\\\\\_ | |
_\/////////////____\///________\///________\///________\///________\///__\///_____\/////__ | |
Author: Alessandro Stranieri | |
Latest: 20130823 | |
URL: http://www.bryan.it | |
License: GPLv3 | |
License URI: http://www.gnu.org/licenses/gpl-3.0.html | |
*/ | |
/** | |
* REQUIRED: WooCommerce - excelling eCommerce - https://github.com/woothemes/woocommerce | |
* REQUIRED: WP Ultimate CSV Importer Plugin - http://wordpress.org/plugins/wp-ultimate-csv-importer/ | |
* | |
* PROBLEM: Attribute's variation needs to be activated manually after import | |
* SOLUTION: This patch activates attribute's variation when you import generic product in WooCommerce using WP Ultimate CSV Importer Plugin, | |
* so you can import all product's variations using the same plugin. | |
* Copy and paste the following code into your theme’s functions.php file. | |
* | |
*/ | |
add_action('set_object_terms', 'woocommerce_variation_attribute_active', 10, 6); | |
function woocommerce_variation_attribute_active($object_id, $terms, $tt_ids, $taxonomy, $append, $old_tt_ids) { | |
if (!$append) { | |
if (substr($taxonomy, 0, 3) == 'pa_') { | |
$attributes = array(); | |
$product_attributes = get_post_meta($object_id, '_product_attributes', false); | |
if (!empty($product_attributes[0])) { | |
foreach ($product_attributes[0] as $prod_key => $value) { | |
$attributes[$prod_key] = $value; | |
} | |
} | |
$split_line = implode( ' | ', $terms ); | |
$attributes[ $taxonomy ] = array( | |
'name' => $taxonomy, | |
'value' => $split_line, | |
'position' => "", | |
'is_visible' => 1, | |
'is_variation' => 1, | |
'is_taxonomy' => 1 | |
); | |
update_post_meta( $object_id, '_product_attributes', $attributes ); | |
} | |
} | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi Stefano,
this patch is 8 years old, a bit outdated :)
I don't think it's still useful
thanks for writing