• Resolved Jorge Razor

    (@jorgehoffmann)


    Hi. I’m trying to pass a variable called pagina to the PDF (from single product page), but when I click on the submit button, it redirects me to cart with message: “Invalid nonce. Unable to process PDF for download.” and the URL is like this: “…/carrinho/?cart-pdf=1&_wpnonce=dc6f3b2f5c&pagina=2”. I know this is custom, but can you help me? Thanks!

    
    <form id="orcamento-single-product-form" method="GET" action="<?php echo wc_get_cart_url(); ?>">
    <button id="enviar-form-personalizacao" type="submit">ENVIAR</button>
    <input type="text" readonly="readonly" name="cart-pdf" value="1" />
    <?php wp_nonce_field( -1, '_wpnonce', false, true ); ?>
    <input type="text" readonly="readonly" name="pagina" value="2" />
    </form>
    
    • This topic was modified 2 years, 7 months ago by Jorge Razor.
Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author David Jensen

    (@dkjensen)

    Hi @jorgehoffmann

    Could you change your nonce field to:

    <?php wp_nonce_field( 'cart-pdf', '_wpnonce', false, true ); ?>

    Let me know if that works

    Thread Starter Jorge Razor

    (@jorgehoffmann)

    That did the trick, thanks again! Now I have another problem, if the cart is not empty, the function works, but if is empty, then I get redirected to cart with the “your cart is empty” message. I guess this is the plugin default behavior, since its made for the cart, but is there a way to bypass that on my function? Thanks.

    Plugin Author David Jensen

    (@dkjensen)

    @jorgehoffmann Great!

    What you could do is check if the cart is empty before rendering your form, and instead display a notice. You can check if the cart is empty using this conditional:

    if ( WC()->cart->is_empty() ) {
        // Cart is empty
    } else {
        // Cart is not empty
    }
    • This reply was modified 2 years, 7 months ago by David Jensen.
    Thread Starter Jorge Razor

    (@jorgehoffmann)

    Unfortunately i had to remove the cart empty check from the wc_cart_pdf_process_download() function, in the core file of the plugin to make it work, because I need the user to be able to generate PDF from the single product page, most of the times without even getting to the cart. Like I said before, this is totally custom and I’ll have to deal with it myself, but thanks A LOT for your attention and support. If you have any more hints, I’d appreciate it ??

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Pass parameters to PDF’ is closed to new replies.