【发布时间】:2018-11-21 01:45:25
【问题描述】:
我正在尝试更新 wp_woocommerce_order_items 表中的项目名称并找到函数 wc_update_order_item 来解决问题。
我希望它更改为随机挑选的产品。他们的主要内容是我已经知道我想要更改的order_item_id。
这是我的代码:
$order_item_id = array(1,2,3);
$num = 3;
$ctr = 0;
$products = new WP_Query( array(
'post_type' => 'product',
'post_status' => 'publish',
'posts_per_page' => $num,
'orderby' => 'rand',
));
if ( $products->have_posts() ): while ( $products->have_posts() ): $products->the_post();
wc_update_order_item($order_item_id[$ctr], array('order_item_name' => $products->post->post_title));
$ctr++;
endwhile; wp_reset_postdata(); endif;
wc_update_order_item() 是应该更新订单商品名称的地方。它确实更新了 order_item_name,但不更新当前的 $products->post->post_title 值。它使用随机产品标题更新。
我如何知道正在保存的标题与循环内的当前 post_title 不同?如果我在循环内echo $products->post->post_title,它应该显示当前产品名称,但更新后的order_item_name 具有不同的值。
【问题讨论】:
标签: php wordpress woocommerce product orders