File: /var/www/html/sparkle/wp-content/themes/flatsome-child/functions.php
<?php
// Add custom Theme Functions here
function wpblog_wc_register_post_statuses() {
register_post_status( 'wc-shipping-progress', array(
'label' => _x( 'Shipping In Progress', 'WooCommerce Order status', 'text_domain' ),
'public' => true,
'exclude_from_search' => false,
'show_in_admin_all_list' => true,
'show_in_admin_status_list' => true,
'label_count' => _n_noop( 'Approved (%s)', 'Approved (%s)', 'text_domain' )
) );
}
add_filter( 'init', 'wpblog_wc_register_post_statuses' );
function wpblog_wc_add_order_statuses( $order_statuses ) {
$order_statuses['wc-shipping-progress'] = _x( 'Shipping In Progress', 'WooCommerce Order status', 'text_domain' );
return $order_statuses;
}
add_filter( 'wc_order_statuses', 'wpblog_wc_add_order_statuses' );
add_filter( 'flatsome_payment_icons', function ( $icons ) {
$icons['wechatpay2'] = 'wechatpay2';
return $icons;
} );
/**
* Remove product data tabs
*/
add_filter( 'woocommerce_product_tabs', 'woo_remove_product_tabs', 98 );
function woo_remove_product_tabs( $tabs ) {
unset( $tabs['additional_information'] ); // Remove the additional information tab
return $tabs;
}
/*
WooCommerce email restriction for coupons does not work. This fix corrects it.
Include this code snippet in your theme or plugin.
*/
add_filter('woocommerce_coupon_is_valid', function ($result, $coupon) {
if (null === WC()->cart) {
return $result;
}
$user = wp_get_current_user();
$restricted_emails = $coupon->get_email_restrictions();
if (count($restricted_emails) > 0) {
return WC()->cart->is_coupon_emails_allowed(
[$user->user_email],
$restricted_emails
);
} else {
return $result;
}
}, 10, 2);
function get_client_ip()
{
$ipaddress = '';
if (getenv('HTTP_CLIENT_IP'))
$ipaddress = getenv('HTTP_CLIENT_IP');
else if (getenv('HTTP_X_FORWARDED_FOR'))
$ipaddress = getenv('HTTP_X_FORWARDED_FOR');
else if (getenv('HTTP_X_FORWARDED'))
$ipaddress = getenv('HTTP_X_FORWARDED');
else if (getenv('HTTP_FORWARDED_FOR'))
$ipaddress = getenv('HTTP_FORWARDED_FOR');
else if (getenv('HTTP_FORWARDED'))
$ipaddress = getenv('HTTP_FORWARDED');
else if (getenv('REMOTE_ADDR'))
$ipaddress = getenv('REMOTE_ADDR');
else
$ipaddress = 'UNKNOWN';
return $ipaddress;
}
/**
* Filter to turn off auto-update notification emails.
*/
add_filter( 'rank_math/auto_update_send_email', '__return_false' );
function prevent_email_domain( $user_login, $user_email, $errors ) {
global $wpdb;
$ip = get_client_ip();
$result = $wpdb->get_results("SELECT * FROM `custom_keyword_blacklist`");
foreach ( $result as $idx=>$keywordObj) {
//$errors->add( 'bad_email_domain', '<strong>錯誤</strong>: '.$keywordObj->name);
if($keywordObj->type=="U"){
if ( stripos( $user_login, $keywordObj->name ) !== false ) {
$lang = get_bloginfo('language');
if($lang=="zh-TW") {
$errors->add( 'bad_email_domain', '<strong>錯誤</strong>: 此字段已被阻止註冊用戶帳戶');
} else {
$errors->add( 'bad_email_domain', '<strong>ERROR</strong>: This word phrase is blocked from registering user account');
}
$wpdb->insert('custom_blocked_registration', array(
'regName' => $user_login,
'regEmail' => $user_email,
'ipAddress' => $ip,
'blockReason' => 'blocked by word phrase '.$keywordObj->name
));
}
}
if($keywordObj->type=="D"){
if ( strpos( $user_email, $keywordObj->name ) !== false ) {
$lang = get_bloginfo('language');
if($lang=="zh-TW") {
$errors->add( 'bad_email_domain', '<strong>錯誤</strong>: 此網域已被阻止註冊用戶帳戶');
} else {
$errors->add( 'bad_email_domain', '<strong>ERROR</strong>: This domain is blocked from registering user account');
}
$wpdb->insert('custom_blocked_registration', array(
'regName' => $user_login,
'regEmail' => $user_email,
'ipAddress' => $ip,
'blockReason' => 'blocked by email domain '.$keywordObj->name
));
}
}
}
//$errors->add( 'bad_email_domain', '<strong>ERROR</strong>: This email domain is not allowed.'.$user_login.$user_email);
}
add_action( 'register_post', 'prevent_email_domain', 10, 3 );