Wordpress 使用购买的产品更新ACF字段';国际商业术语
我正在尝试使用一个函数更新WooCommerce/WP中的“产品主题”用户字段,该函数收集订单中项目的术语ID,并在下订单时将它们添加到“产品主题”字段下的用户配置文件中。当我在代码中指定了一个ID数组,但似乎没有从自定义“主题”道统的每个项目中收集术语ID时,这就起作用了Wordpress 使用购买的产品更新ACF字段';国际商业术语,wordpress,woocommerce,woocommerce-theming,Wordpress,Woocommerce,Woocommerce Theming,我正在尝试使用一个函数更新WooCommerce/WP中的“产品主题”用户字段,该函数收集订单中项目的术语ID,并在下订单时将它们添加到“产品主题”字段下的用户配置文件中。当我在代码中指定了一个ID数组,但似乎没有从自定义“主题”道统的每个项目中收集术语ID时,这就起作用了 add_action('woocommerce_thankyou', 'add_theme_to_user'); add_action('woocommerce_new_order', 'add_theme_to_u
add_action('woocommerce_thankyou', 'add_theme_to_user');
add_action('woocommerce_new_order', 'add_theme_to_user');
function add_theme_to_user($order_id){
$current_user = wp_get_current_user();
$userID = $current_user->ID;
$user = 'user_' . $userID;
$prodCats = array();
$order = new WC_Order( $order_id );
$items = $order->get_items();
$push = array();
foreach ( $items as $item ) {
$item_id = $item['order_item_id'];
$product_name = $item['name'];
$terms = wp_get_post_terms( $itemID, 'theme' );
foreach ( $terms as $term){
array_push($push, $term->term_id);
}
}
update_field('product_themes', $push, 'user_' . $userID);
}
我已经查阅了WooCommerce文档,并就任何类似的问题寻找了解决方案,但我似乎无法使其发挥作用。我错过什么了吗
非常感谢 我自己找到了解决方案,更改了$itemID=$item['order\u item\u id';to$itemID=$item['product_id']
add_action('woocommerce_thankyou', 'add_theme_to_user');
add_action('woocommerce_new_order', 'add_theme_to_user');
function add_theme_to_user($order_id){
$current_user = wp_get_current_user();
$userID = $current_user->ID;
$user = 'user_' . $userID;
$prodCats = array();
$order = new WC_Order( $order_id );
$items = $order->get_items();
$push = array();
foreach ( $items as $item ) {
$itemID = $item['product_id'];
$terms = wp_get_post_terms( $itemID, 'theme' );
foreach ( $terms as $term){
array_push($push, $term->term_id);
update_field('product_themes', $push, 'user_' . $userID);
}
}
update_field('product_themes', $push, 'user_' . $userID);
}
你有没有收到学期id清单?