• Resolved serienautas

    (@serienautas)


    First of all thank you for this monster plugin which is awesome, thank you very much.

    I want to display the license purchased by the user in a different section. Before I had the WC SERIALKEY NUMBERS plugin and with chatgpt I had managed to create a shortcode where I placed it and displayed the license but with this plugin it became impossible.

    I need if someone knows about the subject can throw me some basic information on how to display the license where I want. Something I can tell chatgpt to help me. I am not an expert in programming, but I have some knowledge and I am desperate to know that it has no function to show this license in another sector.

    Is there anything I need to know?

    Translated with DeepL.com (free version)

    The page I need help with: [log in to see the link]

Viewing 3 replies - 1 through 3 (of 3 total)
  • Thread Starter serienautas

    (@serienautas)

    Hola chicos, quiero contarles de que lo logré!!!!!!!!!!!! usando chatgpt me dio la solucion. Aqui les dejo el codigo para colocar en su functions.php de su theme y para usar el shortcode [mostrar_licencias]:

    use LicenseManagerForWooCommerce\Repositories\Resources\License as LicenseResourceRepository;

    function mostrar_licencias_shortcode() {
    if (!is_user_logged_in()) {
    return '<p>Necesitas estar logueado para ver tus licencias.</p>';
    }

    $user_id = get_current_user_id();
    $customer_orders = wc_get_orders(array(
    'customer' => $user_id,
    'status' => 'completed'
    ));

    if (empty($customer_orders)) {
    return '<p>No has comprado ninguna licencia.</p>';
    }

    ob_start(); // Iniciar el buffer de salida

    echo '<h2>Cuentas Adquiridas</h2>';

    foreach ($customer_orders as $order) {
    $order_id = $order->get_id();
    $items = $order->get_items();

    foreach ($items as $item) {
    $product_id = $item->get_product_id();
    $product_name = $item->get_name();
    $licenses = LicenseResourceRepository::instance()->findAllBy(array(
    'order_id' => $order_id,
    'product_id' => $product_id
    ));

    if (!$licenses) {
    continue;
    }

    echo '<table class="shop_table">';
    echo '<thead><tr><th colspan="2">' . esc_html($product_name) . '</th></tr></thead>';
    echo '<tbody>';

    foreach ($licenses as $license) {
    $decrypted_key = $license->getDecryptedLicenseKey();
    $expires_at = $license->getExpiresAt();

    echo '<tr>';
    echo '<td colspan="' . ($expires_at ? '1' : '2') . '">';
    echo '<span class="lmfwc-myaccount-license-key">' . esc_html($decrypted_key) . '</span>';
    echo '</td>';

    if ($expires_at) {
    try {
    $date = wp_date(get_option('date_format'), strtotime($expires_at));
    } catch (Exception $e) {
    $date = '';
    }
    $valid_until = 'Válido hasta'; // Traducción de "Valid until"
    echo '<td><span class="lmfwc-myaccount-license-key">' . sprintf('%s <strong>%s</strong>', esc_html($valid_until), esc_html($date)) . '</span></td>';
    }

    echo '</tr>';
    }

    echo '</tbody>';
    echo '</table>';
    }
    }

    return ob_get_clean(); // Devolver el contenido del buffer de salida
    }

    add_shortcode('mostrar_licencias', 'mostrar_licencias_shortcode');

    ahora solo deben colocar el shortcode [mostrar_licencias] sonde quieran mostrar su licencia. Saludos

    Plugin Support Ibaad Ahmed Khan

    (@ibaad06)

    Hello @serienautas

    Thank you for your contribution and for sharing the solution you discovered! We truly appreciate your initiative and the code you’ve provided for displaying the license using a shortcode.

    I’ve documented your solution and added it to our knowledge base to help others who might encounter a similar challenge.

    If you have any more questions or need further assistance, please feel free to reach out.

    Kind regards.

    Plugin Support Ibaad Ahmed Khan

    (@ibaad06)

    Dear @serienautas

    Hope you are doing well !

    Since there has been no recent activity on this thread, we will mark it resolved. If you encounter any further issues or have additional questions, please don’t hesitate to open a new thread. We’ll be happy to assist you promptly.

    Thank you, and have a great day!

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