/**
  * Handle a completed payment
  * @param  WC_Order $order
  */
 private function payment_status_completed($order, $posted)
 {
     if ($order->has_status('completed')) {
         $this->log('Aborting, Order #' . $order->id . ' is already complete.');
         exit;
     }
     $this->validate_transaction_type($posted['txn_type']);
     $this->validate_currency($order, $posted['mc_currency']);
     $this->validate_amount($order, $posted['mc_gross']);
     $this->validate_receiver_email($order, $posted['receiver_email']);
     $this->save_paypal_meta_data($order, $posted);
     if ('completed' === $posted['payment_status']) {
         $this->payment_complete($order, !empty($posted['txn_id']) ? wc_clean($posted['txn_id']) : '', __('IPN payment completed', 'woocommerce'));
     } else {
         $this->payment_on_hold($order, sprintf(__('Payment pending: %s', 'woocommerce'), $posted['pending_reason']));
     }
 }
 /**
  * Add content to the WC emails.
  *
  * @access public
  * @param WC_Order $order
  * @param bool $sent_to_admin
  * @param bool $plain_text
  *
  * @return void
  */
 public function email_instructions($order, $sent_to_admin, $plain_text = false)
 {
     if (!$sent_to_admin && 'bKash' === $order->payment_method && $order->has_status('on-hold')) {
         if ($this->instructions) {
             echo wpautop(wptexturize($this->instructions)) . PHP_EOL;
         }
     }
 }
Пример #3
0
 /**
  * Add content to the WC emails.
  *
  * Note: The difference from WC_Gateway_BACS is that we use __() before
  * passing the string through wptexturize() and wpautop().
  *
  * @param WC_Order $order
  * @param bool     $sent_to_admin
  * @param bool     $plain_text
  */
 public function email_instructions($order, $sent_to_admin, $plain_text = false)
 {
     if (!$sent_to_admin && 'bacs' === $order->payment_method && $order->has_status('on-hold')) {
         if ($this->instructions) {
             echo wpautop(wptexturize(function_exists('pll__') ? pll__($this->instructions) : __($this->instructions, 'woocommerce'))) . PHP_EOL;
         }
         $this->bank_details($order->id);
     }
 }
 /**
  * Checks if the subscription has an unpaid order or renewal order (and therefore, needs payment).
  *
  * @param string $subscription_key A subscription key of the form created by @see self::get_subscription_key()
  * @param int $user_id The ID of the user who owns the subscriptions. Although this parameter is optional, if you have the User ID you should pass it to improve performance.
  * @return bool True if the subscription has an unpaid renewal order, false if the subscription has no unpaid renewal orders.
  * @since 2.0
  */
 public function needs_payment()
 {
     $needs_payment = false;
     // First check if the subscription is pending or failed or is for $0
     if (parent::needs_payment()) {
         $needs_payment = true;
         // Now make sure the parent order doesn't need payment
     } elseif (false !== $this->order && ($this->order->needs_payment() || $this->order->has_status('on-hold'))) {
         $needs_payment = true;
         // And finally, check that the last renewal order doesn't need payment
     } else {
         $last_renewal_order_id = get_posts(array('posts_per_page' => 1, 'post_type' => 'shop_order', 'post_status' => 'any', 'fields' => 'ids', 'orderby' => 'ID', 'order' => 'DESC', 'meta_query' => array(array('key' => '_subscription_renewal', 'compare' => '=', 'value' => $this->id, 'type' => 'numeric'))));
         if (!empty($last_renewal_order_id)) {
             $renewal_order = new WC_Order($last_renewal_order_id[0]);
             if ($renewal_order->needs_payment() || $renewal_order->has_status(array('on-hold', 'failed', 'cancelled'))) {
                 $needs_payment = true;
             }
         }
     }
     return apply_filters('woocommerce_subscription_needs_payment', $needs_payment, $this);
 }
Пример #5
0
 /**
  * This part is returnurl function for epayph
  * 
  * @global mixed $woocommerce
  */
 function check_epayph_response_returnurl($posted)
 {
     global $woocommerce;
     if (!empty($_POST) && $this->validate_ipn()) {
         $order = new WC_Order($_POST['invoice']);
         switch ($_REQUEST['payment_status']) {
             case 'Completed':
                 $order->add_order_note('ePay.ph Payment Status: SUCCESSFUL' . '<br>Transaction ID: ' . $tranID . $referer);
                 $order->payment_complete();
                 wp_redirect($order->get_checkout_order_received_url());
                 break;
             case 'Pending':
                 if ($order->has_status('completed')) {
                     exit;
                 } else {
                     $order->add_order_note('ePay.ph Payment Status: PENDING');
                     $order->update_status('pending', __('Awaiting Payment Approval', 'woocommerce'));
                     //wp_redirect($order->get_checkout_order_received_url());
                 }
                 break;
             case 'Cancelled':
                 $order->add_order_note('ePay.ph Payment Status: FAILED');
                 $order->update_status('failed', __('Payment Failed', 'woocommerce'));
                 //wp_redirect($order->get_cancel_order_url());
                 break;
             case 'Refunded':
                 $order->add_order_note('ePay.ph Payment Status: Refunded');
                 $order->update_status('refunded', __('Payment Refunded', 'woocommerce'));
                 //wp_redirect($order->get_cancel_order_url());
                 break;
             case 'Display':
                 break;
             default:
                 $order->add_order_note('ePay.ph Payment Status: Invalid Transaction');
                 $order->update_status('on-hold', __('Invalid Transaction', 'woocommerce'));
                 //wp_redirect($order->get_cancel_order_url());
         }
         exit;
     }
 }
 /**
  * Successful Payment!
  **/
 function successful_request($posted)
 {
     $order = new WC_Order((int) $posted["wooorderid"]);
     $var = "";
     if (strlen($this->md5key) > 0) {
         foreach ($posted as $key => $value) {
             if ($key != "hash") {
                 $var .= $value;
             }
         }
         $genstamp = md5($var . $this->md5key);
         if ($genstamp != $posted["hash"]) {
             echo "MD5 error";
             error_log('MD5 check failed for ePay callback with order_id:' . $posted["wooorderid"]);
             status_header(500);
             exit;
         }
     }
     if ($order->has_status('pending')) {
         // Payment completed
         $order->add_order_note(__('Callback completed', 'woocommerce-gateway-epay-dk'));
         if ($this->settings["addfeetoorder"] == "yes") {
             $order_fee = new stdClass();
             $order_fee->id = 'epay_fee';
             $order_fee->name = __('Fee', 'woocommerce-gateway-epay-dk');
             $order_fee->amount = isset($posted['txnfee']) ? floatval($posted['txnfee'] / 100) : 0;
             $order_fee->taxable = false;
             $order_fee->tax = 0;
             $order_fee->tax_data = array();
             $order->add_fee($order_fee);
             $order->set_total($order->order_total + floatval($posted['txnfee'] / 100));
         }
         $order->payment_complete();
         update_post_meta((int) $posted["wooorderid"], 'Transaction ID', $posted["txnid"]);
         update_post_meta((int) $posted["wooorderid"], 'Card no', $posted["cardno"]);
         if (isset($posted["subscriptionid"])) {
             update_post_meta((int) $posted["wooorderid"], 'Subscription ID', $posted["subscriptionid"]);
         }
     }
     echo "OK";
     status_header(200);
     exit;
 }
 /**
  * Mark the given order as cancelled and set the order note
  *
  * @since 2.1.0
  * @param WC_Order $order the order
  * @param string $error_message a message to display inside the "Payment Cancelled" order note
  * @param SV_WC_Payment_Gateway_API_Response optional $response the transaction response object
  */
 public function mark_order_as_cancelled($order, $message, $response = null)
 {
     $order_note = sprintf(_x('%s Transaction Cancelled (%s)', 'Cancelled order note', $this->text_domain), $this->get_method_title(), $message);
     // Mark order as cancelled if not already set
     if (!$order->has_status('cancelled')) {
         $order->update_status('cancelled', $order_note);
     } else {
         $order->add_order_note($order_note);
     }
     $this->add_debug_message($message, 'error');
 }
 /**
  * Called when a sign up fails during the payment processing step.
  *
  * @param WC_Order|int $order The order or ID of the order for which subscriptions should be marked as failed.
  * @since 1.0
  */
 public static function failed_subscription_sign_ups_for_order($order)
 {
     $subscriptions = wcs_get_subscriptions_for_order($order, array('order_type' => 'parent'));
     if (!empty($subscriptions)) {
         if (!is_object($order)) {
             $order = new WC_Order($order);
         }
         // Set subscription status to failed and log failure
         if ($order->has_status('failed')) {
             $order->update_status('failed', __('Subscription sign up failed.', 'woocommerce-subscriptions'));
         }
         foreach ($subscriptions as $subscription) {
             try {
                 $subscription->payment_failed();
             } catch (Exception $e) {
                 // translators: $1: order number, $2: error message
                 $subscription->add_order_note(sprintf(__('Failed to process failed payment on subscription for order #%1$s: %2$s', 'woocommerce-subscriptions'), is_object($order) ? $order->get_order_number() : $order, $e->getMessage()));
             }
         }
         do_action('failed_subscription_sign_ups_for_order', $order);
     }
 }
 /**
  * Checks if the WooCommerce order has this specific status
  */
 public function hasOrderStatus(WC_Order $order, $status)
 {
     return $order->has_status($status);
 }
 /**
  * Add content to the WC emails.
  *
  * @param WC_Order $order
  * @param bool $sent_to_admin
  * @param bool $plain_text
  */
 public function email_instructions($order, $sent_to_admin, $plain_text = false)
 {
     if (!$sent_to_admin && 'bacs' === $order->get_payment_method() && $order->has_status('on-hold')) {
         if ($this->instructions) {
             echo wpautop(wptexturize($this->instructions)) . PHP_EOL;
         }
         $this->bank_details($order->get_id());
     }
 }
