WC Cart PDF template CUSTOM
-
Your plugin is excellent, my question is, is there a way that the client that generates their pdf before can fill in their data such as name, company name and a logo of their company to then be able to share the budget that they will generate in pdf?
-
Hello
Yes this can be done but it will require custom programming. Here is a sample form which will add form inputs via URL parameters to the generate PDF URL:
<form method="get" action="<?php echo esc_url( wc_get_cart_url() );?>"> <p> <label for="quote-name"><?php esc_html_e( 'Name' ); ?></label> <input type="text" id="quote-name" name="quote-name" tabindex="10" required /> </p> <p> <label for="quote-email"><?php esc_html_e( 'Email' ); ?></label> <input type="email" id="quote-email" name="quote-email" tabindex="11" required /> </p> <p> <label for="quote-tel"><?php esc_html_e( 'Phone' ); ?></label> <input type="tel" id="quote-tel" name="quote-tel" tabindex="12" required /> </p> <input type="hidden" name="cart-pdf" value="1" /> <?php wp_nonce_field( 'cart-pdf' ); ?> <button type="submit" class="button"><?php esc_html_e( 'Generate Quote' ); ?></button> </form>
You can modify this form to your use case, the image upload feature will take some extra customization.
Then you can copy the PDF template from the plugin folder
wc-cart-pdf/templates/cart-table.php
into your child theme folderchild-theme/woocommerce/wc-cart-pdf/cart-table.php
.Modify the
cart-table.php
file inside your child theme to retrieve the form values via the $_GET parameters and render them on your PDFLet me know if this helps at all
excellent, if I put the form inside my php wc-cart-pdf.php removing the button
<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">
and it appears in my cart to be able to fill the data that I want to add to my PDF, now in my child theme I have to put in my cart-table.php the code to take by GET but I don’t know where to print it I think I should use the esc_url function or do I have to use echo?
I have to put something like that
<?php /** * WC Cart PDF template * * @package wc-cart-pdf */ /** * Before template hook * * @since 1.0.4 */ do_action( 'wc_cart_pdf_before_template' ); $logo = parse_url( get_option( 'wc_cart_pdf_logo', get_option( 'woocommerce_email_header_image' ) ), PHP_URL_PATH ); $logo = ! $logo ? '' : $_SERVER['DOCUMENT_ROOT'] . $logo; $quote_name = $_GET["quote_name"]; $quote_mail = $_GET["quote_mail"]; ?>
and print in pdf how?
Tu email es: <?php isset($_GET["quote-email"]) ? print $_GET["quote-email"] : ""; ?>
that print in pdf and now i put css style to order?
That’s correct, but you will want to escape the output like this
<?php isset( $_GET["quote-email"] ) ? print esc_html( $_GET["quote-email"] ) : ""; ?>
To add CSS, copy the plugin template file
wc-cart-pdf/templates/pdf-styles.php
into your child theme folderchild-theme/woocommerce/wc-cart-pdf/pdf-styles.php
.From there you can modify the
pdf-styles.php
and adjust the CSS as necessaryexcellent, those steps are already solved, and understood, only 2 more steps. the image they can raise I have to do with POST right?
something like that?<form action="index.php" method="POST" enctype="multipart/form-data"/> A?adir imagen: <input name="archivo" id="archivo" type="file"/> <input type="submit" name="subir" value="Subir imagen"/> </form>
to verify that it is image and its weight in kb, this php I have to put where?
<?php //Si se quiere subir una imagen if (isset($_POST['subir'])) { //Recogemos el archivo enviado por el formulario $archivo = $_FILES['archivo']['name']; //Si el archivo contiene algo y es diferente de vacio if (isset($archivo) && $archivo != "") { //Obtenemos algunos datos necesarios sobre el archivo $tipo = $_FILES['archivo']['type']; $tamano = $_FILES['archivo']['size']; $temp = $_FILES['archivo']['tmp_name']; //Se comprueba si el archivo a cargar es correcto observando su extensión y tama?o if (!((strpos($tipo, "gif") || strpos($tipo, "jpeg") || strpos($tipo, "jpg") || strpos($tipo, "png")) && ($tamano < 2000000))) { echo '<div><b>Error. La extensión o el tama?o de los archivos no es correcta.<br/> - Se permiten archivos .gif, .jpg, .png. y de 200 kb como máximo.</b></div>'; } else { //Si la imagen es correcta en tama?o y tipo //Se intenta subir al servidor if (move_uploaded_file($temp, 'images/'.$archivo)) { //Cambiamos los permisos del archivo a 777 para poder modificarlo posteriormente chmod('images/'.$archivo, 0777); //Mostramos el mensaje de que se ha subido co éxito echo '<div><b>Se ha subido correctamente la imagen.</b></div>'; //Mostramos la imagen subida echo '<p><img src="images/'.$archivo.'"></p>'; } else { //Si no se ha podido subir la imagen, mostramos un mensaje de error echo '<div><b>Ocurrió algún error al subir el fichero. No pudo guardarse.</b></div>'; } } } } ?>
And how do I capture that image in the cart table? Or something easier? , and the last thing to finish and result in this and a great contribution for others, is how can I make my wordpress only appear to certain users by role or how can I move the entire system to a page so that not just any user see it? Thank you very much for your patience and for answering me so far.
You can use the
wc_cart_pdf_before_process
action hook to do some of your processing before rendering the PDF. When you have your image successfully moved to the correct location using yourmove_uploaded_file
function, you can then retrieve the URL in the PDF. You might have to use the absolute location to the image, such as/var/www/html/images/your-image.jpg
instead of the typical URL format.Hola Cuantum, yo quiero hacer lo mismo, pero no entendi la forma, serias tan amable de explicar como lo hiciste? Te agradeceria mucho.
SaludosHello David! Congratulations for your Plugin!
I have the same question, I would like to implement the same, but I do not understand how@nicoderen Thanks! What specifically are you wanting to customize?
“is there a way that the client that generates their pdf before can fill in their data such as name, company name and a logo of their company to then be able to share the budget that they will generate in pdf?”
If you have some files to do this.
This type of customization requires a bit of knowledge in PHP programming, I do not have any files I can show you but if you want to give it a stab there is some useful information in this thread.
- The topic ‘WC Cart PDF template CUSTOM’ is closed to new replies.