-
-
Save taciara/2a36babecd067fc00e05f94b57c946c7 to your computer and use it in GitHub Desktop.
Copy custom terms when duplicatin a woocommerce product
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 | |
// credits: https://github.com/woocommerce/woocommerce/issues/17487#issuecomment-565433819 | |
add_action( 'woocommerce_product_duplicate', function ( $duplicate, $product ) { | |
$taxonomies = [ 'taxonomy1', 'taxonomy2' ]; | |
foreach ( $taxonomies as $taxonomy ) { | |
$terms = get_the_terms( $product->get_id(), $taxonomy ); | |
if ( ! is_wp_error( $terms ) ) { | |
wp_set_object_terms( $duplicate->get_id(), wp_list_pluck( $terms, 'term_id' ), $taxonomy ); | |
} | |
} | |
}, 999, 2 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment