Here is some of my code in function.php:
add_action('woocommerce_thankyou', 'send_thank_you_email', 1, 1);
function send_thank_you_email($order_id)
{
$order = wc_get_order($order_id);
$order_email = $order->get_billing_email();
$first_name = $order->get_billing_first_name();
$last_name = $order->get_billing_last_name();
$_req_res = _send_email_voucher($_booking_number, $_hotelname_en,
$order_email , $first_name, $last_name);
$order = wc_get_order($order_id);
.
.
.
And in _send_email_voucher function I use TCPDF to create PDF from an HTML file.
I use TCPDF beacuse the HTML file has Persian utf-8 characters, and TCPDF supports Persian characters.
function _send_email_voucher($_booking_number, $_hotelname_en, $_hotelname_fa, $_roomType_en, $_roomType_fa,
$_chekin_en, $_chekin_fa, $_chekout_en, $_chekout_fa, $_passengers, $_hotelstar,
$_hoteladdr, $_hotelphone, $_xtra_services, $_to_address, $_to_name, $_subject = "???? ???? ???",
$_depart_flight_number, $_depart_date_time, $_depart_flight_aircraft, $_depart_flight_airline,
$_return_flight_number, $return_date_time, $_return_flight_aircraft, $_return_flight_airline
){
ob_start();
include("voucher.php");
$_body = ob_get_contents();
$pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
$pdf->setCreator(PDF_CREATOR);
$pdf->setAuthor('Nicola Asuni');
$pdf->setTitle('TCPDF Example 018');
$pdf->setSubject('TCPDF Tutorial');
$pdf->setKeywords('TCPDF, PDF, example, test, guide');
// set default header data
$pdf->setHeaderData(PDF_HEADER_LOGO, PDF_HEADER_LOGO_WIDTH, PDF_HEADER_TITLE.' 018', PDF_HEADER_STRING);
// set header and footer fonts
$pdf->setHeaderFont(Array(PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN));
$pdf->setFooterFont(Array(PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA));
// set default monospaced font
$pdf->setDefaultMonospacedFont(PDF_FONT_MONOSPACED);
// set margins
$pdf->setMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT);
$pdf->setHeaderMargin(PDF_MARGIN_HEADER);
$pdf->setFooterMargin(PDF_MARGIN_FOOTER);
// set auto page breaks
$pdf->setAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);
// set image scale factor
$pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);
// set some language dependent data:
$lg = Array();
$lg['a_meta_charset'] = 'UTF-8';
$lg['a_meta_dir'] = 'rtl';
$lg['a_meta_language'] = 'fa';
$lg['w_page'] = 'page';
// set some language-dependent strings (optional)
$pdf->setLanguageArray($lg);
$pdf->setFont('dejavusans', '', 12);
$pdf->AddPage();
$pdf->setRTL(true);
$htmlpersian = '<span color="#660000">Persian example:</span><br />???? ??????? ???? PDF ????? ?? ??? ???? ?? ??. ???? ?? ?????.<br />???? ??? \"?\" ?? ???? ????? ????? ???? ???? ??? ?? ??? ??.<br />????? ???? ??? ? ??? ??? ?? ?? ??? ????? ??.<br />?? ???? ?? "Asuni Nicola" ? ???? ??? ?? ??? ???? ???????? ???? ?????.';
$pdf->WriteHTML($htmlpersian, true, 0, true, 0);
$pdf->Output('example_018.pdf', 'I');
.
.
.
But I get the following error:
TCPDF ERROR:?Some data has already been output, can’t send PDF file
For solving problem I use ob_start, But the problem still persists.
I know taht the problem is in the Thankyou Page already been output, what I don’t know is ?ow do I make my function “send_thank_you_email” the first thing to be executed?
Or is there any other way to Email this PDF file without problem?
]]>Este es el código que tengo por ahora:
add_action( ‘woocommerce_thankyou’, function () {
$sms = “Hola%20”;
$urls = ‘https://api.whatsapp.com/send?phone=57300000000&text=’ .$sms ;
$urln = ‘https://api.whatsapp.com/send?phone=57311111111&text=’ .$sms ;
if ( ! $order->has_status( ‘failed’ ) ) {
if ($order_billing_state == “S-SUR”) {
wp_redirect( $urls );
exit;
} else {
wp_redirect( $urln );
exit;
}
}
}
Les agradezco mucho si me pueden ayudar…
]]>My goal is to call a synch task with an external ERP to update the stock of the product just purchased.
Thanks for any advice
regards
ad
add_action(‘woocommerce_thankyou’, ‘send_order_information_for_delivery’, 999, 1);
function send_order_information_for_delivery($order_id)
{
$order = wc_get_order($order_id);
$order_items = $order->get_items();
.
.
.
}
Any idea why sometimes doesn’t work?
Thanks a lot!
]]>I’m trying to add a new role to a user who buys a product (=annual fee).
But my php code doesn’t work. It seems that the function I created is not used at all.
What is wrong in the following code that I add in the function.php file of the child theme ?
/** Add a new user type : adherent
* with limited possibilities
* the purpose is only to keep the info that the current user has paid the annual fee
*/
$result = add_role( ‘adherent’, __(
‘Adherent’ ),
array(
‘read’ => true, // true allows this capability
‘edit_posts’ => false, // user can’t edit their own posts
‘edit_pages’ => false, // user can’t edit pages
‘edit_others_posts’ => false, // user can’t edit others posts not just their own
‘create_posts’ => false, // user can’t create new posts
‘manage_categories’ => false, // user can’t manage post categories
‘publish_posts’ => false, // user can’t publish, otherwise posts stays in draft mode
‘edit_themes’ => false, // false denies this capability. User can’t edit your theme
‘install_plugins’ => false, // User cant add new plugins
‘update_plugin’ => false, // User can’t update any plugins
‘update_core’ => false // user cant perform core updates
)
);
/**
* When a user pays the annual fee, a new role is added : adherent
*/
add_action( ‘woocommerce_thankyou’, ‘the_user_is_updated’ );
function the_user_is_updated( $order_id ) {
$order = wc_get_order($order_id);
// Only continue if have $order_id
if ( ! $order_id ) {
echo ‘no current order’;
return;
}
$user_id = $order->get_user_id();
$user_id->add_role(‘adherent’);
echo ‘user updated’;
}
Thanks for your help
]]>I’m trying to add a new role to a user who buys a product (=annual fee).
But my php code doesn’t work. It seems that the function I created is not used at all.
What is wrong in the following code that I add in the function.php file of the child theme ?
/** Add a new user type : adherent
* with limited possibilities
* the purpose is only to keep the info that the current user has paid the annual fee
*/
$result = add_role( ‘adherent’, __(
‘Adherent’ ),
array(
‘read’ => true, // true allows this capability
‘edit_posts’ => false, // user can’t edit their own posts
‘edit_pages’ => false, // user can’t edit pages
‘edit_others_posts’ => false, // user can’t edit others posts not just their own
‘create_posts’ => false, // user can’t create new posts
‘manage_categories’ => false, // user can’t manage post categories
‘publish_posts’ => false, // user can’t publish, otherwise posts stays in draft mode
‘edit_themes’ => false, // false denies this capability. User can’t edit your theme
‘install_plugins’ => false, // User cant add new plugins
‘update_plugin’ => false, // User can’t update any plugins
‘update_core’ => false // user cant perform core updates
)
);
/**
* When a user pays the annual fee, a new role is added : adherent
*/
add_action( ‘woocommerce_thankyou’, ‘the_user_is_updated’ );
function the_user_is_updated( $order_id ) {
$order = wc_get_order($order_id);
// Only continue if have $order_id
if ( ! $order_id ) {
echo ‘no current order’;
return;
}
$user_id = $order->get_user_id();
$user_id->add_role(‘adherent’);
echo ‘user updated’;
}
Thanks for your help
]]>This line is
wc_get_template( ‘checkout/thankyou.php’, array( ‘order’ => $order ) );
Any one idea to correct it?
(woocommerce 2.3.7)
Thanks in avance
Paco.
https://www.ads-software.com/plugins/woocommerce/
]]>the function for displaying stuff on the thank you page of a woocommerce shop?
I have been using it too add tracking tools, but it stopped working, my code isnt inserted anymore on purchase?
Thanks
https://www.ads-software.com/plugins/woocommerce/
]]>