Пример #11
0
function swr_give_older_orders_rewards()
{
    global $swr_settings, $woocommerce;
    if (!isset($_GET['give_older_orders_rewards']) || $_GET['give_older_orders_rewards'] != 1) {
        return;
    }
    $orders = get_posts(array('numberposts' => -1, 'post_type' => 'shop_order'));
    if ($orders && count($orders) > 0) {
        foreach ($orders as $order) {
            if (version_compare($woocommerce->version, '2.2.0') >= 0) {
                $order = new WC_Order($order->ID);
                $reward = $swr_settings->get_reward_earned_for_order($order->id);
                if (!$reward) {
                    swr_update_order_meta($order->id, false);
                    if ($order->has_status("completed")) {
                        swr_add_reward($order->id);
                    }
                }
            } else {
                $terms = wp_get_object_terms($order->ID, 'shop_order_status', array('fields' => 'slugs'));
                $status = isset($terms[0]) ? $terms[0] : 'pending';
                $reward = $swr_settings->get_reward_earned_for_order($order->ID);
                if (!$reward) {
                    swr_update_order_meta($order->ID, false);
                    if ($status == 'completed') {
                        swr_add_reward($order->ID);
                    }
                }
            }
        }
    }
}
 /**
  * Handle a captured payment
  * @param  WC_Order $order
  */
 protected function payment_status_captured($order, $posted)
 {
     if ($order->has_status('captured')) {
         WC_Gateway_Komoju::log('Aborting, Order #' . $order->id . ' is already complete.');
         exit;
     }
     $this->validate_currency($order, $posted['currency']);
     $this->validate_amount($order, $posted['grand_total'] - $posted['payment_method_fee']);
     $this->save_komoju_meta_data($order, $posted);
     if ('captured' === $posted['status']) {
         $this->payment_complete($order, !empty($posted['external_order_num']) ? wc_clean($posted['external_order_num']) : '', __('IPN payment captured', 'woocommerce'));
         if (!empty($posted['payment_method_fee'])) {
             // log komoju transaction fee
             update_post_meta($order->id, 'Payment Gateway Transaction Fee', wc_clean($posted['payment_method_fee']));
         }
     } else {
         $this->payment_on_hold($order, sprintf(__('Payment pending: %s', 'woocommerce'), $posted['additional_information']));
     }
 }
Пример #13
0
}
?>
	</div>
</div>
	<div id="content">
	
		<div id="inner-content" class="row">
		    <main id="main" class="large-12 medium-12 columns" role="main">
								<?php 
