结账时添加您已购买过的提示
需求
如果登录用户之前已经购买过这个产品,当他再次购买该产品时在购物车页面显示提醒通知
解决办法
使用 woocommerce_after_cart_item_name 动作钩子即可:
function action_woocommerce_after_cart_item_name( $cart_item, $cart_item_key ) { // Only for logged-in users if ( ! is_user_logged_in() ) return; // Get current user $user = wp_get_current_user(); // Get product ID $product_id = $cart_item['variation_id'] > 0 ? $cart_item['variation_id'] : $cart_item['product_id']; // If true if ( wc_customer_bought_product( $user->user_email, $user->ID, $product_id ) ) { echo '<p class="my-class">' . sprintf( __( 'Hi %s you already purchased this product in the past.', 'woocommerce' ), $user->first_name ) . '</p>'; } } add_action( 'woocommerce_after_cart_item_name', 'action_woocommerce_after_cart_item_name', 10, 2 );
结果展示
本文链接:http://78moban.cn/post/14399.html
版权声明:站内所有文章皆来自网络转载,只供模板演示使用,并无任何其它意义!