Untitled
unknown
plain_text
10 months ago
2.0 kB
3
Indexable
function is_agent($user_id){ $agent_group = get_user_meta($user_id,'salesking_group',true); if ($agent_group !== 'none' && !empty($agent_group)){ return true; } else { return false; } } function is_agent_shopping(){ // check if switch cookie is set if (isset($_COOKIE['salesking_switch_cookie'])){ $switch_to = sanitize_text_field($_COOKIE['salesking_switch_cookie']); $current_id = get_current_user_id(); if (!empty($switch_to) && is_user_logged_in()){ // show bar $udata = get_userdata( get_current_user_id() ); $name = $udata->first_name.' '.$udata->last_name; // get agent details $agent = explode('_',$switch_to); $customer_id = intval($agent[0]); $agent_id = intval($agent[1]); $agent_registration = $agent[2]; // check real registration in database $udataagent = get_userdata( $agent_id ); $registered_date = $udataagent->user_registered; // if current logged in user is the one in the cookie + agent cookie checks out if ($current_id === $customer_id && $agent_registration === $registered_date){ return true; } } } return false; } function disable_payment_methods_for_non_agents($available_gateways) { if (!function_exists('is_agent')) { return $available_gateways; } if (!is_agent() && !is_agent_shopping()) { $gateways_to_disable = [ 'custom_f726aff85e66dc5', 'custom_078f58d7faead43', 'custom_ffb128d9e89c2f3', 'custom_061574f903423d5', 'custom_9eca9df2e667668', 'custom_53d7dcd8aba06dd' ]; foreach ($gateways_to_disable as $gateway_id) { if (isset($available_gateways[$gateway_id])) { unset($available_gateways[$gateway_id]); } } } return $available_gateways; } add_filter('woocommerce_available_payment_gateways', 'disable_payment_methods_for_non_agents');
Editor is loading...
Leave a Comment