Untitled

mail@pastecode.io avatar
unknown
plain_text
2 months ago
1.3 kB
1
Indexable
Never
// add link to the menu
add_filter ( 'woocommerce_account_menu_items', 'salesk_one_more_link' );
function salesk_one_more_link( $menu_links ){

	if (is_agent(get_current_user_id())){
		$new = array( 'gotoagent' => 'Sales Agent Dashboard' );

		// array_slice() is good when you want to add an element between the other ones
		$menu_links = array_slice( $menu_links, 0, 3, true ) 
		+ $new 
		+ array_slice( $menu_links, 3, NULL, true );
	}

	return $menu_links;
}

// hook the external URL
add_filter( 'woocommerce_get_endpoint_url', 'salesk_hook_endpoint', 10, 4 );
function salesk_hook_endpoint( $url, $endpoint, $value, $permalink ){
	if( 'gotoagent' === $endpoint ) {
		$url = esc_attr(trailingslashit(get_page_link(apply_filters( 'wpml_object_id', get_option( 'salesking_agents_page_setting', 'disabled' ), 'post' , true))));
	}
	return $url;
}

// custom icon
add_action( 'wp_head', 'salesk_link_custom_icon' );
function salesk_link_custom_icon() {
	?><style>
	.woocommerce-MyAccount-navigation ul li.woocommerce-MyAccount-navigation-link--gotoagent a:before{
		content: "\f4fe"
	}
	</style><?php
}

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;
	}
}
Leave a Comment