WooCommerce で、返品したクライアントが受け取った注文の製品 SKU を変更しようとしています。
現在、現在のコードを使用していますが、機能していないようです。
私は2つの異なる製品を持っています。id の製品5836
は通常の製品で、もう 1 つはサブスクリプションです。
これは私のコードです:
function action_woocommerce_thankyou( $order_id ) {
// Let's get the order details
$order = wc_get_order( $order_id );
// Customer who made the purchase
$user_id = $order->get_user_id();
// Now get order count for the customer
$order_count = wc_get_customer_order_count( $user_id );
$items = $order->get_items();
foreach ( $order->get_items() as $item_id => $item) {
$product_name = $item['name'];
$product_id = $item['product_id'];
$product_variation_id = $item['variation_id'];
if ( $order_count > 1) {
// Returning customer...
if ( $product_id == '5836') {
update_post_meta( $order_id['product_id'], '_sku', $ANT0001 );}
else {
// Returning customer...
update_post_meta( $order_id['product_id'], '_sku', $ANT0002 );}
} else {
// New customer...
}
}
}
add_action( 'woocommerce_thankyou', 'action_woocommerce_thankyou', 10, 1 );