• Resolved theotheo

    (@theotheo)


    I am trying to display the license key of each order in my-account/orders endpoint but i cant get it to work because i miss this $license variable or something. How can i do it?

    Thank you for your time.

Viewing 8 replies - 1 through 8 (of 8 total)
  • Plugin Author Darko G.

    (@darkog)

    Hey @theotheo ,

    Can you send screenshot where exactly you want to display the license?

    The plugin already displays the license keys in the order pages, unless something is wrong.

    Best Regards,
    Darko

    Thread Starter theotheo

    (@theotheo)

    I know it already shows in my-account/view-order/ but i am talking about displaying the license key in my-account/orders

    Plugin Author Darko G.

    (@darkog)

    Hey @theotheo

    This is a sample snippet to add licenses to the orders table in my account. You can modify it as per your needs.

    /**
     * Add the column to the table
     *
     * @param $columns
     *
     * @return mixed
     */
    function dlm_add_license_in_myaccount_orders_table( $columns ) {
    	$columns['licenses'] = __( 'Licenses', 'woocommerce' );
    
    	return $columns;
    }
    
    add_filter( 'woocommerce_account_orders_columns', 'dlm_add_license_in_myaccount_orders_table', 10, 1 );
    
    /**
     * Add value to the column
     *
     * @param $order
     *
     * @return void
     */
    function dlm_add_license_in_myaccount_orders_table_value( $order ) {
    	$orderData = \IdeoLogix\DigitalLicenseManager\Integrations\WooCommerce\Orders::getLicenses( [ 'order' => $order ] );
    	$licenses  = [];
    	if ( ! empty( $orderData['data'] ) ) {
    		foreach ( $orderData['data'] as $item ) {
    			if ( ! empty( $item['keys'] ) ) {
    				foreach ( $item['keys'] as $license ) {
    					$licenses[ $license->getDecryptedLicenseKey() ] = $item['name'];
    				}
    			}
    		}
    	}
    	if ( ! empty( $licenses ) ) {
    		echo '<ul>';
    		foreach ( $licenses as $licenseKey => $productName ) {
    			echo sprintf( '<li>%s - %s</li>', $licenseKey, $productName );
    		}
    		echo '</ul>';
    	}
    }
    add_action( 'woocommerce_my_account_my_orders_column_licenses', 'dlm_add_license_in_myaccount_orders_table_value' );
    Thread Starter theotheo

    (@theotheo)

    Thank you very much, i will check as soon as i have time. By the way if you need to translate the core of your plugin to greek i’m willing to do it to help a bit with the project since i’m greek.

    • This reply was modified 1 year, 10 months ago by theotheo.
    Thread Starter theotheo

    (@theotheo)

    @darkog I checked the code and it actually breaks the /my-account/orders pagination. When you try to go to the next page of orders it is broken. Also it would be best if there is a way to display the license key in any place and not attach it in columns only.

    I don’t know if it is possible but if you could actually create a function and create a shortcode for it enabling users to display a license key anywhere would be nice. It would be a nice general improvement to the plugin.

    Thread Starter theotheo

    (@theotheo)

    Additional note:

    It only displays a license when there is only 1 item in the order. If the are multiple items of the same item it doesn’t display a license for each same item. This also happens when multiple different products are in an order…licenses are not displayed for each item.

    Plugin Author Darko G.

    (@darkog)

    Hey @theotheo

    Regarding the translating it onto your language:

    You can start on this page.

    Basically, using your www.remarpro.com account you can enter translations for the strings and the Greek team will have to accept those translations.

    If you are willing to manage the Digital License Manager’s Greek translations you can even request PTE (Project Translation Editor) form the Greek team. Feel free to contact them on Slack or email.

    Regarding the other issue (if still present):

    @darkog I checked the code and it actually breaks the /my-account/orders pagination. When you try to go to the next page of orders it is broken. Also it would be best if there is a way to display the license key in any place and not attach it in columns only.

    theotheo?

    Can you send me an error log that you are possibly receiving? First please enable debug.log and then when you visit the page you will get the issues.

    Regarding the shortcode:

    create a shortcode for it enabling users to display a license key anywhere would be nice

    theotheo

    How exactly you envision this one? Do you mean by providing order id to print a table with licenses or displaying the license key somewhere by license id?

    Regarding the additional note:

    It only displays a license when there is only 1 item in the order. If the are multiple items of the same item it doesn’t display a license for each same item. This also happens when multiple different products are in an order…licenses are not displayed for each item.

    theotheo

    I am testing the code again, but couldn’t find those issue myself. See image1 and image2 – tested with multiple products. I moved the code to separate plugin which can be found here, you can drop it in mu-plugins folder or plugins and then activate.

    Best Regards,
    Darko

    Plugin Author Darko G.

    (@darkog)

    Marking this as resolved. Feel free to reopen if any of any of the issues still exist.

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘How to display licenses in my account/orders endpoint’ is closed to new replies.