我有下面的代码作为插件运行。我想检查用户(来宾或注册用户)是否两次订购同一产品并收到通知,但无法正常工作。
请问有什么主意吗?
我的代码是:
add_action('manage_shop_order_posts_custom_column', 'woocommerce_admin_orders_frequent_customer_flash_notice_flash_notice_in_order_number_column', 10, 2);
function woocommerce_admin_orders_frequent_customer_flash_notice_flash_notice_in_order_number_column($column) {
global $post;
switch ($column) {
case 'order_number' :
$dateFrom = date('Y-m-d', strtotime("-1 days")) . " 12:00";
$dateTo = date('Y-m-d') . " 12:00";
$query = new WP_Query( array(
'numberposts' => -1,
'meta_key' => '_billing_email',
'meta_value' => get_post_meta($post->ID, '_billing_email'),
'post_type' => wc_get_order_types(),
'post_status' => array_keys( wc_get_order_statuses() ),
'date_query' => array(array('before' => $dateTo, 'after' => $dateFrom), 'inclusive' => true)
) );
$count = $query->found_posts;
if ($count > 1) {
$count -= 1;
echo "<span style='white-space: nowrap' class='redblink'>$count other orders between 12PM yesterday and 12PM today</span>";
}
break;
}
}
add_action('admin_head', 'woocommerce_admin_orders_frequent_customer_flash_notice_admin_styles');
function woocommerce_admin_orders_frequent_customer_flash_notice_admin_styles() {
echo '<style>
.post-type-shop_order tr.type-shop_order td.order_number { position: relative; }
.post-type-shop_order tr.type-shop_order td.order_number .redblink { color: red; position: absolute; bottom: 0; animation: blinker 1s linear infinite; }
@keyframes blinker {
50% {
opacity: 0;
}
}
</style>';
}
答案 0 :(得分:0)
您需要一些不同的信息来检查用户是否再次订购了同一产品。
在下面的代码中,我使用了一个foreach循环来获取订单项(产品ID)和一个自定义函数,用于检查之前是否已购买了订单项。然后,如果出现这种情况,则会显示闪烁的通知:
props.textTransform
代码进入活动子主题(或活动主题)的functions.php文件中。经过测试,可以正常工作。
相关:Check if a user has purchased specific products in WooCommerce