Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AleStranieri/6317355 to your computer and use it in GitHub Desktop.
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
<?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 );
}
}
}
?>
@AleStranieri
Copy link
Author

hello, what i have to do to use this patch?
thank's
regards

Hi Stefano,
this patch is 8 years old, a bit outdated :)
I don't think it's still useful
thanks for writing

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment