Support » Plugin: License Manager for WooCommerce » Account menu Link position

  • Resolved botprophet

    (@botprophet)


    Quick question.

    I’ve been trying to move the License Keys link in “your account” from under log-out to elsewhere.

    Been looking at
    … wp-content\plugins\license-manager-for-woocommerce\includes\integrations\woocommerce\MyAccount.php

    Any hint as to how to reposition this link?

    Also tried this with Code Snippets, but it leaves the link/url to 0.

    add_filter ( 'woocommerce_account_menu_items', 'lmfwc_customize_account_menu_items' );
    function lmfwc_customize_account_menu_items( $menu_items ){
    	
         // Add new Custom URL in My Account Menu 
        $new_menu_item = array('woocommerce_account_view-license-keys_endpoint'=> __('Your License keys', 'license-manager-for-woocommerce'));
        $new_menu_item_position=3;
        
        array_splice( $menu_items, ($new_menu_item_position-1), 0, $new_menu_item );
        return $menu_items;
    }

    Thanks.

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter botprophet

    (@botprophet)

    It’s not pretty, but i figured out a way.
    Put this in your functions file or code snippet plugin:

    add_filter( 'woocommerce_account_menu_items', 'lmfwc_reorder_my_license_link', 100, 1 );
    function lmfwc_reorder_my_license_link( $items ) {
        $ordered_items = array();
    
        // HERE set your custom label name for 'license' key in this array
        $license_item = array( 'view-license-keys' => __( 'Your License keys', 'license-manager-for-woocommerce' ) );
    
        // Remove 'license' key / label pair from original $items array
        unset( $items['view-license-keys'] );
    
        // merging arrays
        $license_item_position=3; // Define Position at which the New URL has to be inserted
    	$ordered_items_1 = array_slice($items, 0, $license_item_position-1);
    	$ordered_items_2 = $license_item;
    	$ordered_items_3 = array_slice($items, $license_item_position);
    	$items = array_merge( $ordered_items_1,$ordered_items_2,$ordered_items_3 );
    	
        return $items;
    }

    The shorter array_splice function didn’t work for me

    • This reply was modified 4 months, 1 week ago by botprophet.
    Drazen Bebic

    (@drazenbebic)

    @botprophet

    There’s a helper function which I like to use for this purpose:

    
    function lmfwc_array_insert_after( $needle, $haystack, $new_key, $new_value ) {
    	if ( array_key_exists( $needle, $haystack ) ) {
    		$new_array = array();
    
    		foreach ( $haystack as $key => $value ) {
    			$new_array[ $key ] = $value;
    
    			if ( $key === $needle ) {
    				$new_array[ $new_key ] = $new_value;
    			}
    		}
    
    		return $new_array;
    	}
    
    	return $haystack;
    }
    

    The function looks for the “needle” in the “haystack”, and once it finds it, inserts the “new_value” using the “new_key”. It returns the modified array.

    If anything’s unclear let me know 🙂

Viewing 2 replies - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.