(WooCommerce) 检查客户是否下了超过一定数量的订单或花费了一定金额?
(WooCommerce) Check if customer has made more than a certain number of orders or spent a certain amount?
有什么方法可以设置条件语句,向已经下了一定数量的订单或在我的商店消费超过一定金额的客户显示消息?
我基本上想为尊贵的客户提供全站折扣,我已经为此设置了一个系统,但理想情况下,我想展示一个表格,用户可以在其中申请此折扣,但为了防止大家不要申请我只想给回头客看。
事实证明,我们可以窃取...呃借用...直接从 WooCommerce source 中查询订单。我们只需要将 posts_per_page
参数修改为 -1
,这样它就会查询 all 个帖子。
这可能会消耗资源...所以 1. 我建议仅 运行 登录用户使用它。 2.也许只检索你想限制你的优惠券的帖子数量(又名...... 5 个订单给你一个折扣,只检索 5 个帖子)和 3. 甚至可能暂时缓存值或者甚至可能保持跟踪它作为用户元。最后一个比我现在想进入的有点棘手所以
if ( is_user_logged_in() ) {
$number_of_orders = 10;
$customer_orders = get_posts( apply_filters( 'woocommerce_my_account_my_orders_query', array(
'numberposts' => $number_of_orders,
'meta_key' => '_customer_user',
'meta_value' => get_current_user_id(),
'post_type' => wc_get_order_types( 'view-orders' ),
'post_status' => array_keys( wc_get_order_statuses() )
) ) );
if ( $customer_orders && count( $customer_orders > $number_of_orders ) ){
// whoa you've got more than 10 orders
}
}
有什么方法可以设置条件语句,向已经下了一定数量的订单或在我的商店消费超过一定金额的客户显示消息?
我基本上想为尊贵的客户提供全站折扣,我已经为此设置了一个系统,但理想情况下,我想展示一个表格,用户可以在其中申请此折扣,但为了防止大家不要申请我只想给回头客看。
事实证明,我们可以窃取...呃借用...直接从 WooCommerce source 中查询订单。我们只需要将 posts_per_page
参数修改为 -1
,这样它就会查询 all 个帖子。
这可能会消耗资源...所以 1. 我建议仅 运行 登录用户使用它。 2.也许只检索你想限制你的优惠券的帖子数量(又名...... 5 个订单给你一个折扣,只检索 5 个帖子)和 3. 甚至可能暂时缓存值或者甚至可能保持跟踪它作为用户元。最后一个比我现在想进入的有点棘手所以
if ( is_user_logged_in() ) {
$number_of_orders = 10;
$customer_orders = get_posts( apply_filters( 'woocommerce_my_account_my_orders_query', array(
'numberposts' => $number_of_orders,
'meta_key' => '_customer_user',
'meta_value' => get_current_user_id(),
'post_type' => wc_get_order_types( 'view-orders' ),
'post_status' => array_keys( wc_get_order_statuses() )
) ) );
if ( $customer_orders && count( $customer_orders > $number_of_orders ) ){
// whoa you've got more than 10 orders
}
}