【发布时间】:2019-08-18 14:46:57
【问题描述】:
通过检查 GUEST 客户的电子邮件地址与处理和完成的订单,如果电子邮件没有订单,我想给 GUEST 一个“首次订单折扣”。如果客人在他们的电子邮件中输入内容时会发生这种情况,那就太好了。
我想我已经设法制作了折扣代码,现在我正在寻求帮助,以合并这两个代码,使其全部工作。
这是折扣代码:
add_action( 'woocommerce_cart_calculate_fees', 'first_time_order_discount', 10, 1 );
function first_time_order_discount( $wc_cart ) {
if ( is_admin() && ! defined('DOING_AJAX') ) return;
// discount percentage, change this into whatever you like
// currently set to 5%
$percent = 5;
// calculate first order discount based on the percentage above
$first_order_discount = $wc_cart->cart_contents_total * $percent / 100;
$wc_cart->add_fee( __( 'First Order Discount', 'woocommerce')." ($percent%)", -$first_order_discount );
}
这里是控制代码:
function has_bought( $customer_email ){
$orders = get_posts( array(
'numberposts' => -1,
'post_type' => 'shop_order',
'post_status' => array('wc-processing', 'wc-completed'),
) );
$email_array = array();
foreach($orders as $order) {
$order_obj = wc_get_order($order->ID);
$order_obj_data = $order_obj->get_data();
array_push($email_array, $order_obj_data['billing']['email']);
}
if (in_array($customer_email, $email_array)) {
return true;
} else {
return false;
}
}
不确定如何将这两个合并为一个。
【问题讨论】:
-
@helgatheviking 你不能帮忙吗?
-
仅供参考:重新启用已删除的答案并更新...请检查。
标签: php jquery ajax wordpress woocommerce