在 WooCommerce 中,我正在尝试更改返回客户收到的订单的产品 SKU。
目前我使用当前的代码,但它似乎不起作用。
我有 2 种不同的产品。带有 id 的产品5836
是普通产品,而另一个是订阅产品。
这是我的代码:
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 );