How to properly send file from Custom field on Email(PayPal)
-
Hello guys, I’m working on a portfolio page in which the user can buy a product and if the purchase was successful an email should be sent to him with the product attachment according to the product ID.
I created two custom fields. One for setting the price and a second one for getting the file(or a link.)
Custom Field for setting the price:
// Price to buy product with Paypal function comprar_url($postID){ $comprar_url = 'Precio para comprar Archivo con Paypal'; $producto_url = get_post_meta($postID, $comprar_url, true); if($producto_url==''){ delete_post_meta($postID,$comprar_url); add_post_meta($postID,$comprar_url, '#'); return "#"; } return $producto_url; }
Custom field to get the file:
// URL de descarga de archivo function descargar_url($postID){ $descargar_url = 'URL para descargar Archivo'; $archivo_url = get_post_meta($postID, $descargar_url, true); if($archivo_url==''){ delete_post_meta($postID,$descargar_url); add_post_meta($postID,$descargar_url, '#'); return "#"; } return $archivo_url; }
Having created those two custom fields I added a form to make the purchase of the product(according to the ID) in the Front End:
<!-- Paypal Button --> <?php $producto_url = get_post_meta($post->ID, 'Precio para comprar Archivo con Paypal', true); ?> <?php if ($producto_url == '#') : ?> <?php else : ?> <form action="https://www.paypal.com/cgi-bin/webscr" method="post"> <input type="hidden" name="cmd" value="_xclick"> <!-- The PayPal account to pay --> <input type="hidden" name="business" id="business" value="<?php bloginfo('admin_email'); ?>" /> <!-- Amount price --> <input type="hidden" name="amount" id="amount" value="<?php echo comprar_url(get_the_ID()); ?>" /> <!-- It will be shown on PayPal checkout page --> <input type="hidden" name="item_name" id="item_name" value="<?php the_title(); ?>" /> <!-- Specify your product ID here to process it later --> <input type="hidden" name="item_number" id="item_number" value="<?php the_id(); ?>" /> <!-- Charset --> <input type="hidden" name="charset" value="utf-8"> <!-- Currency --> <input type="hidden" name="currency_code" value="USD"> <!-- Thank You page, the customer will be redirected after the payment --> <input type="hidden" name="return" value="<?php echo site_url(); ?>"> <button type="submit" class="btn btn-success btn-sm"><i class="fa fa-paypal" aria-hidden="true"></i></button> </form> <?php endif; ?>
Now in the code above I’m getting the proper values from the custom field to set the price.
The problem that I have is in another document in which I handle whether the purchase was successful or not. Here it is:
$r = array( 'status' => $_POST['payment_status'], 'payer_email' => $_POST['payer_email'] ); if( isset( $_POST['item_number'] ) ) { $r['item_number'] = intval($_POST['item_number']); } elseif ( isset( $_POST['item_number1'] ) ) { $r['item_number'] = intval($_POST['item_number1']); } if( strtolower( $_POST['payment_status'] ) == 'completed' && $r['item_number'] ) { /* * On success - do some stuff here, you can: * send the product by email */ // Download Button $archivo_url = get_post_meta($post->ID, 'URL para descargar Archivo', true); if ($archivo_url == '#') : echo 'Sorry, there's has been an error with the download. Please, contact the websmaster'; else : $plugin_path = echo "" descargar_url(get_the_ID()); ""; // I can store this info from custom field $headers = 'From: Admin <no-reply@demo.com>' . "\r\n"; wp_mail( $_POST['stripeEmail'], 'Thanks for buying with us', 'The product is attached to this email.', $headers, $attachments ); endif; exit(); } exit();
Is it possible to get the values from the custom fiel in the email?… can you check my code, please?.
Thanks in advanced for helping out.
- The topic ‘How to properly send file from Custom field on Email(PayPal)’ is closed to new replies.