Untitled

mail@pastecode.io avatar
unknown
plain_text
a year ago
1.8 kB
5
Indexable
Never
function check_is_agent_with_access(){
	// 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 apply_filters('b2bking_enable_salesking_visibility', true);
            }
        }
    }
    return false;
}
add_action('plugins_loaded', function(){
	if (check_is_agent_with_access()){
    	remove_filter( 'woocommerce_get_price_html', array('B2bking_Dynamic_Rules', 'b2bking_dynamic_rule_hidden_price'), 99999, 2 );
    	remove_filter( 'woocommerce_variation_price_html', array('B2bking_Dynamic_Rules', 'b2bking_dynamic_rule_hidden_price'), 99999, 2 );
    	// Dynamic rule Hidden price - disable purchasable
    	remove_filter( 'woocommerce_is_purchasable', array('B2bking_Dynamic_Rules', 'b2bking_dynamic_rule_hidden_price_disable_purchasable'), 10, 2);
    	remove_filter( 'woocommerce_variation_is_purchasable', array('B2bking_Dynamic_Rules', 'b2bking_dynamic_rule_hidden_price_disable_purchasable'), 10, 2);
    }
});