• Resolved Jorge Razor

    (@jorgehoffmann)


    Is there a shortcode or something similar that generates the button anywhere I want? I need to insert it in some places on my site. Thanks for your attention. This plugin is awesome e so easy to use ?? Congratz!

Viewing 11 replies - 1 through 11 (of 11 total)
  • Plugin Author David Jensen

    (@dkjensen)

    @jorgehoffmann

    Hello

    There is not a shortcode, rather a function to render the button. However you can use this to create a shortcode such as the following:

    function child_wc_cart_pdf_shortcode( $atts, $content = '' ) {
        if ( function_exists( 'wc_cart_pdf_button' ) ) {
            ob_start();
    
            wc_cart_pdf_button();
    
            return ob_get_clean();
        }
    
        return '';
    }
    add_shortcode( 'wc_cart_pdf_button', 'child_wc_cart_pdf_shortcode' );

    Then you can use the shortcode [wc_cart_pdf_button].

    Thread Starter Jorge Razor

    (@jorgehoffmann)

    Hello, thanks for the reply. Unfortunately the shortcode only works on the cart page, I guess because the function wc_cart_pdf_button is only called there by the plugin. If I am right, is there a way of calling this function on other pages thru functions.php?

    Neither does this code works: add_action( ‘woocommerce_after_add_to_cart_form’, ‘wc_cart_pdf_button’ );, for the same reason I think.

    Thanks.

    Plugin Author David Jensen

    (@dkjensen)

    @jorgehoffmann Ah yes you are right. Try the following shortcode instead:

    function child_wc_cart_pdf_shortcode( $atts, $content = '' ) {
        if ( function_exists( 'wc_get_cart_url' ) ) {
            ob_start();
    		?>
    
    		<a href="<?php echo esc_url( wp_nonce_url( add_query_arg( array( 'cart-pdf' => '1' ), wc_get_cart_url() ), 'cart-pdf' ) ); ?>" class="cart-pdf-button button" target="_blank">
    			<?php echo esc_html( get_option( 'wc_cart_pdf_button_label', __( 'Download Cart as PDF', 'wc-cart-pdf' ) ) ); ?>
    		</a>
    
    		<?php
    
            return ob_get_clean();
        }
    
        return '';
    }
    add_shortcode( 'wc_cart_pdf_button', 'child_wc_cart_pdf_shortcode' );
    Thread Starter Jorge Razor

    (@jorgehoffmann)

    All working good now. Thanks a lot for the replys and patience.

    Now I can print almoust anything from any front-end page just by passing the right parameters thru the URL.

    Once again, congratulations on the plugin.

    Plugin Author David Jensen

    (@dkjensen)

    @jorgehoffmann Neat, thanks!

    Edit: sorry for the inconvenience, I already removed it with css ??

    Hi David, thanks so much for this, working like a charm ??
    How can I remove the automatically placed button? It’s below the page and I placed the new one with the shortcode on top of my page.

    • This reply was modified 2 years, 7 months ago by margob.
    Plugin Author David Jensen

    (@dkjensen)

    @margob You can use the following code to remove the default placed button:

    remove_action( 'woocommerce_proceed_to_checkout', 'wc_cart_pdf_button', 21 );
    remove_action( 'woocommerce_review_order_before_payment', 'wc_cart_pdf_show_checkout' );

    can please someone tell me where to put the functions provided here because I don’t know where to place that code and then start using my shortcode

    Plugin Author David Jensen

    (@dkjensen)

    @hassamsharik007 You can add the code to your child theme functions.php file or use a plugin like Code Snippets.

    @jorgehoffmann How would the HTML code be to pass those parameters? please an example

    @dkjensen thanks

    Thread Starter Jorge Razor

    (@jorgehoffmann)

    Hi, @anuarsaba ??

    I’ve created a form on the single product page that opens a bootstrap modal where the customer can choose between open the PDF in a new window or receive it by e-mail:

    <form id="orcamento-single-product-form" method="GET" action="<?php echo wc_get_cart_url(); ?>" target="_blank" class="w-100 br-24 mt-5 mt-lg-0">
    <?php wp_nonce_field('cart-pdf', '_wpnonce', false, true ); ?>
    <input class="d-none" type="text" readonly="readonly" name="cart-pdf" value="1" />
    <input class="d-none" type="text" readonly="readonly" name="pagina" value="2" />
    <input class="d-none" type="text" readonly="readonly" name="idproduto" value="<?php the_ID(); ?>" />
    <input class="d-none" type="text" readonly="readonly" id="precoproduto" name="precoproduto" value="" />
    <input class="d-none" type="text" readonly="readonly" id="emailorcamento" name="email" value="" />
    <button id="enviar-form-personalizacao" type="submit" class="d-none">BAIXAR OR?AMENTO</button>
    <div class="divisor-texto mb-4 mt-3"></div>
    <a href="#" class="cor-roxo hover-roxo text-center text-lg-start d-inline-block w-100" title="Baixar or?amento" data-bs-toggle="modal" data-bs-target="#modal-orcamento-passo-1"><b>BAIXAR OR?AMENTO ></b></a>
    <small id="orcamento-texto" class="d-none mb-4">*Selecione todos os componentes para habilitar o bot?o de or?amento.</small>
    </form>

    Then I modified the code on the plugin file (not recommended, but needed to achive what I wanted it) plugins/wc-cart-pdf/wc-cart-pdf.php to menage the parameters and behave the way I wanted, generating the PDF on the browser or send it via email to the custumer (with wp_mail).

    Hope this helps you.

Viewing 11 replies - 1 through 11 (of 11 total)
  • The topic ‘Insert button anywhere’ is closed to new replies.