我想在之后自动将用户角色更改为高级用户角色
3已完成订单
一笔订单消费满500现金
我在互联网上找到了这两个代码片段:
function change_privategroup_on_purchase( $order_id ) {
$order = new WC_Order( $order_id );
$items = $order->get_items();
foreach ( $items as $item ) {
$product_name = $item['name'];
$product_id = $item['product_id'];
$product_variation_id = $item['variation_id'];
if ( $order->user_id > 0 ) {
// Insert the Product IDs Here. If Multiple Products seperate by ||
if ( $product_id == '7026' || $product_id == '7027' || $product_id == '7028' || $product_id == '7029') {
// Mention the group number below. Here it is group1.
update_user_meta( $order->user_id, 'private_group', 'group1');
}
}
}
}
add_action( 'woocommerce_order_status_processing', 'change_privategroup_on_purchase' );
这是访问订单历史记录的一个:
function has_bought() {
// Get all customer orders
$customer_orders = get_posts( array(
'numberposts' => 3, // one order is enough
'meta_key' => '_customer_user',
'meta_value' => get_current_user_id(),
'post_type' => 'shop_order', // WC orders post type
'post_status' => 'wc-completed', // Only orders with "completed" status
'fields' => 'ids', // Return Ids "completed"
) );
// return "true" when customer has already at least one order (false if not)
return count($customer_orders) > 3 ? true : false;
}
我如何调整它们以使其发挥作用?
慕婉清6462132