global $woocommerce;
$order = new WC_Order($order_id);
if ($order) {
    ?>

	<?php 
    if ($order->has_status('failed')) {
        ?>

		<p class="woocommerce-thankyou-order-failed"><?php 
        _e('Unfortunately your order cannot be processed as the originating bank/merchant has declined your transaction. Please attempt your purchase again.', 'woocommerce');
        ?>
</p>

		<p class="woocommerce-thankyou-order-failed-actions">
			<a href="<?php 
        echo esc_url($order->get_checkout_payment_url());
        ?>
" class="button pay"><?php 
        _e('Pay', 'woocommerce');
        ?>
</a>
Пример #14
0
 /**
  * Mark the given order as failed, and set the order note
  *
  * @param WC_Order $order the order
  * @param string $order_note the order note to set
  */
 public function order_failed($order, $order_note)
 {
     if (!$order->has_status('failed')) {
         $order->update_status('failed', $order_note);
     } else {
         // otherwise, make sure we add the order note so we can detect when someone fails to check out multiple times
         $order->add_order_note($order_note);
     }
 }
 /**
  * My Orders custom actions.
  * Remove the pay button when the booking requires confirmation.
  *
  * @param  array $actions
  * @param  WC_Order $order
  * @return array
  */
 public function my_orders_actions($actions, $order)
 {
     global $wpdb;
     if ($order->has_status('pending') && 'wc-booking-gateway' === $order->payment_method) {
         $status = array();
         foreach ($order->get_items() as $order_item_id => $item) {
             if ('line_item' == $item['type']) {
                 $_status = $wpdb->get_col($wpdb->prepare("\n\t\t\t\t\t\tSELECT posts.post_status\n\t\t\t\t\t\tFROM {$wpdb->postmeta} AS postmeta\n\t\t\t\t\t\t\tLEFT JOIN {$wpdb->posts} AS posts ON (postmeta.post_id = posts.ID)\n\t\t\t\t\t\tWHERE postmeta.meta_key = '_booking_order_item_id'\n\t\t\t\t\t\tAND postmeta.meta_value = %d\n\t\t\t\t\t", $order_item_id));
                 $status = array_merge($status, $_status);
             }
         }
         if (in_array('pending-confirmation', $status) && isset($actions['pay'])) {
             unset($actions['pay']);
         }
     }
     return $actions;
 }
 /**
  * Check if the order has the given status
  *
  * @param WC_Order $order
  * @param string|array $status single status or array of statuses to check
  * @since 3.0.0
  * @return bool
  */
 public static function order_has_status($order, $status)
 {
     if (self::is_wc_version_gte_2_2()) {
         return $order->has_status($status);
     } else {
         if (is_array($status)) {
             return in_array($order->status, $status);
         } else {
             return $status === $order->status;
         }
     }
 }
 /**
  * Handle a completed payment.
  * @param WC_Order $order
  * @param array $posted
  */
 protected function payment_status_completed($order, $posted)
 {
     if ($order->has_status(array('processing', 'completed'))) {
         WC_Gateway_Paypal::log('Aborting, Order #' . $order->get_id() . ' is already complete.');
         exit;
     }
     $this->validate_transaction_type($posted['txn_type']);
     $this->validate_currency($order, $posted['mc_currency']);
     $this->validate_amount($order, $posted['mc_gross']);
     $this->validate_receiver_email($order, $posted['receiver_email']);
     $this->save_paypal_meta_data($order, $posted);
     if ('completed' === $posted['payment_status']) {
         $this->payment_complete($order, !empty($posted['txn_id']) ? wc_clean($posted['txn_id']) : '', __('IPN payment completed', 'woocommerce'));
         if (!empty($posted['mc_fee'])) {
             // Log paypal transaction fee.
             update_post_meta($order->get_id(), 'PayPal Transaction Fee', wc_clean($posted['mc_fee']));
         }
     } else {
         if ('authorization' === $posted['pending_reason']) {
             $this->payment_on_hold($order, __('Payment authorized. Change payment status to processing or complete to capture funds.', 'woocommerce'));
         } else {
             $this->payment_on_hold($order, sprintf(__('Payment pending (%s).', 'woocommerce'), $posted['pending_reason']));
         }
     }
 }
Пример #18
0
 /**
  * Test: has_status
  */
 function test_has_status()
 {
     $object = new WC_Order();
     $this->assertFalse($object->has_status('completed'));
     $this->assertFalse($object->has_status(array('processing', 'completed')));
     $this->assertTrue($object->has_status('pending'));
     $this->assertTrue($object->has_status(array('processing', 'pending')));
 }
 /**
  * Add content to the WC emails.
  *
  * @access public
  * @param  WC_Order $order
  * @param  bool $sent_to_admin
  * @param  bool $plain_text
  */
 public function email_instructions($order, $sent_to_admin, $plain_text = false)
 {
     if (!$sent_to_admin && $this->id === $order->payment_method && $order->has_status('pending')) {
         WC_Stellar()->stellar_instructions($order->id, 'email');
     }
 }
 /**
  * Add content to the WC emails.
  *
  * @access public
  * @param WC_Order $order
  * @param bool $sent_to_admin
  * @param bool $plain_text
  */
 public function email_instructions($order, $sent_to_admin, $plain_text = false)
 {
     if ($this->instructions && !$sent_to_admin && 'direct-debit' === $order->payment_method && $order->has_status('processing')) {
         echo wpautop(wptexturize($this->instructions)) . PHP_EOL;
     }
 }
 /**
  * Add content to the WC emails.
  *
  * @access public
  * @param WC_Order $order
  * @param bool $sent_to_admin
  * @param bool $plain_text
  * @return void
  */
 public function email_instructions($order, $sent_to_admin, $plain_text = false)
 {
     if (!$sent_to_admin && 'redlight_swish' === $order->payment_method && $order->has_status('on-hold')) {
         $this->swish_email_details($order->id);
     }
 }
 /**
  * Mark the given order as cancelled and set the order note
  *
  * @since 2.1.0
  * @param WC_Order $order the order
  * @param string $error_message a message to display inside the "Payment Cancelled" order note
  * @param SV_WC_Payment_Gateway_API_Response optional $response the transaction response object
  */
 public function mark_order_as_cancelled($order, $message, $response = null)
 {
     /* translators: Placeholders: %1$s - payment gateway title, %2$s - message/error */
     $order_note = sprintf(esc_html__('%1$s Transaction Cancelled (%2$s)', 'woocommerce-plugin-framework'), $this->get_method_title(), $message);
     // Mark order as cancelled if not already set
     if (!$order->has_status('cancelled')) {
         $order->update_status('cancelled', $order_note);
     } else {
         $order->add_order_note($order_note);
     }
     $this->add_debug_message($message, 'error');
 }
Пример #23
0
function pdf_file_creation($atts){
	
	require_once 'mpdf/mpdf.php';
	global $wpdb, $shopkeeper_theme_options;
	try{
	 $site_logo = $shopkeeper_theme_options['light_transparent_header_logo']['url'];
	//$order_id=$_REQUEST['order_id'];
	//echo $order_id;

		$order_id=$atts['order_id'];
		$order_item_id=$atts['order_item_id'];	
		
		$billing_first_name = get_post_meta($order_id,'_billing_first_name',true);
		$billing_last_name = get_post_meta($order_id,'_billing_last_name',true);
		$billing_email = get_post_meta($order_id,'_billing_email',true);

		$order=new WC_Order($order_id);
		$items = $order->get_items();
		$item_data=$items [array_keys($items)[0]];
		
		$plan_id=$item_data['item_meta']['_product_id'][0];
		$site_id=get_current_blog_id();
		$plan_details=get_post($plan_id);
		$plan_period=get_post_meta($plan_id,'plan_period',true);
		$path = wp_upload_dir();
		$pdfname='';
		
		$order_details=$wpdb->get_results('select id,meals_per_day,no_of_weeks,regenerate,current_weight from up_user_nutrition_plans where order_id='.$order_id.' AND site_id='.$site_id);
		
		$weight_range=$wpdb->get_results('select expected_weight from up_plan_logs where user_nutrition_plan_id=(select id from  up_user_nutrition_plans where order_id='.$order_id.' AND site_id='.$site_id.')',ARRAY_N);
		
		$no_of_weeks=$order_details[0]->no_of_weeks;

		if(isset($order_details) && !empty($order_details)){
		  
			$plan_name=$items [array_keys($items)[0]]['name'];
			$username="******";
			$password="******";
			$opts = array(
				  'http'=>array(
					'method'=>"GET",
					'header'=>"Accept-language: en\r\n" .
							  "Cookie: foo=bar\r\n".
							  "Authorization: Basic " . base64_encode("$username:$password")
				  )
				);
		
			$context = stream_context_create($opts);
			
			$html1=file_get_contents(home_url().'/pdf1/?order_id='.$order_id,false,$context);
		 
			$html2=file_get_contents(home_url().'/pdf2/?order_id='.$order_id,false,$context);
			  
			$html3=file_get_contents(home_url().'/pdf3/?order_id='.$order_id,false,$context);
			
			  //echo $html1;
			for($i=1;$i<=$no_of_weeks;$i++){
			
				$weight_range_new[$i]=$weight_range[$i-1][0];
				
				// echo $weight_range_new[$i].'<br/>';
				// echo "in for loop".$i;
				$html4[$i]=file_get_contents(home_url().'/pdf4/?order_id='.$order_id.'&week_no='.$i,false,$context);
				  
				$html5[$i]=file_get_contents(home_url().'/pdf5/?order_id='.$order_id.'&week_no='.$i,false,$context);
				  
				$html6[$i]=file_get_contents(home_url().'/pdf6/?order_id='.$order_id.'&week_no='.$i,false,$context);
			  
				$html7[$i]=file_get_contents(home_url().'/pdf7/?order_id='.$order_id.'&week_no='.$i,false,$context);
				 
				$html8[$i]=file_get_contents(home_url().'/pdf8/?order_id='.$order_id.'&week_no='.$i,false,$context);
			  
				$html9[$i]=file_get_contents(home_url().'/pdf9/?order_id='.$order_id.'&week_no='.$i,false,$context);
					  
				$html10[$i]=file_get_contents(home_url().'/pdf10/?order_id='.$order_id.'&week_no='.$i,false,$context);
		
				$html11[$i]=file_get_contents(home_url().'/shopping/?order_id='.$order_id.'&week_no='.$i,false,$context);
			 }
			
			
			$html12=file_get_contents(home_url().'/pdf12/?order_id='.$order_id,false,$context);
			  
			$html13=file_get_contents(home_url().'/pdf13/?order_id='.$order_id,false,$context);
			 
			//$html14=file_get_contents(home_url().'/pdf14/?order_id='.$order_id);
		//	print_r($weight_range_new);
			
		// mode, format, default_font_size, default_font, margin_left, margin_right,
				// margin_top, margin_bottom, margin_header, margin_footer, orientation
			//echo "after for loop";
			$mpdf = new mPDF('UTF-8','A4-L');
			$mpdf->defaultPagebreakType='clonebycss';
			$mpdf->SetCompression(true);
			$mpdf->useLang = true;
			//$mpdf->use_kwt = true;  
			$css=file_get_contents(get_template_directory_uri().'-child/PDF_html/pdf_style.css',false,$context);
		
			//--------------------------------------------------, L , R , T , B , 
			$mpdf->AddPage('UTF-8','A4-L', 0, 'avenir', 0,0,0,0,0,0, 'L');
			$mpdf->WriteHTML($css,1);
			
			$mpdf->WriteHTML(htmlspecialchars_decode($html1),2);
			//file_put_contents($uppath1.'status.json',json_encode(array('current'=>'58','total'=>'100')));
			$mpdf->AddPage('UTF-8','A4-L', 0, 'avenir', 0,0,0,0,0,0, 'L');
			$mpdf->WriteHTML(htmlspecialchars_decode($html2));

			$header3=__('<div style="padding:0px 0px 0px 0px;height:12mm;width:100%;background:#FFF;border:0;outline:none;margin:0;">
							<div style="padding:1px 38.4px 0px 37px;">
								 <div style="width:20%; float:left; color:#162c5d;text-align:left; line-height:10px;">
									  <p style="float:left;">Tipps & Tricks</p>
								</div>
								<div style="float:left;width:60%;text-align:center; vertical-align:middle;">
									<img style="margin-top:8px;" width="" height="28"  src="'.$site_logo.'"></div>
								<div style="float:right;width:19%;padding-right:2px; color:#162c5d;text-align:right;line-height:10px; ">
									<p>Seite {PAGENO}/{nbpg}</p>
								</div>
							</div>     
						  </div>', 'shopkeeper' );
						  
			$mpdf->SetHTMLHeader(htmlspecialchars_decode($header3));
			
		//	$mpdf->SetHTMLFooter(htmlspecialchars_decode($header3));
			$mpdf->AddPage('UTF-8','A4-L', 0, 'avenir', 0,0,0,16.7,10.18,0,0);
			$mpdf->WriteHTML(htmlspecialchars_decode($html3));
/*<div style="width:30%; float:left; color:#162c5d;text-align:left; line-height:10px;">
								  <p class="p4-header_green">Abnahme Woche '.$i.': ca. '.$min_w.' - '.$max_w.' kg</p>
							  </div> */
			for($i=1;$i<=$no_of_weeks;$i++){
				/*if($i==1){ 
					$min_w=str_replace(".",",",0.1);
				}
				else{
					//$min_w=	str_replace(".",",",(float)$order_details[0]->current_weight-(float)$weight_range_new[$i]);
					$min_w=$max_w;
				}*/
		
				$wr= (float)$order_details[0]->current_weight-(float)$weight_range_new[$i];
				$min_w=($wr*0.75);
				$max_w=($wr*1.75);
				$max_w=	number_format($max_w,"1",",","");
				$min_w=	number_format($min_w,"1",",","");

				$header4[$i]=__('<div style="padding:0px 0px 0px 0px;width:100%;background:#FFF;border:0;outline:none;margin:0;">
							<div style="padding:1px 38.4px 0px 37px;">
							  <div style="width:43%; float:left; color:#162c5d;text-align:left;padding-bottom:1px; line-height:10px;">
								  <p style="float:left;">Woche '.$i.': Montag</p>
							  </div>
							 
							  <div style="float:left;width:12%;text-align:center; vertical-align:middle;">
								<img style="margin-top:8px;" width="" height="28"  src="'.$site_logo.'">
							</div>
							  <div style="float:right;width:44%; color:#162c5d;text-align:right;line-height:10px; ">
								  <p>Seite {PAGENO}/{nbpg}</p>
							  </div>
							</div>     
						  </div>', 'shopkeeper' );
				$mpdf->SetHTMLHeader(htmlspecialchars_decode($header4[$i]));
			
				$mpdf->AddPage('UTF-8','A4-L', 0, 'avenir', 0,0,0,16.7,10.18,0,0);
				$mpdf->WriteHTML(htmlspecialchars_decode($html4[$i]));

				$header5[$i]=__('<div style="padding:0px 0px 0px 0px;width:100%;background:#FFF;border:0;outline:none;margin:0;">
							<div style="padding:1px 38.4px 0px 37px;">
							  <div style="width:43%; float:left; color:#162c5d;text-align:left; line-height:10px;">
								  <p style="float:left;">Woche '.$i.': Dienstag</p>
							  </div>
							   
							  <div style="float:left;width:12%;text-align:center; vertical-align:middle;">
								<img style="margin-top:8px;" width="" height="28"  src="'.$site_logo.'"></div>
							  <div style="float:right;width:44%; color:#162c5d;text-align:right;line-height:10px; ">
								  <p>Seite {PAGENO}/{nbpg}</p>
							  </div>
							</div>     
						  </div>', 'shopkeeper' );

				$mpdf->SetHTMLHeader(htmlspecialchars_decode($header5[$i]));
				$mpdf->AddPage('UTF-8','A4-L', 0, 'avenir', 0,0,0,16.7,10.18,0,0);
				$mpdf->WriteHTML(htmlspecialchars_decode($html5[$i]));

				$header6[$i]=__('<div style="padding:0px 0px 0px 0px;width:100%;background:#FFF;border:0;outline:none;margin:0;">
							<div style="padding:1px 38.4px 0px 37px;">
							  <div style="width:43%; float:left; color:#162c5d;text-align:left; line-height:10px;">
								  <p style="float:left;">Woche '.$i.': Mittwoch</p>
							  </div>
							 
							  <div style="float:left;width:12%;text-align:center; vertical-align:middle;">
								<img style="margin-top:8px;" width="" height="28"  src="'.$site_logo.'"></div>
							  <div style="float:right;width:44%; color:#162c5d;text-align:right;line-height:10px; ">
								  <p>Seite {PAGENO}/{nbpg}</p>
							  </div>
							</div>     
						  </div>', 'shopkeeper' );
				$mpdf->SetHTMLHeader(htmlspecialchars_decode($header6[$i]));
				$mpdf->AddPage('UTF-8','A4-L', 0, 'avenir', 0,0,0,16.7,10.18,0,0);
				$mpdf->WriteHTML(htmlspecialchars_decode($html6[$i]));

				$header7[$i]=__('<div style="padding:0px 0px 0px 0px;width:100%;background:#FFF;border:0;outline:none;margin:0;">
							<div style="padding:1px 38.4px 0px 37px;">
							  <div style="width:43%; float:left; color:#162c5d;text-align:left; line-height:10px;">
								  <p style="float:left;">Woche '.$i.': Donnerstag</p>
							  </div>
							 
							  <div style="float:left;width:12%;text-align:center; vertical-align:middle;">
								<img style="margin-top:8px;" width="" height="28"  src="'.$site_logo.'"></div>
							  <div style="float:right;width:44%; color:#162c5d;text-align:right;line-height:10px; ">
								  <p>Seite {PAGENO}/{nbpg}</p>
							  </div>
							</div>     
						  </div>', 'shopkeeper' );
				$mpdf->SetHTMLHeader(htmlspecialchars_decode($header7[$i]));
				$mpdf->AddPage('UTF-8','A4-L', 0, 'avenir', 0,0,0,16.7,10.18,0,0);
				$mpdf->WriteHTML(htmlspecialchars_decode($html7[$i]));
			
				$header8[$i]=__( '<div style="padding:0px 0px 0px 0px;width:100%;background:#FFF;border:0;outline:none;margin:0;">
							<div style="padding:1px 38.4px 0px 37px;">
							  <div style="width:43%; float:left; color:#162c5d;text-align:left; line-height:10px;">
								  <p style="float:left;">Woche '.$i.': Freitag</p>
							  </div>
							 
							   <div style="float:left;width:12%;text-align:center; vertical-align:middle;">
								<img style="margin-top:8px;" width="" height="28"  src="'.$site_logo.'"></div>
							  <div style="float:right;width:44%; color:#162c5d;text-align:right;line-height:10px; ">
								  <p>Seite {PAGENO}/{nbpg}</p>
							  </div>
							</div>     
						  </div>', 'shopkeeper' );

				$mpdf->SetHTMLHeader(htmlspecialchars_decode($header8[$i]));
				$mpdf->AddPage('UTF-8','A4-L', 0, 'avenir', 0,0,0,16.7,10.18,0,0);
				$mpdf->WriteHTML(htmlspecialchars_decode($html8[$i]));
				
				$header9[$i]=__('<div style="padding:0px 0px 0px 0px;width:100%;background:#FFF;border:0;outline:none;margin:0;">
							<div style="padding:1px 38.4px 0px 37px;">
							  <div style="width:43%; float:left; color:#162c5d;text-align:left; line-height:10px;">
								  <p style="float:left;">Woche '.$i.': Samstag</p>
							  </div>
							  
							   <div style="float:left;width:12%;text-align:center; vertical-align:middle;">
								<img style="margin-top:8px;" width="" height="28"  src="'.$site_logo.'"></div>
							  <div style="float:right;width:44%; color:#162c5d;text-align:right;line-height:10px; ">
								  <p>Seite {PAGENO}/{nbpg}</p>
							  </div>
							</div>     
						  </div>', 'shopkeeper' );
				$mpdf->SetHTMLHeader(htmlspecialchars_decode($header9[$i]));
				$mpdf->AddPage('UTF-8','A4-L', 0, 'avenir', 0,0,0,16.7,10.18,0,0);
				$mpdf->WriteHTML(htmlspecialchars_decode($html9[$i]));
				
				$header10[$i]=__('<div style="padding:0px 0px 0px 0px;width:100%;background:#FFF;border:0;outline:none;margin:0;">
							<div style="padding:1px 38.4px 0px 37px;">
							  <div style="width:43%; float:left; color:#162c5d;text-align:left; line-height:10px;">
								  <p style="float:left;">Woche '.$i.': Sonntag</p>
							  </div>
							 
							   <div style="float:left;width:12%;text-align:center; vertical-align:middle;">
								<img style="margin-top:8px;" width="" height="28"  src="'.$site_logo.'"></div>
							  <div style="float:right;width:44%; color:#162c5d;text-align:right;line-height:10px; ">
								  <p>Seite {PAGENO}/{nbpg}</p>
							  </div>
							</div>     
						  </div>', 'shopkeeper' );
				$mpdf->SetHTMLHeader(htmlspecialchars_decode($header10[$i]));
				
				$mpdf->AddPage('UTF-8','A4-L', 0, 'avenir', 0,0,0,16.7,10.18,0,0);
				$mpdf->WriteHTML(htmlspecialchars_decode($html10[$i]));

				$header11[$i]=__('<div style="padding:0px 0px 0px 0px;width:100%;background:#FFF;border:0;outline:none;margin:0;">
								<div style="padding:1px 38.4px 0px 37px;">
									  <div style="width:20%; float:left; color:#162c5d;text-align:left; line-height:10px;">
										  <p style="float:left;">Einkaufsliste</p>
										 
										</div>
									 <div style="float:left;width:60%;text-align:center; vertical-align:middle;">
										<img style="margin-top:8px;" width="" height="28"  src="'.$site_logo.'"></div>
									<div style="float:right;width:19%;padding-right:2px; color:#162c5d;text-align:right;line-height:10px; ">
										<p>Seite {PAGENO}/{nbpg}</p>
									</div>
								</div>     
							  </div>', 'shopkeeper' );
				$mpdf->SetHTMLHeader(htmlspecialchars_decode($header11[$i]));
				$mpdf->AddPage('UTF-8','A4-L', 0, 'avenir', 0,0,0,16.7,10.18,0,0);
				$mpdf->WriteHTML(htmlspecialchars_decode($html11[$i]));
		}
		
			$header12=__('<div style="padding:0px 0px 0px 0px;width:100%;background:#FFF;border:0;outline:none;margin:0;">
							<div style="padding:1px 38.4px 0px 37px;">
								  <div style="width:20%; float:left; color:#162c5d;text-align:left; line-height:10px;">
									  <p style="float:left;">Fatburner Getrankeliste</p>
									 </div>
								  <div style="float:left;width:60%;text-align:center; vertical-align:middle;">
									<img style="margin-top:8px;" width="" height="28"  src="'.$site_logo.'"></div>
								<div style="float:right;width:19%;padding-right:2px; color:#162c5d;text-align:right;line-height:10px; ">
									<p>Seite {PAGENO}/{nbpg}</p>
								</div>
							</div>     
						  </div>', 'shopkeeper' );
			$mpdf->SetHTMLHeader(htmlspecialchars_decode($header12));
			$mpdf->AddPage('UTF-8','A4-L', 0, 'avenir', 0,0,0,16.7,10.18,0,0);
			$mpdf->WriteHTML(htmlspecialchars_decode($html12));

			$mpdf->SetHTMLHeader('');
			$mpdf->AddPage('UTF-8','A4-L', 0, 'avenir', 0,0,0,0,0,0,0);
			$mpdf->WriteHTML(htmlspecialchars_decode($html13));
			
		/*	$mpdf->SetHTMLHeader('');
			$mpdf->AddPage('UTF-8','A4-L', 0, 'avenir', 0,0,0,0,0,0,0);
			$mpdf->WriteHTML(htmlspecialchars_decode($html14));*/
			
			$path = wp_upload_dir(); 
			//$path['basedir']
			if(!file_exists($path['path'] . '/pdf')){mkdir($path['path'] . '/pdf/',0777, true);}
			/*for($i=71;$i<100;$i++){
				file_put_contents($uppath1.'status.json',json_encode(array('current'=>$i,'total'=>'100')));
				usleep(300000);
			}*/
		$pdfpath="";
		if($order_details[0]->regenerate == 1){
			//echo "if";
			$plan_name = str_replace(' ', "_", $plan_name);
			$pdfpath_db=$path['url'] . '/'.'pdf/'.$plan_name.'_Ernährungsplan_'.$billing_first_name.'_'.$billing_last_name.'_update_'.$order_id.'.pdf';			
			$pdf_name=$plan_name."_Ernährungsplan_".$billing_first_name."_".$billing_last_name."_update";
			$pdfpath=$path['path'] . '/'.'pdf/'.$plan_name.'_Ernährungsplan_'.$billing_first_name.'_'.$billing_last_name.'_update_'.$order_id.'.pdf';
			$sql="update up_user_nutrition_plans set regenerate=0 where order_id=".$order_id;
			$wpdb->query($sql);
			$q=$wpdb->query('UPDATE  up_user_nutrition_plans SET `re_pdf_name`="'.$pdf_name.'",`re_pdf_path`="'.$pdfpath_db.'" WHERE `order_id` ='.$order_id.' AND site_id='.$site_id);
		}
		else
		{// Ernährungsplan
			$plan_name = str_replace(' ', "_", $plan_name);
			$pdfpath_db=$path['url'].'/'.'pdf/'.$plan_name.'_Ernährungsplan_'.$billing_first_name.'_'.$billing_last_name.'_'.$order_id.'.pdf';			
			$pdf_name=$plan_name."_Ernährungsplan_".$billing_first_name."_".$billing_last_name;
			$pdfpath=$path['path'].'/'.'pdf/'.$plan_name.'_Ernährungsplan_'.$billing_first_name.'_'.$billing_last_name.'_'.$order_id.'.pdf';
			$q=$wpdb->query('UPDATE  up_user_nutrition_plans SET `pdf_name`="'.$pdf_name.'",`pdf_path`="'.$pdfpath_db.'" WHERE `order_id` ='.$order_id.' AND site_id='.$site_id);
		}
		//echo $pdfpath;
		//exit;
		
		//$pdfdoc = $mpdf->Output();
	//	exit;
		$mpdf->Output($pdfpath, "F");
		
		if($order_item_id != ''){
			$pdf_processing_description='Nutrition Plan(PDF) is generated';
			$sql1="Update ".$wpdb->prefix."woocommerce_order_itemmeta set meta_value = 3 WHERE order_item_id=".$order_item_id." and meta_key = 'pdf_processing_status'";
			$wpdb->query($sql1);
			$sql2="Update ".$wpdb->prefix."woocommerce_order_itemmeta set meta_value ='".$pdf_processing_description."' WHERE order_item_id=".$order_item_id." and meta_key = 'pdf_processing_description'";
				$wpdb->query($sql2);
		}
		$blog_id = get_current_blog_id();
		$date1 = date('Y-m-d H:i:s');
		$dataq = $wpdb->get_results("select meta_value from  ".$wpdb->prefix."woocommerce_order_itemmeta where order_item_id='".$order_item_id."' and meta_key='pdf_processing_status'");
		$dataq= json_decode(json_encode($dataq),true); 
		$cron_sql="insert into up_cron_status (order_id,description,pdf_processing_status,description_done_datetime,site_id) values ('".$order_id."','pdf has been successfully generated.','3','".$date1."','".$blog_id."')";
		//echo "3rd".$cron_sql."</br>";
		//$cron=$wpdb->query($cron_sql);
				
			if($dataq[0]['meta_value']==3 && (get_post_meta($order->id, '_payment_method', true) != 'bacs' || get_post_meta($order->id, '_payment_method', true) == ''))
			{
		//		echo 'here';
				//wp_mail('*****@*****.**','test-cron-pdf','mail sent successfully from pdf_function');
				$order = new WC_Order( $order_id );
				$status=$order->get_status();
				if($order->has_status('processing')){
					//echo 'in processing';
					$order->update_status( 'completed' );
				}
				/*$pdf_processing_description='Mail is sent to user successfully in pdf_function';
				$wpdb->query('update '.$wpdb->prefix.'woocommerce_order_itemmeta set meta_value=4 where meta_key="pdf_processing_status" and order_item_id="'.$order_item_id.'"');
				$sql2="Update ".$wpdb->prefix."woocommerce_order_itemmeta set meta_value ='".$pdf_processing_description."' WHERE order_item_id=".$order_item_id." and meta_key = 'pdf_processing_description'";
				$wpdb->query($sql2);*/
				$cron_sql="insert into up_cron_status (order_id,description,pdf_processing_status,description_done_datetime,site_id) values ('".$order_id."','order is completed and mail is sent','4','".$date1."','".$blog_id."')";
				//echo "4th".$cron_sql."</br>";
				//$cron=$wpdb->query($cron_sql);
		
				/*$ml = new WC_Email_Customer_Completed_Order();
				$ml->trigger($order_id);*/
			}
		
		}
	}
	catch(Exception $e) {
		echo 'Message: ' .$e->getMessage();
	}
	//exit;
//wp_die();
}