有没有办法可以设置条件声明,向已经订购了一定数量订单或在我的商店花费超过一定金额的客户显示消息?
我基本上想为有价值的客户提供网站折扣,我已经为其设置了系统,但理想情况下我想要显示一个用户可以申请此折扣的表单,但是要防止所有人申请我只想把它展示给回头客。
答案 0 :(得分:1)
事实证明,我们可以窃取......借用...... WooCommerce source之外的订单查询。我们只需将posts_per_page
参数修改为-1
,以便查询所有帖子。
这有可能咀嚼资源......所以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
}
}