• Resolved serienautas

    (@serienautas)


    Queria compartir mi felicidad! sin saber programar le pedi a chatgpt que trabajaramos juntos en crear un shortcode para mostrar la licencia comprada donde yo quisiera. Despues de 40min ofreciendole la documentacion del plugin y los mensajes de aqui del foro de gente que buscaba lo mismo, consegui el cometido.

    El shortcode a usar es [mostrar_licencias] y el codigo que deben a?adir al functions.php de su theme de wordpress es el siguiente:


    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');

    La web donde la estoy usando es en https://serienautas.com/

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

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Support Ibaad Ahmed Khan

    (@ibaad06)

    Hello @serienautas

    Thank you for your contribution! We’ve responded to your other thread with the details. Please check that thread for our acknowledgment.

    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 2 replies - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.