1
我需要在WooCommerce中創建優惠券,該優惠券僅在用戶的電子郵件以.ac.uk
結束時纔有效。WooCommerce學生折扣
例如[email protected]
或[email protected]
。
折扣將是總購物籃10%。
我找不到任何解決方案在線或任何可以幫助的插件。
任何想法?
感謝。
我需要在WooCommerce中創建優惠券,該優惠券僅在用戶的電子郵件以.ac.uk
結束時纔有效。WooCommerce學生折扣
例如[email protected]
或[email protected]
。
折扣將是總購物籃10%。
我找不到任何解決方案在線或任何可以幫助的插件。
任何想法?
感謝。
您可以使用此自動(由ac.uk
用戶電子郵件整理)申請優惠券到客戶的購買功能用正確的條件語句:
add_action('woocommerce_before_cart_table', 'coupon_auto_apply_user_email_tld', 10, 0);
function coupon_auto_apply_user_email_tld() {
$current_user = wp_get_current_user();
$user_email = $current_user->user_email;
$mail_part = explode('@', $user_email);
$domain_part = explode('.', $mailParts[1]);
$mail_tld = $domain_part[1] . '.' . $domain_part[2]);
if ($woocommerce->cart->has_discount($coupon_code)) return;
if ($mail_tld == 'ac.uk') {
$coupon_code = 'UNIQUECODE'; // <= set the name of your coupon code here
if (! WC()->cart->add_discount(sanitize_text_field($coupon_code))) {
WC()->show_messages();
}
echo '<div class="woocommerce_message"><strong>The total price in your cart will be discounted 10% off…</strong></div>';
}
else
{
return;
}
}
您將在WooCommerce優惠券設置與優惠券設置慾望行爲(10%折扣),您將在此功能中報告此優惠券。
將代碼複製到位於活動主題中的functions.php文件中,或者更好地使用活動的兒童主題。