Last active
October 27, 2022 19:59
-
-
Save luizbills/86f63617fd826b815b132a49ee3ec2d8 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