Hi there
You could try to add the follwing code to functions.php file of your theme or child theme
if ( ! function_exists( 'yith_wcwl_add_item_purchased_to_wishlist' ) ) {
function yith_wcwl_add_item_purchased_to_wishlist( $order_id, $order ) {
/**
* @var $order WC_Order
*/
$customer_id = $order->get_customer_id();
if ( ! $customer_id ) {
return;
}
if ( ! function_exists( 'YITH_WCWL' ) ) {
return;
}
$customer_default_wishlist = YITH_WCWL_Wishlist_Factory::get_default_wishlist( $customer_id, 'edit' );
if ( ! $customer_default_wishlist ) {
return;
}
$items = $order->get_items( 'line_item' );
if ( empty( $items ) ) {
return;
}
foreach ( $items as $item ) {
/**
* @var $item WC_Order_Item_Product
*/
$product_id = $item->get_product_id();
$variation_id = $item->get_variation_id();
$product_id = $variation_id ? $variation_id : $product_id;
if ( ! $product_id || $customer_default_wishlist->has_product( $product_id ) ) {
continue;
}
$customer_default_wishlist->add_product( $product_id );
}
$customer_default_wishlist->save();
}
add_action( 'woocommerce_order_status_completed', 'yith_wcwl_add_item_purchased_to_wishlist', 10, 2 );
add_action( 'woocommerce_order_status_processing', 'yith_wcwl_add_item_purchased_to_wishlist', 10, 2 );
}
When an order switches to completed or processing, this code will cycle through items, and add them to customer’s wishlist
If no wishlist exists, one will be created for this purpose