PluginProbe
Export All Posts, Products, Orders & Users | WP Ultimate Exporter | WordPress CSV Export / trunk
Export All Posts, Products, Orders & Users | WP Ultimate Exporter | WordPress CSV Export vtrunk
3.0 2.24.2 2.24.1 1.7.2 1.7.3 1.7.4 1.7.5 1.7.6 1.7.7 1.7.8 1.7.9 2.0 2.0.1 2.1 2.1.1 2.1.2 2.10 2.11 2.12 2.13 2.14 2.15 2.16 2.16.1 2.16.2 All 96 releases
wp-ultimate-exporter / exportExtensions / WooComExport.php

WooComExport.php in Export All Posts, Products, Orders & Users | WP Ultimate Exporter | WordPress CSV Export trunk, at exportExtensions/WooComExport.php

2,120 lines 112.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * WP Ultimate Exporter plugin file.
4 *
5 * Copyright (C) 2010-2020, Smackcoders Inc - info@smackcoders.com
6 */
7
8 namespace Smackcoders\SMEXP;
9 use Smackcoders\SMEXP\WC_Coupon;
10 if ( ! defined( 'ABSPATH' ) )
11 exit; // Exit if accessed directly
12
13 /**
14 * Class WooCommerceExport
15 * @package Smackcoders\WCSV
16 */
17 // require_once dirname(__FILE__) . '/ExportExtension.php';
18
19
20 require_once dirname(__FILE__) . '/ElementorExport.php';
21
22 // use Smackcoders\SMEXP\ExportExtension;
23
24 class WooCommerceExport extends ExportExtension{
25 protected static $instance = null,$mapping_instance,$export_handler,$export_instance,$post_export;
26 public $offset = 0;
27 public $limit = 1000;
28 public $totalRowCount;
29 public static function getInstance() {
30 if ( null == self::$instance ) {
31 self::$instance = new self;
32 WooCommerceExport::$export_instance = ExportExtension::getInstance();
33 WooCommerceExport::$post_export = PostExport::getInstance();
34 }
35 return self::$instance;
36 }
37
38 /**
39 * WooCommerceExport constructor.
40 */
41 public function __construct() {
42 $this->plugin = Plugin::getInstance();
43 }
44
45 /**
46 * Export woocommerce orders
47 * @param $id
48 * @param $type
49 * @param $optional
50 * @return bool
51 */
52 public function getCouponsData($id, $type, $optionalType){
53 $coupon_id = $id;
54 $c = new \WC_Coupon($coupon_id);
55 $DiscountType = $c->get_discount_type();
56 $CouponAmount = $c->get_amount();
57 $IndividualUse = $c->get_individual_use();
58 $ProductIDs = $c->get_product_ids();
59 $ExcludeProductIDs = $c->get_excluded_product_ids();
60 $UsageLimit = $c->get_usage_limit();
61 $UsageLimitPerUser = $c->get_usage_limit_per_user();
62 $LimitUsageToXItems = $c->get_limit_usage_to_x_items();
63 $ExpiryDate = $c->get_date_expires();
64 $FreeShipping = $c->get_free_shipping();
65 $ExcludeSaleItems = $c->get_exclude_sale_items();
66 $MinimumAmount = $c->get_minimum_amount();
67 $MaximumAmount = $c->get_maximum_amount();
68 $CustomerEmail = $c->get_email_restrictions();
69 $ExcludedProductCategories = $c->get_excluded_product_categories();
70 $ProductCategories = $c->get_product_categories();
71
72 $product_Ids = array();
73 $Exclude_Product_IDs =array();
74 $product_cat = array();
75 $exclude_cat = array();
76 $cus_email = array();
77 foreach ($ProductCategories as $p_IDs) {
78 $product_cat[] = $p_IDs;
79 }
80 foreach ($ExcludedProductCategories as $p_IDs) {
81 $exclude_cat[] = $p_IDs;
82 }
83
84 foreach ($CustomerEmail as $p_IDs) {
85 $cus_email[] = $p_IDs;
86 }
87
88 foreach ($ProductIDs as $p_IDs) {
89 $product_Ids[] = $p_IDs;
90 }
91 foreach($ExcludeProductIDs as $Exclude_PIds){
92 $Exclude_Product_IDs[] = $Exclude_PIds;
93 }
94
95 WooCommerceExport::$export_instance->data[$id]['exclude_product_categories'] = !empty($exclude_cat) ? implode(',', $exclude_cat) : '';
96 WooCommerceExport::$export_instance->data[$id]['customer_email'] = !empty($cus_email) ? implode(',', $cus_email) : '';
97 WooCommerceExport::$export_instance->data[$id]['product_categories'] = !empty($product_cat) ? implode(',', $product_cat) : '';
98
99
100
101 WooCommerceExport::$export_instance->data[$id]['discount_type'] = $DiscountType;
102 WooCommerceExport::$export_instance->data[$id]['coupon_amount'] = $CouponAmount;
103 WooCommerceExport::$export_instance->data[$id]['individual_use'] = $IndividualUse ? 'yes' : 'no';
104 WooCommerceExport::$export_instance->data[$id]['usage_limit'] = $UsageLimit;
105 WooCommerceExport::$export_instance->data[$id]['usage_limit_per_user'] = $UsageLimitPerUser;
106 WooCommerceExport::$export_instance->data[$id]['limit_usage_to_x_items'] = $LimitUsageToXItems;
107 WooCommerceExport::$export_instance->data[$id]['expiry_date'] = $ExpiryDate ? $ExpiryDate->date('Y-m-d H:i:s') : null;
108 WooCommerceExport::$export_instance->data[$id]['free_shipping'] = $FreeShipping ? 'yes' : 'no';
109 WooCommerceExport::$export_instance->data[$id]['exclude_sale_items'] = $ExcludeSaleItems ? 'yes' : 'no';
110 WooCommerceExport::$export_instance->data[$id]['minimum_amount'] = $MinimumAmount;
111 WooCommerceExport::$export_instance->data[$id]['maximum_amount'] = $MaximumAmount;
112 // Handle the product IDs and excluded product IDs with implode only if they are not empty
113 WooCommerceExport::$export_instance->data[$id]['product_ids'] = !empty($product_Ids) ? implode(',', $product_Ids) : '';
114 WooCommerceExport::$export_instance->data[$id]['exclude_product_ids'] = !empty($Exclude_Product_IDs) ? implode(',', $Exclude_Product_IDs) : '';
115
116 }
117 public function getWooComOrderData($id, $type, $optional)
118 {
119 $order = wc_get_order($id);
120 $order_data = $order->get_data();
121 $orderid = self::$export_instance->data[$id]['ID'];
122 WooCommerceExport::$export_instance->data[$id]['ORDERID'] = $orderid;
123 //fetch the order data
124 $date_created_object = $order_data['date_created'];
125 $formatted_date_time = $date_created_object->date('m/d/Y H:i:s');
126 WooCommerceExport::$export_instance->data[$id]['order_date'] = $formatted_date_time;
127 $customer_note = $order_data['customer_note'];
128 WooCommerceExport::$export_instance->data[$id]['customer_note'] = $customer_note;
129 $billing_details = $order_data['billing'];
130 $order_status = $order_data['status'];
131 WooCommerceExport::$export_instance->data[$id]['order_status'] = 'wc-'.$order_status;
132 $_billing_first_name = $billing_details['first_name'];
133 WooCommerceExport::$export_instance->data[$id]['_billing_first_name'] = $_billing_first_name;
134 $_billing_last_name = $billing_details['last_name'];
135 WooCommerceExport::$export_instance->data[$id]['_billing_last_name'] = $_billing_last_name;
136 $_billing_company = $billing_details['company'];
137 WooCommerceExport::$export_instance->data[$id]['_billing_company'] = $_billing_company;
138 $_billing_address_1 = $billing_details['address_1'];
139 WooCommerceExport::$export_instance->data[$id]['_billing_address_1'] = $_billing_address_1;
140 $_billing_address_2 = $billing_details['address_2'];
141 WooCommerceExport::$export_instance->data[$id]['_billing_address_2'] = $_billing_address_2;
142 $_billing_city = $billing_details['city'];
143 WooCommerceExport::$export_instance->data[$id]['_billing_city'] = $_billing_city;
144 $_billing_state = $billing_details['state'];
145 WooCommerceExport::$export_instance->data[$id]['_billing_state'] = $_billing_state;
146 $_billing_postcode = $billing_details['postcode'];
147 WooCommerceExport::$export_instance->data[$id]['_billing_postcode'] = $_billing_postcode;
148 $_billing_country = $billing_details['country'];
149 WooCommerceExport::$export_instance->data[$id]['_billing_country'] = $_billing_country;
150 $_order_currency = $order_data['currency'];
151 WooCommerceExport::$export_instance->data[$id]['_order_currency'] = $_order_currency;
152 $_order_shipping_tax = $order_data['shipping_tax'];
153 WooCommerceExport::$export_instance->data[$id]['_order_shipping_tax'] = $_order_shipping_tax;
154 $_order_shipping = $order->get_shipping_total();
155 WooCommerceExport::$export_instance->data[$id]['_order_shipping'] = $_order_shipping;
156 $_order_tax = $order_data['cart_tax'];
157 WooCommerceExport::$export_instance->data[$id]['_order_tax'] = $_order_tax;
158 $_customer_user = $order_data['customer_id'];
159 if($_customer_user != 0){
160 $user_data = get_userdata($_customer_user);
161 $user_email = $user_data->user_email;
162 WooCommerceExport::$export_instance->data[$id]['_customer_user'] = $user_email ;
163 }
164 $_billing_email = $billing_details['email'];
165 WooCommerceExport::$export_instance->data[$id]['_billing_email'] = $_billing_email;
166
167 $_billing_phone = $billing_details['phone'];
168 WooCommerceExport::$export_instance->data[$id]['_billing_phone'] = $_billing_phone;
169
170 $_shipping_first_name = $order_data['shipping']['first_name'];
171 WooCommerceExport::$export_instance->data[$id]['_shipping_first_name'] = $_shipping_first_name;
172
173 $_shipping_last_name = $order_data['shipping']['last_name'];
174 WooCommerceExport::$export_instance->data[$id]['_shipping_last_name'] = $_shipping_last_name;
175
176 $_shipping_company = $order_data['shipping']['company'];
177 WooCommerceExport::$export_instance->data[$id]['_shipping_company'] = $_shipping_company;
178
179 $_shipping_address_1 = $order_data['shipping']['address_1'];
180 WooCommerceExport::$export_instance->data[$id]['_shipping_address_1'] = $_shipping_address_1;
181
182 $_shipping_address_2 = $order_data['shipping']['address_2'];
183 WooCommerceExport::$export_instance->data[$id]['_shipping_address_2'] = $_shipping_address_2;
184
185 $_shipping_city = $order_data['shipping']['city'];
186 WooCommerceExport::$export_instance->data[$id]['_shipping_city'] = $_shipping_city;
187
188 $_shipping_state = $order_data['shipping']['state'];
189 WooCommerceExport::$export_instance->data[$id]['_shipping_state'] = $_shipping_state;
190
191 $_shipping_postcode = $order_data['shipping']['postcode'];
192 WooCommerceExport::$export_instance->data[$id]['_shipping_postcode'] = $_shipping_postcode;
193
194 $_shipping_country = $order_data['shipping']['country'];
195 WooCommerceExport::$export_instance->data[$id]['_shipping_country'] = $_shipping_country;
196
197 $_shipping_phone = $order_data['shipping']['phone'];
198 WooCommerceExport::$export_instance->data[$id]['_shipping_phone'] = $_shipping_phone;
199
200 $_order_total = $order_data['total'];
201 WooCommerceExport::$export_instance->data[$id]['_order_total'] = $_order_total;
202
203 $_cart_discount = $order_data['discount_total'];
204 WooCommerceExport::$export_instance->data[$id]['_cart_discount'] = $_cart_discount;
205
206 $_cart_discount_tax = $order_data['discount_tax'];
207 WooCommerceExport::$export_instance->data[$id]['_cart_discount_tax'] = $_cart_discount_tax;
208
209 $_payment_method = $order_data['payment_method'];
210 WooCommerceExport::$export_instance->data[$id]['_payment_method'] = $_payment_method;
211
212 $_recorded_sales= $order_data['recorded_sales'];
213 if($_recorded_sales > 0){
214 $_recorded_sales = 'yes';
215 }else{
216 $_recorded_sales = 'no';
217 }
218 WooCommerceExport::$export_instance->data[$id]['recorded_sales'] = $_recorded_sales;
219
220 $_payment_method_title = $order_data['payment_method_title'];
221 WooCommerceExport::$export_instance->data[$id]['_payment_method_title'] = $_payment_method_title;
222
223 $_transaction_id = $order_data['transaction_id'];
224 WooCommerceExport::$export_instance->data[$id]['_transaction_id'] = $_transaction_id;
225 $line_items = $order->get_items();
226 $mycoupon = $order->get_coupons();
227
228 if (!empty($mycoupon)) {
229 foreach ($mycoupon as $coupon) {
230 $coupon_code = $coupon->get_code();
231 }
232 }
233 if(!empty($line_items)){
234 foreach ($line_items as $item_id => $item) {
235 $item_names[] = $item->get_name();
236 $product_type[] = $item->get_type();
237 $variation_id[] = $item->get_variation_id();
238 $product_id[] = $item->get_product_id();
239 $subtotal[] = $item->get_subtotal();
240 $subtotal_tax[] = $item->get_subtotal_tax();
241 $total[] = $item->get_total();
242 $total_tax[] = $item->get_total_tax();
243 $item_tax_data[] = $item->get_taxes();
244 if (!empty($item_tax_data) && is_array($item_tax_data)) {
245 if(!empty($item_tax_data[0]['total']) || !empty($item_tax_data[0]['subtotal'])){
246 $line_tax[] = implode(',', $item_tax_data[0]['total']);
247 $line_tax[] = implode(',', $item_tax_data[0]['subtotal']);
248 }else{
249 $line_tax = array();
250 }
251 }
252 $tax_class[] = $item->get_tax_class();
253 $quantity[] = $item->get_quantity();
254 }
255 if (!empty($coupon_code)) {
256 $item_names[] = $coupon_code;
257 $product_type[] = 'coupon';
258 }
259 //itemdata
260 self::$export_instance->data[$id]['item_name'] = implode(',', $item_names);
261 self::$export_instance->data[$id]['item_type'] = implode(',', $product_type);
262 self::$export_instance->data[$id]['item_variation_id'] = implode(',', $variation_id);
263 self::$export_instance->data[$id]['item_product_id'] = implode(',', $product_id);
264 self::$export_instance->data[$id]['item_line_subtotal'] = implode(',', $subtotal);
265 self::$export_instance->data[$id]['item_line_subtotal_tax'] = implode(',', $subtotal_tax);
266 self::$export_instance->data[$id]['item_line_total'] = implode(',', $total);
267 self::$export_instance->data[$id]['item_line_tax'] = implode(',', $total_tax);
268 self::$export_instance->data[$id]['item_line_tax_data'] = implode(',', $line_tax);
269 self::$export_instance->data[$id]['item_tax_class'] = implode(',', $tax_class);
270 self::$export_instance->data[$id]['item_qty'] = implode(',', $quantity);
271 }
272 //fee data
273 $fees = $order->get_fees();
274 if(!empty($fees)){
275 foreach ($fees as $fee) {
276 $fee_name[] = $fee->get_name();
277 $fee_type[] = $fee->get_type(); // Assuming there's a get_type() method; check the documentation
278 $fee_tax_class[] = $fee->get_tax_class();
279 $fee_line_total[] = $fee->get_total();
280 $fee_line_tax[] = $fee->get_total_tax();
281 // $fee_line_subtotal[] = $fee->get_subtotal();
282 // $fee_line_subtotal_tax[] = $fee->get_subtotal_tax();
283 $tax_data = $fee->get_taxes();
284 if(!empty($tax_data['total'])){
285 $fee_line_tax_data[] = $tax_data['total'];
286 }else{
287 $fee_line_tax_data = array();
288 }
289 }
290 //fee data
291 self::$export_instance->data[$id]['fee_name'] = implode(',', $fee_name);
292 self::$export_instance->data[$id]['fee_type'] = implode(',', $fee_type);
293 //self::$export_instance->data[$id]['fee_line_subtotal'] = implode(',', $fee_line_subtotal);
294 //self::$export_instance->data[$id]['fee_line_subtotal_tax'] = implode(',', $fee_line_subtotal_tax);
295 self::$export_instance->data[$id]['fee_line_total'] = implode(',', $fee_line_total);
296 self::$export_instance->data[$id]['fee_line_tax'] = implode(',', $fee_line_tax);
297 self::$export_instance->data[$id]['fee_line_tax_data'] = implode(',',$fee_line_tax_data );
298 self::$export_instance->data[$id]['fee_tax_class'] = implode(',', $fee_tax_class);
299 }
300 //shipment data fetch
301 $shipping_methods = $order->get_shipping_methods();
302 if(!empty($shipping_methods)){
303 foreach ($shipping_methods as $shipping_method) {
304 $shipment_name[] = $shipping_method->get_method_title();
305 $shipment_method_id[] = $shipping_method->get_method_id();
306 $shipment_cost[] = $shipping_method->get_total();
307 $shipment_taxe_data = $shipping_method->get_taxes();
308 if(!empty($shipment_taxe_data['total'])){
309 $shipment_taxes[] = $shipment_taxe_data['total'];
310 }else{
311 $shipment_taxes = array();
312 }
313 }
314 // shipment data
315 self::$export_instance->data[$id]['shipment_name'] = implode(',', $shipment_name);
316 self::$export_instance->data[$id]['shipment_method_id'] = implode(',', $shipment_method_id);
317 self::$export_instance->data[$id]['shipment_cost'] = implode(',', $shipment_cost);
318 self::$export_instance->data[$id]['shipment_taxes'] = implode(',', $shipment_taxes);
319 }
320
321 if(is_plugin_active('advanced-product-fields-for-woocommerce/advanced-product-fields-for-woocommerce.php') ) {
322 $this->getPPOMData($id,$product_id);
323 }
324 if (is_plugin_active('woo-extra-product-options/woo-extra-product-options.php')) {
325 $this->getEPOData($id,$product_id);
326 }
327 if (is_plugin_active('woo-custom-product-addons/start.php')) {
328 $this->getWCPAData($id,$product_id);
329 }
330 if ( is_plugin_active( 'yith-woocommerce-order-tracking-premium/init.php' ) ) {
331 self::$export_instance->data[$id]['ywot_tracking_code'] = $order->get_meta('ywot_tracking_code', true);
332 self::$export_instance->data[$id]['ywot_tracking_postcode'] = $order->get_meta('ywot_tracking_postcode', true);
333 self::$export_instance->data[$id]['ywot_carrier_id'] = $order->get_meta('ywot_carrier_id', true);
334 self::$export_instance->data[$id]['ywot_pick_up_date'] = $order->get_meta('ywot_pick_up_date', true);
335 self::$export_instance->data[$id]['ywot_estimated_delivery_date'] = $order->get_meta('ywot_estimated_delivery_date', true);
336 self::$export_instance->data[$id]['ywot_picked_up'] = $order->get_meta('ywot_picked_up', true);
337 }
338
339
340 }
341
342 /**
343 * Code for PPOM export
344 * @param $id
345 * @param $product_id
346 */
347 public function getPPOMData($order_id, $product_ids)
348 {
349
350 global $wpdb;
351 $table_name = $wpdb->prefix . 'nm_personalized';
352
353 // Fetch all the PPOM field setups from the `wp_nm_personalized` table
354 $field_setups = $wpdb->get_results( "SELECT * FROM $table_name" );
355
356 if ( !empty( $field_setups ) ) {
357
358 foreach ( $field_setups as $setup ) {
359 $meta_data = json_decode( $setup->the_meta, true ); // Unserialize the field meta data
360
361
362 // Display the unserialized field data if available
363 if ( is_array( $meta_data ) ) {
364
365 foreach ( $meta_data as $key => $field ) {
366 $pro_meta_fields[$field['title']] = $field['data_name'];
367 }
368
369
370 }
371 }
372
373 }
374
375
376
377 // Get order items for the specified order ID
378 $order_items = wc_get_order( $order_id )->get_items();
379
380 foreach ( $order_items as $item_id => $item ) {
381 // Get the meta data for each order item
382 $item_meta = wc_get_order_item_meta( $item_id, '', false );
383
384 foreach ( $item_meta as $meta_key => $meta_value ) {
385
386 if ( array_key_exists($meta_key, $pro_meta_fields)) { // Change this condition based on your actual meta key format
387
388 self::$export_instance->data[$order_id][$meta_key] = $meta_value[0]; // Store each field key-value pair
389
390 }
391 }
392 }
393
394
395 }
396 public function getEPOData($order_id, $product_ids)
397 {
398 global $wpdb;
399
400 // Fetch all EPO field setups from the `wp_woocommerce_order_itemmeta` table
401 $table_name = $wpdb->prefix . 'woocommerce_order_itemmeta';
402
403 $epo_data = $wpdb->get_results( $wpdb->prepare(
404 "SELECT * FROM $table_name WHERE order_item_id IN (SELECT order_item_id FROM {$wpdb->prefix}woocommerce_order_items WHERE order_id = %d)",
405 $order_id
406 ) );
407
408 $pro_meta_fields = [];
409
410 if ( !empty( $epo_data ) ) {
411 foreach ( $epo_data as $data ) {
412 if ( is_serialized( $data->meta_value ) ) {
413 $meta_data = unserialize( $data->meta_value );
414 } else {
415 $meta_data = $data->meta_value;
416 }
417
418 if ( is_array( $meta_data ) ) {
419 foreach ( $meta_data as $key => $field ) {
420 if (isset($field['title']) && isset($field['data_name'])) {
421 $pro_meta_fields[$field['title']] = $field['data_name'];
422 } else {
423 }
424 }
425 } else {
426 $pro_meta_fields[$data->meta_key] = $meta_data;
427 }
428 }
429 }
430
431
432 $order_items = wc_get_order($order_id)->get_items();
433
434 foreach ($order_items as $item_id => $item) {
435 $item_meta = wc_get_order_item_meta($item_id, '', false);
436
437 foreach ($item_meta as $meta_key => $meta_value) {
438 if (array_key_exists($meta_key, $pro_meta_fields)) {
439 if (is_array($meta_value) && isset($meta_value[0])) {
440 self::$export_instance->data[$order_id][$meta_key] = $meta_value[0];
441 } else {
442 }
443 }
444 }
445 }
446 }
447
448 public function getWCPAData($order_id, $product_ids)
449 {
450 global $wpdb;
451
452 // Fetch all WCPA field setups from the `wp_woocommerce_order_itemmeta` table
453 $table_name = $wpdb->prefix . 'woocommerce_order_itemmeta';
454
455 // Fetching metadata for the given order items
456 $wcpa_data = $wpdb->get_results($wpdb->prepare(
457 "SELECT * FROM $table_name WHERE order_item_id IN (SELECT order_item_id FROM {$wpdb->prefix}woocommerce_order_items WHERE order_id = %d)",
458 $order_id
459 ));
460
461 $pro_meta_fields = [];
462
463 if (!empty($wcpa_data)) {
464 foreach ($wcpa_data as $data) {
465 // Check if the meta_value is serialized, then unserialize it
466 if (is_serialized($data->meta_value)) {
467 $meta_data = unserialize($data->meta_value);
468 } else {
469 $meta_data = $data->meta_value;
470 }
471
472 // Check if the meta_data is an array
473 if (is_array($meta_data)) {
474 foreach ($meta_data as $key => $field) {
475 if (isset($field['title']) && isset($field['data_name'])) {
476 // Adjusting keys to match export requirements
477 $pro_meta_fields[$field['label']] = $field['value']; // Use label and value instead of title and data_name
478 }
479 }
480 } else {
481 // If it's not an array, directly assign the meta_key to the fields
482 $pro_meta_fields[$data->meta_key] = $meta_data;
483 }
484 }
485 }
486
487 // Fetching all order items for the given order_id
488 $order_items = wc_get_order($order_id)->get_items();
489
490 foreach ($order_items as $item_id => $item) {
491 // Get item metadata for each order item
492 $item_meta = wc_get_order_item_meta($item_id, '', false);
493
494 // Loop through the item meta and check if the meta_key exists in the pro_meta_fields
495 foreach ($item_meta as $meta_key => $meta_value) {
496 if (array_key_exists($meta_key, $pro_meta_fields)) {
497 // Adjusting keys to match export requirements
498 if (is_array($meta_value) && isset($meta_value[0])) {
499 self::$export_instance->data[$order_id][str_replace(' ', '-', strtolower($meta_key))] = $meta_value[0]; // Convert key format
500 }
501 }
502 }
503 }
504 }
505
506 /**
507 * Code for Woocommerce Refund export
508 * @param $id
509 * @param $type
510 * @param $optionalType
511 */
512 public function getWooComCustomerUser($id, $type, $optionalType)
513 {
514 global $wpdb;
515 $parent = WooCommerceExport::$export_instance->data[$id]['post_parent'];
516 $query = $wpdb->prepare("SELECT post_id,meta_key,meta_value FROM {$wpdb->prefix}postmeta where post_id = %d", $parent);
517 $result = $wpdb->get_results($query);
518 if(!empty($result)){
519 foreach ($result as $key => $value) {
520 if($value->meta_key == '_customer_user'){
521 $cus_user = $value->meta_value;
522 }
523 }
524 }
525 WooCommerceExport::$export_instance->data[$id]['customer_user'] = $cus_user;
526 }
527
528 /**
529 * Export woocommerce product and variation
530 * @param $id
531 * @param $type
532 * @param $optionalType
533 */
534 public function getVariationData($id, $type, $optionalType)
535 {
536 $variations_data = wc_get_product($id);
537 $variation_datas = $variations_data->get_data();
538 $variations[] = wc_get_product($id);
539 foreach ($variations as $attr_key => $variation) {
540 $parent_id = $variation->get_parent_id();
541 $parent_product = wc_get_product($parent_id);
542 $parent_sku = $parent_product->get_sku();
543 $variation_sku = $variation->get_sku();
544 $variation_id = $variation->get_id();
545 $featured_image_id = $variation->get_image_id();
546 $featured_image_url = wp_get_attachment_image_url($featured_image_id, 'full');
547 $product_attributes = $parent_product->get_attributes();
548 $attribute_name = $att_values = $is_visible = $is_variation = $position = $is_taxonomy = [];
549
550 foreach ($product_attributes as $attribute_key => $attribute) {
551 $attribute_name[] = str_replace('pa_', '', $attribute['name']);
552 $taxonomy_name = $attribute['taxonomy'];
553 $attribute_options = $attribute['options'];
554 $term_names = [];
555 foreach ($attribute_options as $term_key => $term_id) {
556 $term = get_term_by('id', $term_id, $taxonomy_name);
557 if (!empty($term->name)) {
558 $term_names[] = $term->name;
559 }
560 }
561 if (!empty($term_names)) {
562 $att_values[] = implode('|', $term_names); // Combine term names with |
563 }
564 $is_visible[] = $attribute['is_visible'];
565 $is_variation[] = $attribute['is_variation'];
566 $position[] = $attribute['position'];
567 }
568 $attachment_meta = wp_get_attachment_metadata($featured_image_id);
569 $product_caption = isset($attachment_meta['image_meta']['caption']) ? $attachment_meta['image_meta']['caption'] : '';
570 $product_alt_text = get_post_meta($featured_image_id, '_wp_attachment_image_alt', true);
571 $product_description = get_post_field('post_content', $featured_image_id);
572
573 $product_title = $parent_product->get_title();
574 $is_featured = get_post_meta($parent_product->get_id(), 'featured', true) ? '1' : '0';
575 $downloadable = $variation->is_downloadable() ? 'yes' : 'no';
576 if ($variation->is_downloadable()) {
577 $download_limit = $variation->get_download_limit();
578 $download_expiry = $variation->get_download_expiry();
579 $downloadable_files = [];
580 $download_type = [];
581 $downloads = $variation->get_downloads();
582 foreach ($downloads as $download) {
583 $file_string = $download['name'].','.$download['file'];
584 $downloadable_files[] = $file_string;
585 }
586 $download_file_str = implode('|', $downloadable_files);
587 WooCommerceExport::$export_instance->data[$id]['downloadable_files'] = $download_file_str ?? '';
588 WooCommerceExport::$export_instance->data[$id]['download_limit'] = $download_limit ?? '';
589 WooCommerceExport::$export_instance->data[$id]['download_expiry'] = $download_expiry ?? '';
590 }
591 $price = $variation->get_price();
592 $sale_price_dates_from = $variation->get_date_on_sale_from();
593 $sale_price_dates_to = $variation->get_date_on_sale_to();
594 $regular_price = $variation->get_regular_price();
595 $sale_price = $variation->get_sale_price();
596 $purchase_note = $variation->get_purchase_note();
597 $default_attributes = $variation->get_default_attributes();
598 $attribute_default = [];
599 foreach ($default_attributes as $def_attribute_key => $def_attribute_value) {
600 $attribute_default[] = str_replace('pa_', '', $def_attribute_key) . '|' . $def_attribute_value;
601 }
602 $custom_attributes = $variation->get_attributes();
603 $attribute_names = [];
604 foreach ($custom_attributes as $cus_attribute_key => $cus_attribute_value) {
605 if(strpos($cus_attribute_value,'-')!== false){
606 $cus_attribute_value = str_replace('-',' ',$cus_attribute_value);
607 }
608 $attribute_names[] = str_replace('pa_', '', $cus_attribute_key) . '|' . $cus_attribute_value;
609 }
610 $tax_status = $variation->get_tax_status();
611 $tax_status_mapping = array('taxable' => 1 , 'shipping' => 2, 'none' => 3);
612 $is_virtual = $variation->is_virtual() ? 'yes' : 'no';
613 if(!$variation->is_virtual()){
614 $weight = $variation->get_weight();
615 $length = $variation->get_length();
616 $width = $variation->get_width();
617 $height = $variation->get_height();
618 }
619 $manages_stock = $variation->managing_stock() ? 'yes' : 'no';
620 $stock_status = $variation->get_stock_status();
621 $sold_individually = $variation->get_sold_individually();
622 if($variation->managing_stock()){
623 $stock_qty = $variation->get_stock_quantity();
624 $low_stock_amount = $variation->get_low_stock_amount();
625 $backorders = $variation->get_backorders();
626 switch ($backorders) {
627 case 'no':
628 $backorders_no= '1';
629 break;
630
631 case 'notify':
632 $backorders_no= '2';
633 break;
634
635 case 'yes':
636 $backorders_no = '3';
637 break;
638
639 default:
640 $backorders_no = '';
641 break;
642 }
643 }
644 $var_description = $variation->get_description();
645 $var_class_id = $variation->get_shipping_class_id();
646 $shipping_class_term = get_term($var_class_id, 'product_shipping_class');
647 }
648 WooCommerceExport::$export_instance->data[$id]['PARENTSKU'] = $parent_sku ;
649 WooCommerceExport::$export_instance->data[$id]['VARIATIONSKU'] = $variation_sku;
650 WooCommerceExport::$export_instance->data[$id]['VARIATIONID'] = $variation_id;
651 WooCommerceExport::$export_instance->data[$id]['product_attribute_name'] = implode('|',$attribute_name);
652 WooCommerceExport::$export_instance->data[$id]['product_attribute_value'] = implode(',', $att_values);
653 WooCommerceExport::$export_instance->data[$id]['product_attribute_visible'] = implode('|', $is_visible);
654 WooCommerceExport::$export_instance->data[$id]['product_attribute_variation'] = implode('|', $is_variation);
655 WooCommerceExport::$export_instance->data[$id]['product_attribute_position'] = implode('|', $position);
656
657 WooCommerceExport::$export_instance->data[$id]['product_caption'] = $product_caption ?? '';
658 WooCommerceExport::$export_instance->data[$id]['product_alt_text'] = $product_alt_text ?? '';
659 WooCommerceExport::$export_instance->data[$id]['product_description'] = $product_description ?? '';
660
661 WooCommerceExport::$export_instance->data[$id]['product_title'] = $product_title ?? '';
662 WooCommerceExport::$export_instance->data[$id]['featured'] = $is_featured ?? '';
663
664 WooCommerceExport::$export_instance->data[$id]['price'] = $price ?? '';
665 WooCommerceExport::$export_instance->data[$id]['sale_price_dates_from'] = $sale_price_dates_from ?? '';
666 WooCommerceExport::$export_instance->data[$id]['sale_price_dates_to'] = $sale_price_dates_to ?? '';
667 WooCommerceExport::$export_instance->data[$id]['regular_price'] = $regular_price ?? '';
668 WooCommerceExport::$export_instance->data[$id]['sale_price'] = $sale_price ?? '';
669 WooCommerceExport::$export_instance->data[$id]['purchase_note'] = $purchase_note ?? '';
670
671 WooCommerceExport::$export_instance->data[$id]['default_attributes'] = implode(',',$attribute_default) ?? '';
672 WooCommerceExport::$export_instance->data[$id]['custom_attributes'] = implode(',',$attribute_names) ?? '';
673 WooCommerceExport::$export_instance->data[$id]['_downloadable'] = $downloadable ?? '';
674
675 WooCommerceExport::$export_instance->data[$id]['tax_class'] = $variation_datas['tax_class'] ?? '';
676 WooCommerceExport::$export_instance->data[$id]['tax_status'] = array_key_exists($tax_status,$tax_status_mapping) ? $tax_status_mapping[$tax_status] : '' ;
677
678 WooCommerceExport::$export_instance->data[$id]['weight'] = $weight ?? '';
679 WooCommerceExport::$export_instance->data[$id]['length'] = $length ?? '';
680 WooCommerceExport::$export_instance->data[$id]['width'] = $width ?? '';
681 WooCommerceExport::$export_instance->data[$id]['height'] = $height ?? '';
682
683 WooCommerceExport::$export_instance->data[$id]['virtual'] = $is_virtual ?? '';
684
685 WooCommerceExport::$export_instance->data[$id]['manage_stock'] = $manages_stock ?? '';
686 WooCommerceExport::$export_instance->data[$id]['_stock'] = $stock_qty ?? '';
687 WooCommerceExport::$export_instance->data[$id]['_stock_status'] = $stock_status ?? '';
688 WooCommerceExport::$export_instance->data[$id]['_low_stock_threshold'] = $low_stock_amount ?? '';
689 WooCommerceExport::$export_instance->data[$id]['_stock_qty'] = $stock_qty ?? '';
690 WooCommerceExport::$export_instance->data[$id]['backorders'] = $backorders_no;
691 WooCommerceExport::$export_instance->data[$id]['sold_individually'] = ($sold_individually > 0) ? 'yes' : 'no';
692 WooCommerceExport::$export_instance->data[$id]['_thumbnail_id'] = $featured_image_url ?? '';
693
694 WooCommerceExport::$export_instance->data[$id]['variation_description'] = $var_description ?? '';
695 WooCommerceExport::$export_instance->data[$id]['variation_shipping_class'] = $shipping_class_term ? $shipping_class_term->name : '';
696 }
697 // public function getProductData($id, $type, $optionalType)
698 // {
699 // $product = wc_get_product($id);
700 // $product_datas = $product->get_data();
701 // $product_sku = $product->get_sku();
702 // WooCommerceExport::$export_instance->data[$id]['PRODUCTSKU'] = $product_sku;
703 // $product_attributes = $product->get_attributes();
704 // if (!empty($product_attributes)) {
705 // foreach ($product_attributes as $attribute_key => $attribute) {
706 // $attribute_name[] = str_replace('pa_', '', $attribute['name']);
707 // $taxonomy_name = $attribute['taxonomy'];
708 // $attribute_options = $attribute['options'];
709 // $term_names = $att_values = [];
710 // foreach ($attribute_options as $term_key => $term_id) {
711 // $term = get_term_by('id', $term_id, $taxonomy_name);
712 // if (!empty($term->name)) {
713 // $term_names[] = $term->name;
714 // }
715 // }
716 // if (!empty($term_names)) {
717 // $att_values[] = implode('|', $term_names);
718 // }
719 // $is_visible[] = $attribute['is_visible'];
720 // $is_variation[] = $attribute['is_variation'];
721 // $position[] = $attribute['position'];
722 // $is_taxonomy[] = $attribute['is_taxonomy'];
723 // }
724 // WooCommerceExport::$export_instance->data[$id]['product_attribute_name'] = implode('|', $attribute_name);
725 // WooCommerceExport::$export_instance->data[$id]['product_attribute_value'] = implode(',', $att_values);
726 // WooCommerceExport::$export_instance->data[$id]['product_attribute_visible'] = implode('|', $is_visible);
727 // WooCommerceExport::$export_instance->data[$id]['product_attribute_variation'] = implode('|', $is_variation);
728 // WooCommerceExport::$export_instance->data[$id]['product_attribute_position'] = implode('|', $position);
729 // WooCommerceExport::$export_instance->data[$id]['product_attribute_taxonomy'] = implode('|', $is_taxonomy);
730 // }
731
732
733 // $get_catalog_visibility = $product->get_catalog_visibility();
734 // $visibility_mapping = array('visible' => '1','catalog' => '2','search' => '3','hidden' => '4');
735 // WooCommerceExport::$export_instance->data[$id]['visibility'] = array_key_exists($get_catalog_visibility,$visibility_mapping) ? $visibility_mapping[$get_catalog_visibility] : '';
736
737 // $tax_status = $product->get_tax_status();
738 // $tax_status_mapping = array('taxable' => 1 , 'shipping' => 2, 'none' => 3);
739 // WooCommerceExport::$export_instance->data[$id]['tax_status'] = array_key_exists($tax_status,$tax_status_mapping) ? $tax_status_mapping[$tax_status] : '' ;
740
741 // $product_type = $product->get_type();
742 // $product_type_mapping = array('simple' => 1 , 'grouped' => 2, 'external' => 3, 'variable' => 4 , 'subscription' => 5 , 'variable-subscription' => 6 ,'bundle' => 7);
743 // WooCommerceExport::$export_instance->data[$id]['product_type'] = array_key_exists($product_type,$product_type_mapping) ? $product_type_mapping[$product_type] : '' ;
744
745 // if (has_term('featured', 'product_visibility', $id)) {
746 // WooCommerceExport::$export_instance->data[$id]['featured_product'] = '1';
747 // }
748 // WooCommerceExport::$export_instance->data[$id]['tax_class'] = $product_datas['tax_class'] ?? '';
749 // if (method_exists($product, 'get_file_paths')) {
750 // $file_paths = $product->get_file_paths();
751 // WooCommerceExport::$export_instance->data[$id]['_file_paths'] = isset($file_paths) ? $file_paths : '';
752 // } else {
753 // WooCommerceExport::$export_instance->data[$id]['_file_paths'] = '';
754 // }
755 // $edit_last = get_post_meta($id, '_edit_last', true);
756 // WooCommerceExport::$export_instance->data[$id]['_edit_last'] = $edit_last ?? '';
757 // $edit_lock = get_post_meta($id, '_edit_lock', true);
758 // WooCommerceExport::$export_instance->data[$id]['_edit_lock'] = $edit_lock ?? '';
759 // $thumbnail_id = get_post_thumbnail_id($product->get_id());
760 // $attachment_url = wp_get_attachment_url($thumbnail_id);
761 // WooCommerceExport::$export_instance->data[$id]['_thumbnail_id'] = $attachment_url ?? '';
762 // WooCommerceExport::$export_instance->data[$id]['manage_stock'] = $product->get_manage_stock() ? '1' : '';
763 // $stock_quantity = $product->get_stock_quantity();
764 // $stock_status = $product->get_stock_status();
765 // $low_stock_threshold = $product->get_low_stock_amount();
766 // $total_sales = $product->get_total_sales();
767 // WooCommerceExport::$export_instance->data[$id]['_stock'] = $stock_quantity ?? '';
768 // WooCommerceExport::$export_instance->data[$id]['_stock_status'] = $stock_status ?? '';
769 // WooCommerceExport::$export_instance->data[$id]['_low_stock_threshold'] = $low_stock_threshold ?? '';
770 // WooCommerceExport::$export_instance->data[$id]['_stock_qty'] = $stock_quantity ?? '';
771 // WooCommerceExport::$export_instance->data[$id]['_total_sales'] = $total_sales ?? '';
772 // $downloadable = $product->is_downloadable() ? 'yes' : 'no';
773 // $virtual = $product->is_virtual() ? 'yes' : 'no';
774 // $regular_price = $product->get_regular_price();
775 // $sale_price = $product->get_sale_price();
776 // $purchase_note = $product->get_purchase_note();
777
778 // WooCommerceExport::$export_instance->data[$id]['_downloadable'] = $downloadable ?? '';
779 // WooCommerceExport::$export_instance->data[$id]['_virtual'] = $virtual ?? '';
780 // WooCommerceExport::$export_instance->data[$id]['_regular_price'] = $regular_price ?? '';
781 // WooCommerceExport::$export_instance->data[$id]['_sale_price'] = $sale_price ?? '';
782 // WooCommerceExport::$export_instance->data[$id]['_purchase_note'] = $purchase_note ?? '';
783
784 // $weight = $product->get_weight();
785 // $length = $product->get_length();
786 // $width = $product->get_width();
787 // $height = $product->get_height();
788 // $upsell_ids = $product->get_upsell_ids();
789 // $upsell_product_names = [];
790 // foreach ($upsell_ids as $up_id) {
791 // $upsell_product = wc_get_product($up_id);
792 // $upsell_product_names[] = $upsell_product ? $upsell_product->get_name() : '';
793 // }
794 // $cross_sell_ids = $product->get_cross_sell_ids();
795 // $cross_sell_product_names = [];
796 // foreach ($cross_sell_ids as $cross_id) {
797 // $cross_sell_product = wc_get_product($cross_id);
798 // $cross_sell_product_names[] = $cross_sell_product ? $cross_sell_product->get_name() : '';
799 // }
800 // WooCommerceExport::$export_instance->data[$id]['weight'] = $weight ?? '';
801 // WooCommerceExport::$export_instance->data[$id]['length'] = $length ?? '';
802 // WooCommerceExport::$export_instance->data[$id]['width'] = $width ?? '';
803 // WooCommerceExport::$export_instance->data[$id]['height'] = $height ?? '';
804 // WooCommerceExport::$export_instance->data[$id]['upsell_ids'] = implode(',', $upsell_product_names) ?? '';
805 // WooCommerceExport::$export_instance->data[$id]['crosssell_ids'] = implode(',', $cross_sell_product_names) ?? '';
806
807 // $grouping_product_ids = []; // Initialize an array to store child product IDs
808 // if ($product->is_type('grouped')) {
809 // $children = $product->get_children();
810 // foreach ($children as $child_id) {
811 // $child = wc_get_product($child_id);
812 // if (!empty($child)) {
813 // $grouping_product_ids[] = $child_id;
814 // }
815 // }
816 // }
817 // $grouping_product_ids_string = implode(',', $grouping_product_ids);
818 // WooCommerceExport::$export_instance->data[$id]['grouping_product'] = $grouping_product_ids_string;
819
820 // $sale_price_dates_from = $product->get_date_on_sale_from();
821 // $sale_price_dates_to = $product->get_date_on_sale_to();
822 // $sold_individually = $product->get_sold_individually();
823 // $backorders = $product->get_backorders();
824 // switch ($backorders) {
825 // case 'no':
826 // $backorders_no= '1';
827 // break;
828
829 // case 'notify':
830 // $backorders_no= '2';
831 // break;
832
833 // case 'yes':
834 // $backorders_no = '3';
835 // break;
836
837 // default:
838 // $backorders_no = '';
839 // break;
840 // }
841 // // WooCommerceExport::$export_instance->data[$id]['grouping_product'] = implode(',',$grouping_products);
842 // WooCommerceExport::$export_instance->data[$id]['sale_price_dates_from'] = $sale_price_dates_from ?? '';
843 // WooCommerceExport::$export_instance->data[$id]['sale_price_dates_to'] = $sale_price_dates_to ?? '';
844 // WooCommerceExport::$export_instance->data[$id]['sold_individually'] = ($sold_individually > 0) ? 'yes' : 'no';
845 // WooCommerceExport::$export_instance->data[$id]['backorders'] = $backorders_no;
846 // $product_url = ($product->is_type('external')) ? $product->get_product_url() : '';
847 // $button_text = ($product->is_type('external')) ? $product->single_add_to_cart_text() : '';
848 // $featured =get_post_meta($product->get_id(), 'featured', true) ? '1' : '0';
849 // WooCommerceExport::$export_instance->data[$id]['product_url'] = $product_url;
850 // WooCommerceExport::$export_instance->data[$id]['button_text'] = $button_text;
851 // WooCommerceExport::$export_instance->data[$id]['featured'] = $featured;
852 // $downloadable_files = [];
853 // $download_type = [];
854 // if(($product->is_type('variable'))){
855 // $download_limits = [];
856 // $download_expiries = [];
857 // $variations = $product->get_children();
858 // foreach ($variations as $variation_id) {
859 // $variation = wc_get_product($variation_id);
860 // // Check if the variation is downloadable
861 // if ($variation->is_downloadable()) {
862 // $downloads = $variation->get_downloads();
863 // foreach ($downloads as $download) {
864 // $file_url = $download->get_file(); // Get the file URL
865 // $file_name = $download->get_name(); // Get the file name
866 // $file_string = $file_name.','.$file_url;
867 // $downloadable_files[] = $file_string;
868 // if (strpos($file_url, 'http') === 0) {
869 // $download_type[] = 'external'; // If URL starts with http, it's an external URL
870 // } else {
871 // $download_type[] = 'file'; // Otherwise, it's a file URL
872 // }
873
874 // }
875 // $download_limit = $variation->get_download_limit(); // Default is -1 for unlimited
876 // $download_expiry = $variation->get_download_expiry(); // Default is -1 for no expiry
877 // // Store the values
878 // $download_limits[] = $download_limit;
879 // $download_expiries[] = $download_expiry;
880
881 // }
882 // $download_limit = !empty($download_limit) ? implode('|', $download_limits) : '';
883 // $download_expiry = !empty($download_expiry) ? implode('|', $download_expiries) : '';
884 // $download_type_str = !empty($download_type) ? implode('|', $download_type) : '';
885 // $download_file_str = !empty($downloadable_files) ? implode('|', $downloadable_files) : '';
886 // }
887 // }else{
888 // $downloads = $product->get_downloads();
889 // foreach ($downloads as $download) {
890 // $file_string = $download['name'].','.$download['file'];
891 // $downloadable_files[] = $file_string;
892 // if (strpos($download['file'], 'http') === 0) {
893 // $download_type[] = 'external'; // If URL starts with http, it's an external URL
894 // } else {
895 // $download_type[] = 'file'; // Otherwise, it's a file URL
896 // }
897 // }
898 // $download_type_str = !empty($download_type) ? implode('|', $download_type) : '';
899 // $download_file_str = !empty($downloadable_files) ? implode('|', $downloadable_files) : '';
900
901 // $download_limit = $product->get_download_limit();
902 // $download_expiry = $product->get_download_expiry();
903 // }
904
905 // WooCommerceExport::$export_instance->data[$id]['downloadable_files'] = $download_file_str;
906 // WooCommerceExport::$export_instance->data[$id]['download_limit'] = ($download_limit > -1) ? $download_limit : '';
907 // WooCommerceExport::$export_instance->data[$id]['download_expiry'] = ($download_expiry > -1) ? $download_expiry : '';
908 // WooCommerceExport::$export_instance->data[$id]['download_type'] = $download_type_str;
909
910 // $subscription_period = get_post_meta($id, '_subscription_period', true);
911 // $subscription_period_interval = get_post_meta($id, '_subscription_period_interval', true);
912 // $subscription_length = get_post_meta($id, '_subscription_length', true);
913 // $subscription_trial_period = get_post_meta($id, '_subscription_trial_period', true);
914 // $subscription_trial_length = get_post_meta($id, '_subscription_trial_length', true);
915 // $subscription_price = get_post_meta($id, '_subscription_price', true);
916 // $subscription_sign_up_fee = get_post_meta($id, '_subscription_sign_up_fee', true);
917
918 // WooCommerceExport::$export_instance->data[$id]['_subscription_period'] = $subscription_period ?? '';
919 // WooCommerceExport::$export_instance->data[$id]['_subscription_period_interval'] = $subscription_period_interval ?? '';
920 // WooCommerceExport::$export_instance->data[$id]['_subscription_length'] = $subscription_length ?? '';
921 // WooCommerceExport::$export_instance->data[$id]['_subscription_trial_period'] = $subscription_trial_period ?? '';
922 // WooCommerceExport::$export_instance->data[$id]['_subscription_trial_length'] = $subscription_trial_length ?? '';
923 // WooCommerceExport::$export_instance->data[$id]['_subscription_price'] = $subscription_price ?? '';
924 // WooCommerceExport::$export_instance->data[$id]['_subscription_sign_up_fee'] = $subscription_sign_up_fee ?? '';
925 // // Retrieve barcode details
926 // if(is_plugin_active('yith-woocommerce-barcodes-premium/init.php' )){
927 // $barcode_protocol = get_post_meta($id, '_ywbc_barcode_protocol', true);
928 // $barcode_value = get_post_meta($id, '_ywbc_barcode_value', true);
929 // $barcode_display_value = get_post_meta($id, '_ywbc_barcode_display_value', true);
930 // WooCommerceExport::$export_instance->data[$id]['_ywbc_barcode_display_value'] = $barcode_display_value ?? '';
931 // WooCommerceExport::$export_instance->data[$id]['_ywbc_barcode_value'] = $barcode_value ?? '';
932 // WooCommerceExport::$export_instance->data[$id]['_ywbc_barcode_protocol'] = $barcode_protocol ?? '';
933 // }
934
935
936 // //woocommerce-product-bundles plugin
937 // //woocommerce-product-bundles plugin
938 // if (is_plugin_active('woocommerce-product-bundles/woocommerce-product-bundles.php')) {
939 // // Get the bundle product
940 // $bundle_product = wc_get_product($id);
941
942 // if ($bundle_product && $bundle_product->is_type('bundle')) {
943 // // Initialize default values
944 // $bundle_items = array();
945 // $optional_values = array();
946 // $quantity_min = array();
947 // $quantity_max = array();
948 // $price_values = array();
949 // $discount_values = array();
950 // $product_values = array();
951 // $cart_values = array();
952 // $order_values = array();
953 // $product_price_values = array();
954 // $cart_price_values = array();
955 // $order_price_values = array();
956 // $thumb_values = array();
957 // $override_values = array();
958 // $description_values = array();
959 // $override_title_values = array();
960 // $override_description_values = array();
961
962 // // Get bundle settings
963 // $min_bundle_size = $bundle_product->get_min_bundle_size();
964 // $max_bundle_size = $bundle_product->get_max_bundle_size();
965 // $edit_in_cart = $bundle_product->get_editable_in_cart() ? 'Yes' : 'No';
966 // $layout = $bundle_product->get_layout(); // Assuming this method exists
967 // $get_mode = $bundle_product->get_group_mode();
968 // if($get_mode == 'noindent'){
969 // $item_grouping = 'flat';
970 // }else if($get_mode == 'parent'){
971 // $item_grouping = 'grouped';
972 // }else{
973 // $item_grouping = '';
974 // }
975 // foreach ($bundle_product->get_bundled_items() as $bundled_item) {
976 // // Get bundled item product
977 // $bundled_product = $bundled_item->get_product();
978 // $bundle_items[] = $bundled_product->get_name();
979
980 // // Retrieve settings for each bundled item
981 // $optional_values[] = method_exists($bundled_item, 'is_optional') && $bundled_item->is_optional() ? 'Yes' : 'No';
982 // $quantity_min[] = method_exists($bundled_item, 'get_min_quantity') ? $bundled_item->get_min_quantity() : '';
983 // $quantity_max[] = method_exists($bundled_item, 'get_max_quantity') ? $bundled_item->get_max_quantity() : '';
984 // $price_values[] = method_exists($bundled_item, 'is_priced_individually') && $bundled_item->is_priced_individually() ? 'Yes' : 'No';
985 // $discount_values[] = method_exists($bundled_item, 'get_discount') ? $bundled_item->get_discount() : '';
986 // $product_values[] = method_exists($bundled_item, 'get_single_product_visibility') && $bundled_item->get_single_product_visibility() ? 'Yes' : 'No';
987 // $cart_values[] = method_exists($bundled_item, 'get_cart_visibility') && $bundled_item->get_cart_visibility() ? 'Yes' : 'No';
988 // $order_values[] = method_exists($bundled_item, 'get_order_visibility') && $bundled_item->get_order_visibility() ? 'Yes' : 'No';
989 // $product_price_values[] = method_exists($bundled_item, 'get_single_product_price_visibility') && $bundled_item->get_single_product_price_visibility() ? 'Yes' : 'No';
990 // $cart_price_values[] = method_exists($bundled_item, 'get_cart_price_visibility') && $bundled_item->get_cart_price_visibility() ? 'Yes' : 'No';
991 // $order_price_values[] = method_exists($bundled_item, 'get_order_price_visibility') && $bundled_item->get_order_price_visibility() ? 'Yes' : 'No';
992 // $thumb_values[] = method_exists($bundled_item, 'get_hide_thumbnail') && $bundled_item->get_hide_thumbnail() ? 'Yes' : 'No';
993 // $override_values[] = method_exists($bundled_item, 'get_override_title') && $bundled_item->get_override_title() ? 'Yes' : 'No';
994 // $description_values[] = method_exists($bundled_item, 'get_override_description') && $bundled_item->get_override_description() ? 'Yes' : 'No';
995 // $override_title_values[] = method_exists($bundled_item, 'get_override_title_value') ? $bundled_item->get_override_title_value() : '';
996 // $override_description_values[] = method_exists($bundled_item, 'get_override_description_value') ? $bundled_item->get_override_description_value() : '';
997 // }
998
999 // // Prepare export data
1000 // WooCommerceExport::$export_instance->data[$id]['product_bundle_items'] = implode('|', $bundle_items) ?? '';
1001 // WooCommerceExport::$export_instance->data[$id]['optional'] = implode('|', $optional_values) ?? '';
1002 // WooCommerceExport::$export_instance->data[$id]['quantity_min'] = implode('|', $quantity_min) ?? '';
1003 // WooCommerceExport::$export_instance->data[$id]['quantity_max'] = implode('|', $quantity_max) ?? '';
1004 // WooCommerceExport::$export_instance->data[$id]['priced_individually'] = implode('|', $price_values) ?? '';
1005 // WooCommerceExport::$export_instance->data[$id]['discount'] = implode('|', $discount_values) ?? '';
1006 // WooCommerceExport::$export_instance->data[$id]['single_product_visibility'] = implode('|', $product_values) ?? '';
1007 // WooCommerceExport::$export_instance->data[$id]['cart_visibility'] = implode('|', $cart_values) ?? '';
1008 // WooCommerceExport::$export_instance->data[$id]['order_visibility'] = implode('|', $order_values) ?? '';
1009 // WooCommerceExport::$export_instance->data[$id]['single_product_price_visibility'] = implode('|', $product_price_values) ?? '';
1010 // WooCommerceExport::$export_instance->data[$id]['cart_price_visibility'] = implode('|', $cart_price_values) ?? '';
1011 // WooCommerceExport::$export_instance->data[$id]['order_price_visibility'] = implode('|', $order_price_values) ?? '';
1012 // WooCommerceExport::$export_instance->data[$id]['hide_thumbnail'] = implode('|', $thumb_values) ?? '';
1013 // WooCommerceExport::$export_instance->data[$id]['override_title'] = implode('|', $override_values) ?? '';
1014 // WooCommerceExport::$export_instance->data[$id]['override_description'] = implode('|', $description_values) ?? '';
1015 // WooCommerceExport::$export_instance->data[$id]['override_title_value'] = implode('|', $override_title_values) ?? '';
1016 // WooCommerceExport::$export_instance->data[$id]['override_description_value'] = implode('|', $override_description_values) ?? '';
1017 // WooCommerceExport::$export_instance->data[$id]['pb_sale_price'] = $bundle_product->get_sale_price() ?? '';
1018 // WooCommerceExport::$export_instance->data[$id]['pb_regular_price'] = $bundle_product->get_regular_price() ?? '';
1019 // WooCommerceExport::$export_instance->data[$id]['min_bundle_size'] = $min_bundle_size ?? '';
1020 // WooCommerceExport::$export_instance->data[$id]['max_bundle_size'] = $max_bundle_size ?? '';
1021 // WooCommerceExport::$export_instance->data[$id]['edit_in_cart'] = $edit_in_cart ?? '';
1022 // WooCommerceExport::$export_instance->data[$id]['layout'] = $layout ?? '';
1023 // WooCommerceExport::$export_instance->data[$id]['item_grouping'] = $item_grouping ?? '';
1024 // }
1025 // }
1026
1027 // }
1028 public function getProductData($id, $type, $optionalType)
1029 {
1030 global $wpdb;
1031 $product = wc_get_product($id);
1032
1033 if(!empty($product)){
1034 $booking_type ='';
1035 $product_type = $product->get_type();
1036 if($product_type == 'variation'){
1037 $parent_id = $product->get_parent_id();
1038 $parent_product = wc_get_product($parent_id);
1039 $parent_sku = $parent_product->get_sku();
1040 WooCommerceExport::$export_instance->data[$id]['parent'] = $parent_sku;
1041 }
1042 $product_datas = $product->get_data();
1043 $product_sku = $product->get_sku();
1044 WooCommerceExport::$export_instance->data[$id]['PRODUCTSKU'] = $product_sku ?? '';
1045 $product_attributes = $product->get_attributes();
1046 if($product_type !=='variation'){
1047 if (!empty($product_attributes)) {
1048 $count =count($product_attributes);
1049 $new_attr_array =array();
1050 foreach ($product_attributes as $attribute_key => $attribute) {
1051 $new_attr_array[] = $attribute;
1052 }
1053 array_unshift($new_attr_array,"");
1054 unset($new_attr_array[0]);
1055 $att_values = [];
1056 $stored_id = [];
1057 if(!empty($new_attr_array)){
1058 foreach ($new_attr_array as $attribute_key => $attribute) {
1059 if (is_a($attribute, 'WC_Product_Attribute')) {
1060 if(strpos($attribute['name'],'pa_') !== false){
1061 $attr_name = str_replace('pa_', '', $attribute['name']);
1062 $attr_name = $wpdb->get_var($wpdb->prepare("SELECT attribute_label FROM {$wpdb->prefix}woocommerce_attribute_taxonomies WHERE attribute_name=%s", $attr_name));
1063 }
1064 else{
1065 $attr_name = $attribute['name'];
1066 }
1067 $swatch_values = [];
1068
1069 WooCommerceExport::$export_instance->data[$id]['product_attribute_name'.$attribute_key]= $attr_name;
1070
1071
1072
1073 $taxonomy_name = $attribute['taxonomy'];
1074 $attribute_options = $attribute['options'];
1075 $term_names = $att_values = array();
1076 foreach ($attribute_options as $term_key => $term_id) {
1077 if(is_numeric($term_id)){
1078 $term = get_term_by('id', $term_id, $taxonomy_name);
1079 if (!empty($term->name)) {
1080 $term_names[] = $term->name;
1081 // Retrieve swatch type and value if available
1082 if(is_plugin_active( 'woo-variation-swatches/woo-variation-swatches.php' ) || is_plugin_active( 'woo-variation-swatches-pro/woo-variation-swatches.php' )){
1083 $term_meta = $wpdb->get_results($wpdb->prepare("SELECT meta_key,meta_value FROM {$wpdb->termmeta} WHERE term_id = %d ", absint($term->term_id)),ARRAY_A);
1084 $attri_type = $wpdb->get_results( $wpdb->prepare("SELECT attribute_type FROM {$wpdb->prefix}woocommerce_attribute_taxonomies where attribute_label = %s ", $attr_name),ARRAY_A);
1085 $attri_type = !empty($attri_type[0]['attribute_type']) ? $attri_type[0]['attribute_type'] : '';
1086 $term_meta = end($term_meta);
1087 $swatch_value = '';
1088 $swatch_types = [
1089 'product_attribute_color' => 'color',
1090 'product_attribute_image' => 'image',
1091 'product_attribute_button' => 'button',
1092 'product_attribute_radio' => 'radio'
1093 ];
1094
1095 if (!empty($term_meta) && array_key_exists($term_meta['meta_key'], $swatch_types)) {
1096 $swatch_type = $swatch_types[$term_meta['meta_key']];
1097 $swatch_value = $term_meta['meta_value'];
1098 } else {
1099 $swatch_type = '';
1100 $swatch_value = '';
1101 }
1102 $swatch_values[] = !empty($swatch_value) ? $term->name . '->' . $swatch_value : '';
1103 }
1104
1105 }
1106
1107 }
1108 else{
1109 $term_names [] = $term_id;
1110 }
1111 }
1112
1113
1114 if (is_array($swatch_values) && array_filter($swatch_values)) {
1115 $attribute_name = $attr_name . '->' . $swatch_type;
1116 $att_values = implode(',', $swatch_values);
1117 } else {
1118 if (!empty($attri_type) && !empty($term_names) && !empty($swatch_type)) {
1119 $attribute_name = $attr_name . '->' . $attri_type;
1120 $att_values = implode(',', $term_names);
1121 } else if (!empty($term_names)) {
1122 $attr_name = $wpdb->get_var($wpdb->prepare("SELECT attribute_label FROM {$wpdb->prefix}woocommerce_attribute_taxonomies WHERE attribute_name=%s", $attr_name));
1123 $attribute_name = $attr_name;
1124 $att_values = implode(',', $term_names);
1125 }
1126 }
1127 if (is_plugin_active('woo-variation-swatches/woo-variation-swatches.php') || is_plugin_active('woo-variation-swatches-pro/woo-variation-swatches.php')) {
1128 WooCommerceExport::$export_instance->data[$id]['product_attribute_name' . $attribute_key] = $attribute_name;
1129 WooCommerceExport::$export_instance->data[$id]['product_attribute_value' . $attribute_key] = $att_values;
1130 }else{
1131 $att_values = implode(',', $term_names);
1132 WooCommerceExport::$export_instance->data[$id]['product_attribute_value' . $attribute_key] = $att_values;
1133 }
1134 // if (!empty($term_names)) {
1135 // $att_values = implode(',', $term_names);
1136 // }
1137
1138
1139 WooCommerceExport::$export_instance->data[$id]['product_attribute_visible' . $attribute_key] = $attribute['is_visible'];
1140 $is_variation[] = $attribute['is_variation'];
1141 $position[] = $attribute['position'];
1142 $is_taxonomy[] = $attribute['is_taxonomy'];
1143 }
1144
1145 }
1146 }
1147 }
1148 }
1149 else{
1150 if (!empty($product_attributes)) {
1151 $i=1;
1152 foreach ($product_attributes as $attribute_key => $attribute) {
1153 $attr_name = str_replace('pa_', '', $attribute_key);
1154 $attr_name = $wpdb->get_var($wpdb->prepare("SELECT attribute_label FROM {$wpdb->prefix}woocommerce_attribute_taxonomies WHERE attribute_name=%s", $attr_name));
1155 $attr_value = $wpdb->get_var($wpdb->prepare("SELECT name FROM {$wpdb->prefix}terms WHERE slug = %s", $attribute));
1156 WooCommerceExport::$export_instance->data[$id]['product_attribute_name'.$i] = $attr_name;
1157 WooCommerceExport::$export_instance->data[$id]['product_attribute_value'.$i] = $attr_value;
1158 $i++;
1159 }
1160 }
1161 }
1162
1163
1164 $get_catalog_visibility = $product->get_catalog_visibility();
1165 $visibility_mapping = array('visible' => '1','catalog' => '2','search' => '3','hidden' => '4');
1166 WooCommerceExport::$export_instance->data[$id]['visibility'] = array_key_exists($get_catalog_visibility,$visibility_mapping) ? $visibility_mapping[$get_catalog_visibility] : '';
1167
1168 $tax_status = $product->get_tax_status();
1169 $tax_status_mapping = array('taxable' => 1 , 'shipping' => 2, 'none' => 3);
1170 WooCommerceExport::$export_instance->data[$id]['tax_status'] = array_key_exists($tax_status,$tax_status_mapping) ? $tax_status_mapping[$tax_status] : '' ;
1171
1172 $product_type = $product->get_type();
1173 $product_type_mapping = array('simple' => 1 , 'grouped' => 2, 'external' => 3, 'variable' => 4 , 'subscription' => 5 , 'variable-subscription' => 6 ,'bundle' => 7,'variation' => '8' , 'jet_booking' => 9);
1174 WooCommerceExport::$export_instance->data[$id]['product_type'] = array_key_exists($product_type,$product_type_mapping) ? $product_type_mapping[$product_type] : '' ;
1175
1176 if (has_term('featured', 'product_visibility', $id)) {
1177 WooCommerceExport::$export_instance->data[$id]['featured_product'] = '1';
1178 }
1179 WooCommerceExport::$export_instance->data[$id]['tax_class'] = $product_datas['tax_class'] ?? '';
1180 if (method_exists($product, 'get_file_paths')) {
1181 $file_paths = $product->get_file_paths();
1182 WooCommerceExport::$export_instance->data[$id]['_file_paths'] = isset($file_paths) ? $file_paths : '';
1183 } else {
1184 WooCommerceExport::$export_instance->data[$id]['_file_paths'] = '';
1185 }
1186 $edit_last = get_post_meta($id, '_edit_last', true);
1187 WooCommerceExport::$export_instance->data[$id]['_edit_last'] = $edit_last ?? '';
1188 $edit_lock = get_post_meta($id, '_edit_lock', true);
1189 WooCommerceExport::$export_instance->data[$id]['_edit_lock'] = $edit_lock ?? '';
1190 $thumbnail_id = get_post_thumbnail_id($product->get_id());
1191 $attachment_url = wp_get_attachment_url($thumbnail_id);
1192 WooCommerceExport::$export_instance->data[$id]['_thumbnail_id'] = $attachment_url ?? '';
1193 WooCommerceExport::$export_instance->data[$id]['manage_stock'] = $product->get_manage_stock() ? '1' : '';
1194 $stock_quantity = $product->get_stock_quantity();
1195 $stock_status = $product->get_stock_status();
1196 $low_stock_threshold = $product->get_low_stock_amount();
1197 $total_sales = $product->get_total_sales();
1198 WooCommerceExport::$export_instance->data[$id]['_stock'] = $stock_quantity ?? '';
1199 WooCommerceExport::$export_instance->data[$id]['_stock_status'] = $stock_status ?? '';
1200 WooCommerceExport::$export_instance->data[$id]['_low_stock_threshold'] = $low_stock_threshold ?? '';
1201 WooCommerceExport::$export_instance->data[$id]['_total_sales'] = $total_sales ?? '';
1202 $downloadable = $product->is_downloadable() ? 'yes' : 'no';
1203 $virtual = $product->is_virtual() ? 'yes' : 'no';
1204 $regular_price = $product->get_regular_price();
1205 $sale_price = $product->get_sale_price();
1206 $purchase_note = $product->get_purchase_note();
1207
1208 WooCommerceExport::$export_instance->data[$id]['_downloadable'] = $downloadable ?? '';
1209 WooCommerceExport::$export_instance->data[$id]['_virtual'] = $virtual ?? '';
1210 WooCommerceExport::$export_instance->data[$id]['_regular_price'] = $regular_price ?? '';
1211 WooCommerceExport::$export_instance->data[$id]['_sale_price'] = $sale_price ?? '';
1212 WooCommerceExport::$export_instance->data[$id]['_purchase_note'] = $purchase_note ?? '';
1213
1214 $weight = $product->get_weight();
1215 $length = $product->get_length();
1216 $width = $product->get_width();
1217 $height = $product->get_height();
1218 $upsell_ids = $product->get_upsell_ids();
1219 $upsell_product_names = [];
1220 foreach ($upsell_ids as $up_id) {
1221 $upsell_product = wc_get_product($up_id);
1222 $upsell_product_names[] = $upsell_product ? $upsell_product->get_name() : '';
1223 }
1224 $cross_sell_ids = $product->get_cross_sell_ids();
1225 $cross_sell_product_names = [];
1226 foreach ($cross_sell_ids as $cross_id) {
1227 $cross_sell_product = wc_get_product($cross_id);
1228 $cross_sell_product_names[] = $cross_sell_product ? $cross_sell_product->get_name() : '';
1229 }
1230 WooCommerceExport::$export_instance->data[$id]['weight'] = $weight ?? '';
1231 WooCommerceExport::$export_instance->data[$id]['length'] = $length ?? '';
1232 WooCommerceExport::$export_instance->data[$id]['width'] = $width ?? '';
1233 WooCommerceExport::$export_instance->data[$id]['height'] = $height ?? '';
1234 WooCommerceExport::$export_instance->data[$id]['upsell_ids'] = !empty($upsell_product_names) ? implode(',', $upsell_product_names) : '';
1235 WooCommerceExport::$export_instance->data[$id]['crosssell_ids'] = !empty($cross_sell_product_names) ? implode(',', $cross_sell_product_names) : '';
1236
1237 $grouping_product_ids = []; // Initialize an array to store child product IDs
1238 if ($product->is_type('grouped')) {
1239 $children = $product->get_children();
1240 foreach ($children as $child_id) {
1241 $child = wc_get_product($child_id);
1242 if (!empty($child)) {
1243 $grouping_product_ids[] = $child_id;
1244 }
1245 }
1246 }
1247 $grouping_product_ids_string = !empty($grouping_product_ids) ? implode(',', $grouping_product_ids) : '';
1248 WooCommerceExport::$export_instance->data[$id]['grouping_product'] = $grouping_product_ids_string;
1249
1250 $sale_price_dates_from = $product->get_date_on_sale_from();
1251 $sale_price_dates_to = $product->get_date_on_sale_to();
1252 $sold_individually = $product->get_sold_individually();
1253 $backorders = $product->get_backorders();
1254 switch ($backorders) {
1255 case 'no':
1256 $backorders_no= '1';
1257 break;
1258
1259 case 'notify':
1260 $backorders_no= '2';
1261 break;
1262
1263 case 'yes':
1264 $backorders_no = '3';
1265 break;
1266
1267 default:
1268 $backorders_no = '';
1269 break;
1270 }
1271 WooCommerceExport::$export_instance->data[$id]['sale_price_dates_from'] = $sale_price_dates_from ?? '';
1272 WooCommerceExport::$export_instance->data[$id]['sale_price_dates_to'] = $sale_price_dates_to ?? '';
1273 WooCommerceExport::$export_instance->data[$id]['sold_individually'] = ($sold_individually > 0) ? 'yes' : 'no';
1274 WooCommerceExport::$export_instance->data[$id]['backorders'] = $backorders_no;
1275 // $product_url = ($product->is_type('external')) ? $product->get_product_url() : '';
1276 $product_url = get_permalink($id);
1277
1278 $button_text = ($product->is_type('external')) ? $product->single_add_to_cart_text() : '';
1279 $featured = get_post_meta($product->get_id(), 'featured', true) ? '1' : '0';
1280 WooCommerceExport::$export_instance->data[$id]['product_url'] = $product_url;
1281 WooCommerceExport::$export_instance->data[$id]['button_text'] = $button_text;
1282 WooCommerceExport::$export_instance->data[$id]['featured'] = $featured;
1283 $downloadable_files = [];
1284 $download_type = [];
1285 if(($product->is_type('variable'))){
1286 $download_limits = [];
1287 $download_expiries = [];
1288 $variations = $product->get_children();
1289 foreach ($variations as $variation_id) {
1290 $variation = wc_get_product($variation_id);
1291 // Check if the variation is downloadable
1292 if ($variation->is_downloadable()) {
1293 $downloads = $variation->get_downloads();
1294 foreach ($downloads as $download) {
1295 $file_url = $download->get_file(); // Get the file URL
1296 $file_name = $download->get_name(); // Get the file name
1297 $file_string = $file_name.','.$file_url;
1298 $downloadable_files[] = $file_string;
1299 if (strpos($file_url, 'http') === 0) {
1300 $download_type[] = 'external'; // If URL starts with http, it's an external URL
1301 } else {
1302 $download_type[] = 'file'; // Otherwise, it's a file URL
1303 }
1304
1305 }
1306 $download_limit = $variation->get_download_limit(); // Default is -1 for unlimited
1307 $download_expiry = $variation->get_download_expiry(); // Default is -1 for no expiry
1308 // Store the values
1309 $download_limits[] = $download_limit;
1310 $download_expiries[] = $download_expiry;
1311
1312 }
1313 $download_limit = !empty($download_limit) ? implode('|', $download_limits) : '';
1314 $download_expiry = !empty($download_expiry) ? implode('|', $download_expiries) : '';
1315 $download_type_str = !empty($download_type) ? implode('|', $download_type) : '';
1316 $download_file_str = !empty($downloadable_files) ? implode('|', $downloadable_files) : '';
1317 }
1318 }else{
1319 $downloads = $product->get_downloads();
1320 foreach ($downloads as $download) {
1321 $file_string = $download['name'].','.$download['file'];
1322 $downloadable_files[] = $file_string;
1323 if (strpos($download['file'], 'http') === 0) {
1324 $download_type[] = 'external'; // If URL starts with http, it's an external URL
1325 } else {
1326 $download_type[] = 'file'; // Otherwise, it's a file URL
1327 }
1328 }
1329 $download_type_str = !empty($download_type) ? implode('|', $download_type) : '';
1330 $download_file_str = !empty($downloadable_files) ? implode('|', $downloadable_files) : '';
1331
1332 $download_limit = $product->get_download_limit();
1333 $download_expiry = $product->get_download_expiry();
1334 }
1335
1336 WooCommerceExport::$export_instance->data[$id]['downloadable_files'] = $download_file_str;
1337 WooCommerceExport::$export_instance->data[$id]['download_limit'] = ($download_limit > -1) ? $download_limit : '';
1338 WooCommerceExport::$export_instance->data[$id]['download_expiry'] = ($download_expiry > -1) ? $download_expiry : '';
1339 WooCommerceExport::$export_instance->data[$id]['download_type'] = $download_type_str;
1340
1341 $subscription_period = get_post_meta($id, '_subscription_period', true);
1342 $subscription_period_interval = get_post_meta($id, '_subscription_period_interval', true);
1343 $subscription_length = get_post_meta($id, '_subscription_length', true);
1344 $subscription_trial_period = get_post_meta($id, '_subscription_trial_period', true);
1345 $subscription_trial_length = get_post_meta($id, '_subscription_trial_length', true);
1346 $subscription_price = get_post_meta($id, '_subscription_price', true);
1347 $subscription_sign_up_fee = get_post_meta($id, '_subscription_sign_up_fee', true);
1348
1349 WooCommerceExport::$export_instance->data[$id]['_subscription_period'] = $subscription_period ?? '';
1350 WooCommerceExport::$export_instance->data[$id]['_subscription_period_interval'] = $subscription_period_interval ?? '';
1351 WooCommerceExport::$export_instance->data[$id]['_subscription_length'] = $subscription_length ?? '';
1352 WooCommerceExport::$export_instance->data[$id]['_subscription_trial_period'] = $subscription_trial_period ?? '';
1353 WooCommerceExport::$export_instance->data[$id]['_subscription_trial_length'] = $subscription_trial_length ?? '';
1354 WooCommerceExport::$export_instance->data[$id]['_subscription_price'] = $subscription_price ?? '';
1355 WooCommerceExport::$export_instance->data[$id]['_subscription_sign_up_fee'] = $subscription_sign_up_fee ?? '';
1356
1357 if ( is_plugin_active( 'yith-woocommerce-barcodes-premium/init.php' )){
1358 // Retrieve barcode details
1359 $barcode_protocol = get_post_meta($id, '_ywbc_barcode_protocol', true);
1360 $barcode_value = get_post_meta($id, '_ywbc_barcode_value', true);
1361 $barcode_display_value = get_post_meta($id, '_ywbc_barcode_display_value', true);
1362 WooCommerceExport::$export_instance->data[$id]['_ywbc_barcode_display_value'] = $barcode_display_value ?? '';
1363 WooCommerceExport::$export_instance->data[$id]['_ywbc_barcode_value'] = $barcode_value ?? '';
1364 WooCommerceExport::$export_instance->data[$id]['_ywbc_barcode_protocol'] = $barcode_protocol ?? '';
1365 }
1366
1367
1368 }
1369
1370 // //woocommerce-product-bundles plugin
1371 if (is_plugin_active('woocommerce-product-bundles/woocommerce-product-bundles.php')) {
1372 // Get the bundle product
1373 $bundle_product = wc_get_product($id);
1374
1375 if ($bundle_product && $bundle_product->is_type('bundle')) {
1376 // Initialize default values
1377 $bundle_items = array();
1378 $optional_values = array();
1379 $quantity_min = array();
1380 $quantity_max = array();
1381 $price_values = array();
1382 $discount_values = array();
1383 $product_values = array();
1384 $cart_values = array();
1385 $order_values = array();
1386 $product_price_values = array();
1387 $cart_price_values = array();
1388 $order_price_values = array();
1389 $thumb_values = array();
1390 $override_values = array();
1391 $description_values = array();
1392 $override_title_values = array();
1393 $override_description_values = array();
1394
1395 // Get bundle settings
1396 $min_bundle_size = $bundle_product->get_min_bundle_size();
1397 $max_bundle_size = $bundle_product->get_max_bundle_size();
1398 $edit_in_cart = $bundle_product->get_editable_in_cart() ? 'Yes' : 'No';
1399 $layout = $bundle_product->get_layout(); // Assuming this method exists
1400 $get_mode = $bundle_product->get_group_mode();
1401 if($get_mode == 'noindent'){
1402 $item_grouping = 'flat';
1403 }else if($get_mode == 'parent'){
1404 $item_grouping = 'grouped';
1405 }else{
1406 $item_grouping = '';
1407 }
1408 foreach ($bundle_product->get_bundled_items() as $bundled_item) {
1409 // Get bundled item product
1410 $bundled_product = $bundled_item->get_product();
1411 $bundle_items[] = $bundled_product->get_name();
1412
1413 // Retrieve settings for each bundled item
1414 $optional_values[] = method_exists($bundled_item, 'is_optional') && $bundled_item->is_optional() ? 'Yes' : 'No';
1415 $quantity_min[] = method_exists($bundled_item, 'get_min_quantity') ? $bundled_item->get_min_quantity() : '';
1416 $quantity_max[] = method_exists($bundled_item, 'get_max_quantity') ? $bundled_item->get_max_quantity() : '';
1417 $price_values[] = method_exists($bundled_item, 'is_priced_individually') && $bundled_item->is_priced_individually() ? 'Yes' : 'No';
1418 $discount_values[] = method_exists($bundled_item, 'get_discount') ? $bundled_item->get_discount() : '';
1419 $product_values[] = method_exists($bundled_item, 'get_single_product_visibility') && $bundled_item->get_single_product_visibility() ? 'Yes' : 'No';
1420 $cart_values[] = method_exists($bundled_item, 'get_cart_visibility') && $bundled_item->get_cart_visibility() ? 'Yes' : 'No';
1421 $order_values[] = method_exists($bundled_item, 'get_order_visibility') && $bundled_item->get_order_visibility() ? 'Yes' : 'No';
1422 $product_price_values[] = method_exists($bundled_item, 'get_single_product_price_visibility') && $bundled_item->get_single_product_price_visibility() ? 'Yes' : 'No';
1423 $cart_price_values[] = method_exists($bundled_item, 'get_cart_price_visibility') && $bundled_item->get_cart_price_visibility() ? 'Yes' : 'No';
1424 $order_price_values[] = method_exists($bundled_item, 'get_order_price_visibility') && $bundled_item->get_order_price_visibility() ? 'Yes' : 'No';
1425 $thumb_values[] = method_exists($bundled_item, 'get_hide_thumbnail') && $bundled_item->get_hide_thumbnail() ? 'Yes' : 'No';
1426 $override_values[] = method_exists($bundled_item, 'get_override_title') && $bundled_item->get_override_title() ? 'Yes' : 'No';
1427 $description_values[] = method_exists($bundled_item, 'get_override_description') && $bundled_item->get_override_description() ? 'Yes' : 'No';
1428 $override_title_values[] = method_exists($bundled_item, 'get_override_title_value') ? $bundled_item->get_override_title_value() : '';
1429 $override_description_values[] = method_exists($bundled_item, 'get_override_description_value') ? $bundled_item->get_override_description_value() : '';
1430 }
1431
1432 // Prepare export data
1433 WooCommerceExport::$export_instance->data[$id]['product_bundle_items'] = implode('|', $bundle_items) ?? '';
1434 WooCommerceExport::$export_instance->data[$id]['optional'] = implode('|', $optional_values) ?? '';
1435 WooCommerceExport::$export_instance->data[$id]['quantity_min'] = implode('|', $quantity_min) ?? '';
1436 WooCommerceExport::$export_instance->data[$id]['quantity_max'] = implode('|', $quantity_max) ?? '';
1437 WooCommerceExport::$export_instance->data[$id]['priced_individually'] = implode('|', $price_values) ?? '';
1438 WooCommerceExport::$export_instance->data[$id]['discount'] = implode('|', $discount_values) ?? '';
1439 WooCommerceExport::$export_instance->data[$id]['single_product_visibility'] = implode('|', $product_values) ?? '';
1440 WooCommerceExport::$export_instance->data[$id]['cart_visibility'] = implode('|', $cart_values) ?? '';
1441 WooCommerceExport::$export_instance->data[$id]['order_visibility'] = implode('|', $order_values) ?? '';
1442 WooCommerceExport::$export_instance->data[$id]['single_product_price_visibility'] = implode('|', $product_price_values) ?? '';
1443 WooCommerceExport::$export_instance->data[$id]['cart_price_visibility'] = implode('|', $cart_price_values) ?? '';
1444 WooCommerceExport::$export_instance->data[$id]['order_price_visibility'] = implode('|', $order_price_values) ?? '';
1445 WooCommerceExport::$export_instance->data[$id]['hide_thumbnail'] = implode('|', $thumb_values) ?? '';
1446 WooCommerceExport::$export_instance->data[$id]['override_title'] = implode('|', $override_values) ?? '';
1447 WooCommerceExport::$export_instance->data[$id]['override_description'] = implode('|', $description_values) ?? '';
1448 WooCommerceExport::$export_instance->data[$id]['override_title_value'] = implode('|', $override_title_values) ?? '';
1449 WooCommerceExport::$export_instance->data[$id]['override_description_value'] = implode('|', $override_description_values) ?? '';
1450 WooCommerceExport::$export_instance->data[$id]['pb_sale_price'] = $bundle_product->get_sale_price() ?? '';
1451 WooCommerceExport::$export_instance->data[$id]['pb_regular_price'] = $bundle_product->get_regular_price() ?? '';
1452 WooCommerceExport::$export_instance->data[$id]['min_bundle_size'] = $min_bundle_size ?? '';
1453 WooCommerceExport::$export_instance->data[$id]['max_bundle_size'] = $max_bundle_size ?? '';
1454 WooCommerceExport::$export_instance->data[$id]['edit_in_cart'] = $edit_in_cart ?? '';
1455 WooCommerceExport::$export_instance->data[$id]['layout'] = $layout ?? '';
1456 WooCommerceExport::$export_instance->data[$id]['item_grouping'] = $item_grouping ?? '';
1457 }
1458 }
1459
1460 }
1461
1462 /**
1463 * Fetch Terms & Taxonomies
1464 * @param $mode
1465 * @param $module
1466 * @param $optionalType
1467 * @return array
1468 */
1469 public function FetchTaxonomies($module, $optionalType, $mode = null) {
1470
1471 global $wpdb;
1472 $terms_table = $wpdb->prefix."terms";
1473 $terms_taxo_table = $wpdb->prefix."term_taxonomy";
1474 self::$export_instance->generateHeaders($module, $optionalType);
1475 $taxonomy = $optionalType;
1476 $query = $wpdb->prepare("SELECT * FROM $terms_table t INNER JOIN $terms_taxo_table tax ON `tax`.term_id = `t`.term_id WHERE `tax`.taxonomy = %s ", $taxonomy);
1477
1478 $get_all_taxonomies = $wpdb->get_results($query);
1479 self::$export_instance->totalRowCount = count($get_all_taxonomies);
1480 if(!empty($get_all_taxonomies)) {
1481 foreach( $get_all_taxonomies as $termKey => $termValue ) {
1482 $termID = $termValue->term_id;
1483 $termMeta = get_term_meta($termID);
1484 //wpsc_meta data starts
1485 if(in_array('wp-e-commerce/wp-shopping-cart.php', self::$export_instance->get_active_plugins())) {
1486 $wpsc_query = $wpdb->prepare("select meta_key,meta_value from {$wpdb->prefix}wpsc_meta where object_id = %d AND object_type = %s", $termID, 'wpsc_category');
1487 $wpsc_meta = $wpdb->get_results($wpsc_query,ARRAY_A);
1488 foreach($wpsc_meta as $mk => $mv){
1489 if($mv['meta_key'] == 'image'){
1490 if($mv['meta_value']){
1491 $udir = wp_upload_dir();
1492 $img_path = $udir['baseurl'] . "/wpsc/category_images/".$mv['meta_value'];
1493 self::$export_instance->data[$termID]['category_image'] = $img_path;
1494 }else{
1495 self::$export_instance->data[$termID]['category_image'] = '';
1496 }
1497 }elseif($mv['meta_key'] == 'display_type'){
1498 self::$export_instance->data[$termID]['catelog_view'] = $mv['meta_value'];
1499 }elseif($mv['meta_key'] == 'uses_billing_address'){
1500 self::$export_instance->data[$termID]['address_calculate'] = $mv['meta_value']; }elseif($mv['meta_key'] == 'image_width'){
1501 self::$export_instance->data[$termID]['category_image_width'] = $mv['meta_value']; }elseif($mv['meta_key'] == 'image_height'){
1502 self::$export_instance->data[$termID]['category_image_height'] = $mv['meta_value']; }else{
1503 self::$export_instance->data[$termID][$mv['meta_key']] = $mv['meta_value'];
1504 }
1505 }
1506 }
1507 //wpsc_meta data ends
1508 //woocommerce meta data starts
1509 if(in_array('woocommerce/woocommerce.php', self::$export_instance->get_active_plugins())){
1510 if(isset($termMeta['thumbnail_id'][0])){
1511 $thum_id = $termMeta['thumbnail_id'][0];
1512 self::$export_instance->data[$termID]['image'] = self::$export_instance->getAttachment($thum_id);
1513 }
1514 if(!empty($termMeta['display_type'][0])){
1515 self::$export_instance->data[$termID]['display_type'] = $termMeta['display_type'][0];
1516 }
1517 if(!empty($termMeta['cat_meta'][0])){
1518 $cat_meta = unserialize($termMeta['cat_meta'][0]);
1519 self::$export_instance->data[$termID]['top_content'] = $cat_meta['cat_header'];
1520 self::$export_instance->data[$termID]['bottom_content'] = $cat_meta['cat_footer'];
1521 }
1522 }
1523 //woocommerce meta data ends
1524 $termName = $termValue->name;
1525 $termSlug = $termValue->slug;
1526 $termDesc = $termValue->description;
1527 $termParent = $termValue->parent;
1528 if($termParent == 0) {
1529 self::$export_instance->data[$termID]['name'] = $termName;
1530 } else {
1531 $termParentName = get_cat_name( $termParent );
1532 self::$export_instance->data[$termID]['name'] = $termParentName . '|' . $termName;
1533 }
1534 self::$export_instance->data[$termID]['slug'] = $termSlug;
1535 self::$export_instance->data[$termID]['description'] = $termDesc;
1536 self::$export_instance->data[$termID]['TERMID'] = $termID;
1537 self::$export_instance->data[$termID]['parent'] = $termParent;
1538 self::$export_instance->getWPMLData($termID,$optionalType,$module);
1539
1540 WooCommerceExport::$post_export->getPostsMetaDataBasedOnRecordId($termID, $module, $optionalType);
1541
1542 if(in_array('wordpress-seo/wp-seo.php', self::$export_instance->get_active_plugins())) {
1543 $seo_yoast_taxonomies = get_option( 'wpseo_taxonomy_meta' );
1544 if ( isset( $seo_yoast_taxonomies[$optionalType] ) ) {
1545 self::$export_instance->data[ $termID ]['title'] = $seo_yoast_taxonomies[$optionalType][$termID]['wpseo_title'];
1546 self::$export_instance->data[ $termID ]['meta_desc'] = $seo_yoast_taxonomies[$optionalType][$termID]['wpseo_desc'];
1547 self::$export_instance->data[ $termID ]['canonical'] = $seo_yoast_taxonomies[$optionalType][$termID]['wpseo_canonical'];
1548 self::$export_instance->data[ $termID ]['bctitle'] = $seo_yoast_taxonomies[$optionalType][$termID]['wpseo_bctitle'];
1549 self::$export_instance->data[ $termID ]['meta-robots-noindex'] = $seo_yoast_taxonomies[$optionalType][$termID]['wpseo_noindex'];
1550 self::$export_instance->data[ $termID ]['sitemap-include'] = $seo_yoast_taxonomies[$optionalType][$termID]['wpseo_sitemap_include'];
1551 self::$export_instance->data[ $termID ]['opengraph-title'] = $seo_yoast_taxonomies[$optionalType][$termID]['wpseo_opengraph-title'];
1552 self::$export_instance->data[ $termID ]['opengraph-description'] = $seo_yoast_taxonomies[$optionalType][$termID]['wpseo_opengraph-description'];
1553 self::$export_instance->data[ $termID ]['opengraph-image'] = $seo_yoast_taxonomies[$optionalType][$termID]['wpseo_opengraph-image'];
1554 self::$export_instance->data[ $termID ]['twitter-title'] = $seo_yoast_taxonomies[$optionalType][$termID]['wpseo_twitter-title'];
1555 self::$export_instance->data[ $termID ]['twitter-description'] = $seo_yoast_taxonomies[$optionalType][$termID]['wpseo_twitter-description'];
1556 self::$export_instance->data[ $termID ]['twitter-image'] = $seo_yoast_taxonomies[$optionalType][$termID]['wpseo_twitter-image'];
1557 self::$export_instance->data[ $termID ]['focus_keyword'] = $seo_yoast_taxonomies[$optionalType][$termID]['wpseo_focuskw'];
1558
1559 }
1560 }
1561 }
1562 }
1563
1564 $result = self::$export_instance->finalDataToExport(self::$export_instance->data , $module);
1565 if($mode == null)
1566 self::$export_instance->proceedExport($result);
1567 else
1568 return $result;
1569 }
1570
1571 public function getCourseData($id)
1572 {
1573 global $wpdb;
1574 $id = absint($id);
1575
1576 $get_section_details = $wpdb->get_results($wpdb->prepare("SELECT section_id, section_name, section_description FROM {$wpdb->prefix}learnpress_sections WHERE section_course_id = %d ", $id), ARRAY_A);
1577 $section_names = '';
1578 $section_descriptions = '';
1579 $get_lesson_name = '';
1580 $get_lesson_description = '';
1581 $get_lesson_duration = '';
1582 $get_lesson_preview = '';
1583 $get_quiz_name = '';
1584 $get_quiz_description = '';
1585 $get_quiz_meta = [];
1586
1587 foreach($get_section_details as $section_details){
1588 $section_names .= $section_details['section_name'] . '|';
1589 $section_descriptions .= $section_details['section_description'] . '|';
1590
1591 $section_id = absint($section_details['section_id']);
1592 $get_section_item_details = $wpdb->get_results($wpdb->prepare("SELECT item_id, item_type FROM {$wpdb->prefix}learnpress_section_items WHERE section_id = %d ", $section_id), ARRAY_A);
1593
1594 $lesson_name = '';
1595 $lesson_description = '';
1596 $quiz_name = '';
1597 $quiz_description = '';
1598 $lesson_duration = '';
1599 $lesson_preview = '';
1600 $quiz_metas = [];
1601
1602 foreach($get_section_item_details as $section_item_details){
1603 $section_item_id = absint($section_item_details['item_id']);
1604 if($section_item_details['item_type'] == 'lp_lesson'){
1605 $lesson_name .= $wpdb->get_var($wpdb->prepare("SELECT post_title FROM {$wpdb->prefix}posts WHERE ID = %d ", $section_item_id)) . ', ';
1606 $lesson_description .= $wpdb->get_var($wpdb->prepare("SELECT post_content FROM {$wpdb->prefix}posts WHERE ID = %d ", $section_item_id)). ', ';
1607 $lesson_duration .= $wpdb->get_var($wpdb->prepare("SELECT meta_value FROM {$wpdb->prefix}postmeta WHERE post_id = %d AND meta_key = '_lp_duration' ", $section_item_id)) . ', ';
1608 $lesson_preview .= $wpdb->get_var($wpdb->prepare("SELECT meta_value FROM {$wpdb->prefix}postmeta WHERE post_id = %d AND meta_key = '_lp_preview' ", $section_item_id)) . ', ';
1609 }
1610 elseif($section_item_details['item_type'] == 'lp_quiz'){
1611 $quiz_name .= $wpdb->get_var($wpdb->prepare("SELECT post_title FROM {$wpdb->prefix}posts WHERE ID = %d ", $section_item_id)) . ', ';
1612 $quiz_description .= $wpdb->get_var($wpdb->prepare("SELECT post_content FROM {$wpdb->prefix}posts WHERE ID = %d ", $section_item_id)). ', ';
1613
1614 $quiz_meta = $wpdb->get_results($wpdb->prepare("SELECT meta_key, meta_value FROM {$wpdb->prefix}postmeta WHERE post_id = %d AND meta_key LIKE '_lp_%%' ", $section_item_id), ARRAY_A);
1615 foreach($quiz_meta as $quiz_meta_values){
1616 $quiz_key = $quiz_meta_values['meta_key'];
1617 $quiz_value = $quiz_meta_values['meta_value'] . ', ';
1618
1619 if($quiz_key != '_lp_hidden_questions'){
1620 if($quiz_key == '_lp_retake_count'){
1621 $quiz_key = '_lp_quiz_retake_count';
1622 }
1623 $quiz_metas[$quiz_key] = $quiz_value;
1624 }
1625 }
1626 }
1627 }
1628
1629 $get_lesson_name .= rtrim($lesson_name, ', ') . '|';
1630 $get_lesson_description .= rtrim($lesson_description, ', ') . '|';
1631 $get_quiz_name .= rtrim($quiz_name, ', ') . '|';
1632 $get_quiz_description .= rtrim($quiz_description, ', ') . '|';
1633 $get_lesson_duration .= rtrim($lesson_duration, ', ') . '|';
1634 $get_lesson_preview .= rtrim($lesson_preview, ', ') . '|';
1635
1636 foreach($quiz_metas as $quiz_meta_keys => $quiz_meta_values){
1637 $get_quiz_meta[$quiz_meta_keys] = rtrim($quiz_meta_values, ', ') . '|';
1638 }
1639 }
1640
1641 WooCommerceExport::$export_instance->data[$id]['curriculum_name'] = rtrim($section_names, '|');
1642 WooCommerceExport::$export_instance->data[$id]['curriculum_description'] = rtrim($section_descriptions, '|');
1643 WooCommerceExport::$export_instance->data[$id]['lesson_name'] = rtrim($get_lesson_name, '|');
1644 WooCommerceExport::$export_instance->data[$id]['lesson_description'] = rtrim($get_lesson_description, '|');
1645 WooCommerceExport::$export_instance->data[$id]['quiz_name'] = rtrim($get_quiz_name, '|');
1646 WooCommerceExport::$export_instance->data[$id]['quiz_description'] = rtrim($get_quiz_description, '|');
1647 WooCommerceExport::$export_instance->data[$id]['_lp_lesson_duration'] = rtrim($get_lesson_duration, '|');
1648 WooCommerceExport::$export_instance->data[$id]['_lp_preview'] = rtrim($get_lesson_preview, '|');
1649
1650 foreach($get_quiz_meta as $get_quiz_meta_keys => $get_quiz_meta_values){
1651 WooCommerceExport::$export_instance->data[$id][$get_quiz_meta_keys] = rtrim($get_quiz_meta_values, '|');
1652 }
1653 }
1654
1655 public function getLessonData($id){
1656 global $wpdb;
1657 $id = absint($id);
1658 $lesson_duration = $wpdb->get_var($wpdb->prepare("SELECT meta_value FROM {$wpdb->prefix}postmeta WHERE post_id = %d AND meta_key = '_lp_duration' ", $id));
1659 WooCommerceExport::$export_instance->data[$id]['_lp_lesson_duration'] = $lesson_duration;
1660
1661 $get_section_id = $wpdb->get_var($wpdb->prepare("SELECT section_id FROM {$wpdb->prefix}learnpress_section_items WHERE item_id = %d AND item_type = 'lp_lesson' ", $id));
1662 if(!empty($get_section_id)){
1663 $get_section_id = absint($get_section_id);
1664 $get_section_name = $wpdb->get_var($wpdb->prepare("SELECT section_name FROM {$wpdb->prefix}learnpress_sections WHERE section_id = %d ", $get_section_id));
1665 $get_section_course_id = $wpdb->get_var($wpdb->prepare("SELECT section_course_id FROM {$wpdb->prefix}learnpress_sections WHERE section_id = %d ", $get_section_id));
1666
1667 WooCommerceExport::$export_instance->data[$id]['curriculum_name'] = $get_section_name;
1668 WooCommerceExport::$export_instance->data[$id]['course_id'] = $get_section_course_id;
1669 }
1670 }
1671
1672 public function getQuizData($id){
1673 global $wpdb;
1674 $id = absint($id);
1675 $quiz_retake_count = $wpdb->get_var($wpdb->prepare("SELECT meta_value FROM {$wpdb->prefix}postmeta WHERE post_id = %d AND meta_key = '_lp_retake_count' ", $id));
1676 WooCommerceExport::$export_instance->data[$id]['_lp_quiz_retake_count'] = $quiz_retake_count;
1677
1678 $get_section_id = $wpdb->get_var($wpdb->prepare("SELECT section_id FROM {$wpdb->prefix}learnpress_section_items WHERE item_id = %d AND item_type = 'lp_quiz' ", $id));
1679 if(!empty($get_section_id)){
1680 $get_section_id = absint($get_section_id);
1681 $get_section_name = $wpdb->get_var($wpdb->prepare("SELECT section_name FROM {$wpdb->prefix}learnpress_sections WHERE section_id = %d ", $get_section_id));
1682 $get_section_course_id = $wpdb->get_var($wpdb->prepare("SELECT section_course_id FROM {$wpdb->prefix}learnpress_sections WHERE section_id = %d ", $get_section_id));
1683
1684 WooCommerceExport::$export_instance->data[$id]['curriculum_name'] = $get_section_name;
1685 WooCommerceExport::$export_instance->data[$id]['course_id'] = $get_section_course_id;
1686 }
1687
1688 $get_question_title = '';
1689 $get_question_content = '';
1690 $get_question_mark = '';
1691 $get_question_explanation = '';
1692 $get_question_hint = '';
1693 $get_question_type = '';
1694 $get_option_value = '';
1695
1696 $get_question_ids = $wpdb->get_results($wpdb->prepare("SELECT question_id FROM {$wpdb->prefix}learnpress_quiz_questions WHERE quiz_id = %d ", $id), ARRAY_A);
1697 foreach($get_question_ids as $question_ids){
1698 $question_id = absint($question_ids['question_id']);
1699 $get_question_title .= $wpdb->get_var($wpdb->prepare("SELECT post_title FROM {$wpdb->prefix}posts WHERE ID = %d ", $question_id)) . ',';
1700 $get_question_content .= $wpdb->get_var($wpdb->prepare("SELECT post_content FROM {$wpdb->prefix}posts WHERE ID = %d ", $question_id)) . ',';
1701
1702 $get_question_mark .= $wpdb->get_var($wpdb->prepare("SELECT meta_value FROM {$wpdb->prefix}postmeta WHERE post_id = %d AND meta_key = '_lp_mark' ", $question_id)) . ', ';
1703 $get_question_explanation .= $wpdb->get_var($wpdb->prepare("SELECT meta_value FROM {$wpdb->prefix}postmeta WHERE post_id = %d AND meta_key = '_lp_explanation' ", $question_id)) . ',';
1704 $get_question_hint .= $wpdb->get_var($wpdb->prepare("SELECT meta_value FROM {$wpdb->prefix}postmeta WHERE post_id = %d AND meta_key = '_lp_hint' ", $question_id)) . ',';
1705 $get_question_type .= $wpdb->get_var($wpdb->prepare("SELECT meta_value FROM {$wpdb->prefix}postmeta WHERE post_id = %d AND meta_key = '_lp_type' ", $question_id)) . ',';
1706
1707 $get_question_options = $wpdb->get_results($wpdb->prepare("SELECT * FROM {$wpdb->prefix}learnpress_question_answers WHERE question_id = %d ", $question_id), ARRAY_A);
1708 $option_value = '';
1709 foreach($get_question_options as $question_option){
1710 if(empty($question_option['is_true'])){
1711 $question_option['is_true'] = 'no';
1712 }
1713
1714 $option_value .= $question_option['title'] .'|'. $question_option['is_true'] . '->';
1715 }
1716 $get_option_value .= rtrim($option_value, '->') . ',';
1717 }
1718
1719 WooCommerceExport::$export_instance->data[$id]['question_title'] = rtrim($get_question_title, ',');
1720 WooCommerceExport::$export_instance->data[$id]['question_description'] = rtrim($get_question_content, ',');
1721 WooCommerceExport::$export_instance->data[$id]['_lp_mark'] = rtrim($get_question_mark, ', ');
1722 WooCommerceExport::$export_instance->data[$id]['_lp_explanation'] = rtrim($get_question_explanation, ',');
1723 WooCommerceExport::$export_instance->data[$id]['_lp_hint'] = rtrim($get_question_hint, ',');
1724 WooCommerceExport::$export_instance->data[$id]['_lp_type'] = rtrim($get_question_type, ',');
1725 WooCommerceExport::$export_instance->data[$id]['question_options'] = rtrim($get_option_value, ',');
1726
1727 }
1728
1729 public function getQuestionData($id){
1730 global $wpdb;
1731 $id = absint($id);
1732 $get_quiz_id = $wpdb->get_var($wpdb->prepare("SELECT quiz_id FROM {$wpdb->prefix}learnpress_quiz_questions WHERE question_id = %d ", $id));
1733
1734 $get_question_options = $wpdb->get_results($wpdb->prepare("SELECT * FROM {$wpdb->prefix}learnpress_question_answers WHERE question_id = %d ", $id), ARRAY_A);
1735 $option_value = '';
1736 foreach($get_question_options as $question_options){
1737 if(empty($question_options['is_true'])){
1738 $question_options['is_true'] = 'no';
1739 }
1740 $option_value .= $question_options['title'] .'|'. $question_options['is_true'] . '->';
1741 }
1742
1743 if(!empty($get_quiz_id)){
1744 $get_quiz_id = absint($get_quiz_id);
1745 $get_section_id = $wpdb->get_var($wpdb->prepare("SELECT section_id FROM {$wpdb->prefix}learnpress_section_items WHERE item_id = %d AND item_type = 'lp_quiz' ", $get_quiz_id));
1746 if(!empty($get_section_id)){
1747 $get_section_id = absint($get_section_id);
1748 $get_section_name = $wpdb->get_var($wpdb->prepare("SELECT section_name FROM {$wpdb->prefix}learnpress_sections WHERE section_id = %d ", $get_section_id));
1749 $get_section_course_id = $wpdb->get_var($wpdb->prepare("SELECT section_course_id FROM {$wpdb->prefix}learnpress_sections WHERE section_id = %d ", $get_section_id));
1750
1751 WooCommerceExport::$export_instance->data[$id]['curriculum_name'] = $get_section_name;
1752 WooCommerceExport::$export_instance->data[$id]['course_id'] = $get_section_course_id;
1753 }
1754 WooCommerceExport::$export_instance->data[$id]['quiz_id'] = $get_quiz_id;
1755 }
1756
1757 WooCommerceExport::$export_instance->data[$id]['question_options'] = rtrim($option_value, '->');
1758 }
1759
1760 public function getOrderData($id){
1761 global $wpdb;
1762 $id = absint($id);
1763
1764 $order_status = $wpdb->get_var($wpdb->prepare("SELECT post_status FROM {$wpdb->prefix}posts WHERE ID = %d ", $id));
1765 $order_date = $wpdb->get_var($wpdb->prepare("SELECT post_date FROM {$wpdb->prefix}posts WHERE ID = %d ", $id));
1766 $order_total = $wpdb->get_var($wpdb->prepare("SELECT meta_value FROM {$wpdb->prefix}postmeta WHERE post_id = %d AND meta_key = '_order_total' ", $id));
1767 $order_subtotal = $wpdb->get_var($wpdb->prepare("SELECT meta_value FROM {$wpdb->prefix}postmeta WHERE post_id = %d AND meta_key = '_order_subtotal' ", $id));
1768 $user_id = $wpdb->get_var($wpdb->prepare("SELECT meta_value FROM {$wpdb->prefix}postmeta WHERE post_id = %d AND meta_key = '_user_id' ", $id));
1769
1770 $get_order_items = $wpdb->get_results($wpdb->prepare("SELECT order_item_id FROM {$wpdb->prefix}learnpress_order_items WHERE order_id = %d ", $id),ARRAY_A);
1771 $course_id = '';
1772 $item_quantity = '';
1773 $item_total = '';
1774 $item_subtotal = '';
1775 foreach($get_order_items as $get_order_values){
1776 $order_item_id = absint($get_order_values['order_item_id']);
1777
1778 $course_id .= $wpdb->get_var($wpdb->prepare("SELECT meta_value FROM {$wpdb->prefix}learnpress_order_itemmeta WHERE learnpress_order_item_id = %d AND meta_key = '_course_id' ", $order_item_id)) . ', ';
1779 $item_quantity .= $wpdb->get_var($wpdb->prepare("SELECT meta_value FROM {$wpdb->prefix}learnpress_order_itemmeta WHERE learnpress_order_item_id = %d AND meta_key = '_quantity' ", $order_item_id)) . ', ';
1780 $item_total .= $wpdb->get_var($wpdb->prepare("SELECT meta_value FROM {$wpdb->prefix}learnpress_order_itemmeta WHERE learnpress_order_item_id = %d AND meta_key = '_subtotal' ", $order_item_id)) . ', ';
1781 $item_subtotal .= $wpdb->get_var($wpdb->prepare("SELECT meta_value FROM {$wpdb->prefix}learnpress_order_itemmeta WHERE learnpress_order_item_id = %d AND meta_key = '_total' ", $order_item_id)) . ', ';
1782 }
1783
1784 WooCommerceExport::$export_instance->data[$id]['order_status'] = $order_status;
1785 WooCommerceExport::$export_instance->data[$id]['order_date'] = $order_date;
1786 WooCommerceExport::$export_instance->data[$id]['_order_total'] = $order_total;
1787 WooCommerceExport::$export_instance->data[$id]['_order_subtotal'] = $order_subtotal;
1788 WooCommerceExport::$export_instance->data[$id]['user_id'] = $user_id;
1789 WooCommerceExport::$export_instance->data[$id]['item_id'] = rtrim($course_id, ', ');
1790 WooCommerceExport::$export_instance->data[$id]['item_quantity'] = rtrim($item_quantity, ', ');
1791 WooCommerceExport::$export_instance->data[$id]['_item_total'] = rtrim($item_total, ', ');
1792 WooCommerceExport::$export_instance->data[$id]['_item_subtotal'] = rtrim($item_subtotal, ', ');
1793 }
1794
1795 public function elementor_export($id){
1796 $elementorExport = new ElementorExport;
1797 $variable= $elementorExport->templateExport();
1798 if(!empty($variable)){
1799 foreach($variable as $key=>$value){
1800 if ($value['ID'] == $id) {
1801 WooCommerceExport::$export_instance->data[$id]['ID'] = $id;
1802 WooCommerceExport::$export_instance->data[$id]['Template title'] = $value['Template title'];
1803 WooCommerceExport::$export_instance->data[$id]['Template content'] = $value['Template content'];
1804 WooCommerceExport::$export_instance->data[$id]['Style'] = $value['Style'];
1805 WooCommerceExport::$export_instance->data[$id]['Template type'] = $value['Template type'];
1806 WooCommerceExport::$export_instance->data[$id]['Created time'] = $value['Created time'];
1807 WooCommerceExport::$export_instance->data[$id]['Created by'] = $value['Created by'];
1808 WooCommerceExport::$export_instance->data[$id]['Template status'] = $value['Template status'];
1809 WooCommerceExport::$export_instance->data[$id]['Category'] = $value['Category'];
1810 }
1811 }
1812 }
1813 }
1814
1815 public function getCourseDataMasterLMS($id) {
1816 global $wpdb;
1817
1818 $get_item_details = $wpdb->get_results("SELECT item_id, item_title
1819 FROM {$wpdb->prefix}stm_lms_curriculum_log WHERE course_id = $id", ARRAY_A);
1820
1821
1822 $curicullam = $wpdb->get_var("SELECT meta_value FROM {$wpdb->prefix}postmeta WHERE post_id = $id and meta_key='curriculum' ");
1823 $curicullam_array = explode(',', $curicullam);
1824 foreach ($curicullam_array as &$value) {
1825 if (ctype_digit($value)) {
1826 $value = '';
1827 }
1828 }
1829 $curicullam = implode(',', $curicullam_array);
1830 $curicullam = trim($curicullam, ',');
1831 $curicullam_withoutId = preg_replace('/,{2,}/', ',', $curicullam);
1832
1833 $faq = $wpdb->get_var("SELECT meta_value FROM {$wpdb->prefix}postmeta WHERE post_id = $id and meta_key='faq' ");
1834 $faq_array = json_decode($faq, true);
1835 $faq_output = '';
1836 foreach ($faq_array as $faq_item) {
1837 $faq_output .= 'question:' . $faq_item['question'] . ',answer:' . $faq_item['answer'] . ' | ';
1838 }
1839 $faq_output = rtrim($faq_output, ' | ');
1840
1841
1842 $course_files_pack = $wpdb->get_var("SELECT meta_value FROM {$wpdb->prefix}postmeta WHERE post_id = $id and meta_key='course_files_pack' ");
1843 $course_files_pack_array = json_decode($course_files_pack, true);
1844 $course_files_pack_output = '';
1845 foreach ($course_files_pack_array as $course_files_pack_item) {
1846 $course_files_pack_output .= 'course_files_label:' . $course_files_pack_item['course_files_label'];
1847 }
1848 $status_dates = $wpdb->get_var("SELECT meta_value FROM {$wpdb->prefix}postmeta WHERE post_id = $id and meta_key='status_dates' ");
1849 $status_dates_start = $wpdb->get_var("SELECT meta_value FROM {$wpdb->prefix}postmeta WHERE post_id = $id and meta_key='status_dates_start' ");
1850 $views = $wpdb->get_var("SELECT meta_value FROM {$wpdb->prefix}postmeta WHERE post_id = $id and meta_key='views'");
1851 $duration_info = $wpdb->get_var("SELECT meta_value FROM {$wpdb->prefix}postmeta WHERE post_id = $id and meta_key='duration_info'");
1852 $featured = $wpdb->get_var("SELECT meta_value FROM {$wpdb->prefix}postmeta WHERE post_id = $id and meta_key='featured'");
1853 $level = $wpdb->get_var("SELECT meta_value FROM {$wpdb->prefix}postmeta WHERE post_id = $id and meta_key='level'");
1854 $current_students = $wpdb->get_var("SELECT meta_value FROM {$wpdb->prefix}postmeta WHERE post_id = $id and meta_key='current_students'");
1855 $video_duration = $wpdb->get_var("SELECT meta_value FROM {$wpdb->prefix}postmeta WHERE post_id = $id and meta_key='video_duration'");
1856 $price = $wpdb->get_var("SELECT meta_value FROM {$wpdb->prefix}postmeta WHERE post_id = $id and meta_key='price'");
1857 $sale_price = $wpdb->get_var("SELECT meta_value FROM {$wpdb->prefix}postmeta WHERE post_id = $id and meta_key='sale_price'");
1858 $status = $wpdb->get_var("SELECT meta_value FROM {$wpdb->prefix}postmeta WHERE post_id = $id and meta_key='status'");
1859 $expiration_course = $wpdb->get_var("SELECT meta_value FROM {$wpdb->prefix}postmeta WHERE post_id = $id and meta_key='expiration_course'");
1860 $not_membership = $wpdb->get_var("SELECT meta_value FROM {$wpdb->prefix}postmeta WHERE post_id = $id and meta_key='not_membership'");
1861 $end_time = $wpdb->get_var("SELECT meta_value FROM {$wpdb->prefix}postmeta WHERE post_id = $id and meta_key='end_time'");
1862 $announcement = $wpdb->get_var("SELECT meta_value FROM {$wpdb->prefix}postmeta WHERE post_id = $id and meta_key='announcement'");
1863 $course_files_pack = $wpdb->get_var("SELECT meta_value FROM {$wpdb->prefix}postmeta WHERE post_id = $id and meta_key='course_files_pack'");
1864 $status_dates_end = $wpdb->get_var("SELECT meta_value FROM {$wpdb->prefix}postmeta WHERE post_id = $id and meta_key='status_dates_end' ");
1865 $status_dates_start = date('Y-m-d', $status_dates_start/1000);
1866 $status_dates_end = date('Y-m-d', $status_dates_end/1000);
1867 $status_dates_array = explode(',', $status_dates);
1868 $status_dates_formatted = array();
1869
1870 foreach ($status_dates_array as $date) {
1871 $status_dates_formatted[] = date('Y-m-d', $date/1000);
1872 }
1873
1874 $status_dates_formatted_str = implode(',', $status_dates_formatted);
1875
1876 $get_lesson_id = '';
1877 $get_lesson_name = '';
1878 $get_quiz_id = '';
1879 $get_quiz_name = '';
1880
1881 foreach ($get_item_details as $item_details) {
1882 $item_id = $item_details['item_id'];
1883
1884 $lesson_id = '';
1885 $lesson_name = '';
1886 $quiz_id = '';
1887 $quiz_name = '';
1888
1889 $get_section_item_details = $wpdb->get_results("SELECT distinct item_id, item_type FROM {$wpdb->prefix}stm_lms_curriculum_log WHERE item_id = $item_id ", ARRAY_A);
1890
1891 foreach ($get_section_item_details as $section_item_details) {
1892 if ($section_item_details['item_type'] == 'stm-lessons') {
1893 $lesson_id .= $item_id . ', ';
1894 $lesson_name .= $wpdb->get_var("SELECT distinct post_title FROM {$wpdb->prefix}posts WHERE ID = $item_id ") . ',';
1895 } else if ($section_item_details['item_type'] == 'stm-quizzes') {
1896 $quiz_id .= $item_id . ', ';
1897 $quiz_name .= $wpdb->get_var("SELECT distinct post_title FROM {$wpdb->prefix}posts WHERE ID = $item_id ") . ',';
1898 }
1899 }
1900
1901 $get_lesson_id .= rtrim($lesson_id, ', ') . '|';
1902 $get_lesson_name .= rtrim($lesson_name, ',') . '|';
1903 $get_quiz_id .= rtrim($quiz_id, ', ') . '|';
1904 $get_quiz_name .= rtrim($quiz_name, ',') . '|';
1905
1906 $get_lesson_id = str_replace('||', '|', $get_lesson_id);
1907 $get_lesson_name = str_replace('||', '|', $get_lesson_name);
1908 $get_quiz_id = str_replace('||', '|', $get_quiz_id);
1909 $get_quiz_name = str_replace('||', '|', $get_quiz_name);
1910 }
1911
1912 WooCommerceExport::$export_instance->data[$id]['lesson_id'] = $get_lesson_id;
1913 WooCommerceExport::$export_instance->data[$id]['lesson_name'] = $get_lesson_name;
1914 WooCommerceExport::$export_instance->data[$id]['quiz_id'] = $get_quiz_id;
1915 WooCommerceExport::$export_instance->data[$id]['quiz_name'] = $get_quiz_name;
1916 WooCommerceExport::$export_instance->data[$id]['status_dates'] = $status_dates_formatted_str;
1917 WooCommerceExport::$export_instance->data[$id]['status_dates_start'] = $status_dates_start;
1918 WooCommerceExport::$export_instance->data[$id]['status_dates_end'] = $status_dates_end;
1919 WooCommerceExport::$export_instance->data[$id]['curriculum'] = $curicullam_withoutId;
1920 WooCommerceExport::$export_instance->data[$id]['video_duration'] = $video_duration;
1921 WooCommerceExport::$export_instance->data[$id]['views'] = $views;
1922 WooCommerceExport::$export_instance->data[$id]['price'] = $price;
1923 WooCommerceExport::$export_instance->data[$id]['sale_price'] = $sale_price;
1924 WooCommerceExport::$export_instance->data[$id]['status'] = $status;
1925 WooCommerceExport::$export_instance->data[$id]['expiration_course'] = $expiration_course;
1926 WooCommerceExport::$export_instance->data[$id]['not_membership'] = $not_membership;
1927 WooCommerceExport::$export_instance->data[$id]['end_time'] = $end_time;
1928 WooCommerceExport::$export_instance->data[$id]['announcement'] = $announcement;
1929 WooCommerceExport::$export_instance->data[$id]['course_files_pack'] = $course_files_pack;
1930 WooCommerceExport::$export_instance->data[$id]['duration_info'] = $duration_info;
1931 WooCommerceExport::$export_instance->data[$id]['featured'] = $featured;
1932 WooCommerceExport::$export_instance->data[$id]['level'] = $level;
1933 WooCommerceExport::$export_instance->data[$id]['current_students'] = $current_students;
1934 WooCommerceExport::$export_instance->data[$id]['faq'] = $faq_output;
1935 WooCommerceExport::$export_instance->data[$id]['course_files_pack'] = $course_files_pack_output;
1936
1937 }
1938
1939 public function getQuestionDataMasterLMS($id) {
1940
1941 global $wpdb;
1942 $type = $wpdb->get_var("SELECT meta_value FROM {$wpdb->prefix}postmeta WHERE post_id = $id and meta_key='type' ");
1943 $answers = $wpdb->get_var("SELECT meta_value FROM {$wpdb->prefix}postmeta WHERE post_id = $id and meta_key='answers' ");
1944 $question_explanation = $wpdb->get_var("SELECT meta_value FROM {$wpdb->prefix}postmeta WHERE post_id = $id and meta_key='question_explanation' ");
1945 $question = $wpdb->get_var("SELECT meta_value FROM {$wpdb->prefix}postmeta WHERE post_id = $id and meta_key='question' ");
1946 $question_hint = $wpdb->get_var("SELECT meta_value FROM {$wpdb->prefix}postmeta WHERE post_id = $id and meta_key='question_hint' ");
1947 $question_view_type = $wpdb->get_var("SELECT meta_value FROM {$wpdb->prefix}postmeta WHERE post_id = $id and meta_key='question_view_type' ");
1948 $image = $wpdb->get_var("SELECT meta_value FROM {$wpdb->prefix}postmeta WHERE post_id = $id and meta_key='image' ");
1949 $answers = unserialize($answers);
1950 $answers_string = '';
1951 foreach ($answers as $answer) {
1952 $answers_string .= $answer['text'] . ',' . $answer['isTrue'] . '|';
1953 }
1954
1955 WooCommerceExport::$export_instance->data[$id]['type'] = $type;
1956 WooCommerceExport::$export_instance->data[$id]['answers'] = rtrim($answers_string);
1957 WooCommerceExport::$export_instance->data[$id]['question_explanation'] = $question_explanation;
1958 WooCommerceExport::$export_instance->data[$id]['question'] = $question;
1959 WooCommerceExport::$export_instance->data[$id]['question_hint'] = $question_hint;
1960 WooCommerceExport::$export_instance->data[$id]['question_view_type'] = $question_view_type;
1961 WooCommerceExport::$export_instance->data[$id]['image'] = $image;
1962 }
1963 public function orderDataMasterLMS($id) {
1964 global $wpdb;
1965 $status = $wpdb->get_var("SELECT meta_value FROM {$wpdb->prefix}postmeta WHERE post_id = $id and meta_key='status' ");
1966
1967 WooCommerceExport::$export_instance->data[$id]['status'] = $status;
1968 }
1969 public function quizzDataMasterLMS($id) {
1970 global $wpdb;
1971 $duration = $wpdb->get_var("SELECT meta_value FROM {$wpdb->prefix}postmeta WHERE post_id = $id and meta_key='duration' ");
1972 $thumbnail_id = $wpdb->get_var("SELECT meta_value FROM {$wpdb->prefix}postmeta WHERE post_id = $id and meta_key='thumbnail_id' ");
1973 $lesson_excerpt = $wpdb->get_var("SELECT meta_value FROM {$wpdb->prefix}postmeta WHERE post_id = $id and meta_key='lesson_excerpt' ");
1974 $quiz_style = $wpdb->get_var("SELECT meta_value FROM {$wpdb->prefix}postmeta WHERE post_id = $id and meta_key='quiz_style' ");
1975 $correct_answer = $wpdb->get_var("SELECT meta_value FROM {$wpdb->prefix}postmeta WHERE post_id = $id and meta_key='correct_answer' ");
1976 $passing_grade = $wpdb->get_var("SELECT meta_value FROM {$wpdb->prefix}postmeta WHERE post_id = $id and meta_key='passing_grade' ");
1977 $re_take_cut = $wpdb->get_var("SELECT meta_value FROM {$wpdb->prefix}postmeta WHERE post_id = $id and meta_key='re_take_cut' ");
1978 $random_questions = $wpdb->get_var("SELECT meta_value FROM {$wpdb->prefix}postmeta WHERE post_id = $id and meta_key='random_questions' ");
1979 $questions = $wpdb->get_var("SELECT meta_value FROM {$wpdb->prefix}postmeta WHERE post_id = $id and meta_key='questions' ");
1980
1981 WooCommerceExport::$export_instance->data[$id]['duration'] = $duration;
1982 WooCommerceExport::$export_instance->data[$id]['thumbnail_id'] = $thumbnail_id;
1983 WooCommerceExport::$export_instance->data[$id]['lesson_excerpt'] = $lesson_excerpt;
1984 WooCommerceExport::$export_instance->data[$id]['quiz_style'] = $quiz_style;
1985 WooCommerceExport::$export_instance->data[$id]['correct_answer'] = $correct_answer;
1986 WooCommerceExport::$export_instance->data[$id]['passing_grade'] = $passing_grade;
1987 WooCommerceExport::$export_instance->data[$id]['re_take_cut'] = $re_take_cut;
1988 WooCommerceExport::$export_instance->data[$id]['random_questions'] = $random_questions;
1989 WooCommerceExport::$export_instance->data[$id]['questions'] = $questions;
1990 }
1991
1992 public function getLessonDataMasterLMS($id)
1993 {
1994 global $wpdb;
1995 $type = $wpdb->get_var("SELECT meta_value FROM {$wpdb->prefix}postmeta WHERE post_id = $id and meta_key='type'");
1996 $duration = $wpdb->get_var("SELECT meta_value FROM {$wpdb->prefix}postmeta WHERE post_id = $id and meta_key='duration' ");
1997 $preview = $wpdb->get_var("SELECT meta_value FROM {$wpdb->prefix}postmeta WHERE post_id = $id and meta_key='preview' ");
1998 $lesson_excerpt = $wpdb->get_var("SELECT meta_value FROM {$wpdb->prefix}postmeta WHERE post_id = $id and meta_key='lesson_excerpt' ");
1999 $_thumbnail_id = $wpdb->get_var("SELECT meta_value FROM {$wpdb->prefix}postmeta WHERE post_id = $id and meta_key='_thumbnail_id' ");
2000 $video_type = $wpdb->get_var("SELECT meta_value FROM {$wpdb->prefix}postmeta WHERE post_id = $id and meta_key='video_type' ");
2001 $lesson_youtube_url = $wpdb->get_var("SELECT meta_value FROM {$wpdb->prefix}postmeta WHERE post_id = $id and meta_key='lesson_youtube_url' ");
2002 $presto_player_idx = $wpdb->get_var("SELECT meta_value FROM {$wpdb->prefix}postmeta WHERE post_id = $id and meta_key='presto_player_idx' ");
2003 $lesson_video = $wpdb->get_var("SELECT meta_value FROM {$wpdb->prefix}postmeta WHERE post_id = $id and meta_key='lesson_video' ");
2004 $lesson_video_poster = $wpdb->get_var("SELECT meta_value FROM {$wpdb->prefix}postmeta WHERE post_id = $id and meta_key='lesson_video_poster' ");
2005 $lesson_video_width = $wpdb->get_var("SELECT meta_value FROM {$wpdb->prefix}postmeta WHERE post_id = $id and meta_key='lesson_video_width' ");
2006 $lesson_shortcode = $wpdb->get_var("SELECT meta_value FROM {$wpdb->prefix}postmeta WHERE post_id = $id and meta_key='lesson_shortcode' ");
2007 $lesson_embed_ctx = $wpdb->get_var("SELECT meta_value FROM {$wpdb->prefix}postmeta WHERE post_id = $id and meta_key='lesson_embed_ctx' ");
2008 $lesson_stream_url = $wpdb->get_var("SELECT meta_value FROM {$wpdb->prefix}postmeta WHERE post_id = $id and meta_key='lesson_stream_url' ");
2009 $lesson_vimeo_url = $wpdb->get_var("SELECT meta_value FROM {$wpdb->prefix}postmeta WHERE post_id = $id and meta_key='lesson_vimeo_url' ");
2010 $lesson_ext_link_url = $wpdb->get_var("SELECT meta_value FROM {$wpdb->prefix}postmeta WHERE post_id = $id and meta_key='lesson_ext_link_url' ");
2011 $lesson_files_pack = $wpdb->get_var("SELECT meta_value FROM {$wpdb->prefix}postmeta WHERE post_id = $id and meta_key='lesson_files_pack' ");
2012
2013 $lesson_files_pack_array = json_decode($lesson_files_pack, true);
2014 $lesson_files_pack_output = '';
2015 foreach ($lesson_files_pack_array as $lesson_files_pack_item) {
2016 if (!empty($lesson_files_pack_item['closed_tab'])) {
2017 $lesson_files_pack_output .= 'closed_tab:' . $lesson_files_pack_item['closed_tab'] . ',';
2018 }
2019 $lesson_files_pack_output .= 'lesson_files_label:' . $lesson_files_pack_item['lesson_files_label'] . ',';
2020 $lesson_files_pack_output = rtrim($lesson_files_pack_output, ','); }
2021
2022 WooCommerceExport::$export_instance->data[$id]['type'] = $type;
2023 WooCommerceExport::$export_instance->data[$id]['duration'] = $duration;
2024 WooCommerceExport::$export_instance->data[$id]['preview'] = $preview;
2025 WooCommerceExport::$export_instance->data[$id]['lesson_excerpt'] = $lesson_excerpt;
2026 WooCommerceExport::$export_instance->data[$id]['_thumbnail_id'] = $_thumbnail_id;
2027 WooCommerceExport::$export_instance->data[$id]['video_type'] = $video_type;
2028 WooCommerceExport::$export_instance->data[$id]['lesson_youtube_url'] = $lesson_youtube_url;
2029 WooCommerceExport::$export_instance->data[$id]['presto_player_idx'] = $presto_player_idx;
2030 WooCommerceExport::$export_instance->data[$id]['lesson_video'] = $lesson_video;
2031 WooCommerceExport::$export_instance->data[$id]['lesson_video_poster'] = $lesson_video_poster;
2032 WooCommerceExport::$export_instance->data[$id]['lesson_video_width'] = $lesson_video_width;
2033 WooCommerceExport::$export_instance->data[$id]['lesson_shortcode'] = $lesson_shortcode;
2034 WooCommerceExport::$export_instance->data[$id]['lesson_embed_ctx'] = $lesson_embed_ctx;
2035 WooCommerceExport::$export_instance->data[$id]['lesson_stream_url'] = $lesson_stream_url;
2036 WooCommerceExport::$export_instance->data[$id]['lesson_vimeo_url'] = $lesson_vimeo_url;
2037 WooCommerceExport::$export_instance->data[$id]['lesson_ext_link_url'] = $lesson_ext_link_url;
2038 WooCommerceExport::$export_instance->data[$id]['lesson_files_pack'] = $lesson_files_pack_output;
2039 }
2040
2041
2042 public function getMenuData($term_id){
2043 global $wpdb;
2044 $term_name = get_term( $term_id )->name;
2045 $get_object_ids = $wpdb->get_results("SELECT p.* FROM {$wpdb->prefix}posts AS p
2046 LEFT JOIN {$wpdb->prefix}term_relationships AS tr ON tr.object_id = p.ID
2047 LEFT JOIN {$wpdb->prefix}term_taxonomy AS tt ON tt.term_taxonomy_id = tr.term_taxonomy_id
2048 WHERE p.post_type = 'nav_menu_item'
2049 AND tt.term_id = $term_id ", ARRAY_A);
2050
2051 $menu_item_types = '';
2052 $menu_object_ids = '';
2053 $menu_objects = '';
2054 $menu_urls = '';
2055 foreach($get_object_ids as $object_ids){
2056 $object_id = $object_ids['ID'];
2057
2058 $get_object_meta = $wpdb->get_results("SELECT meta_key , meta_value FROM {$wpdb->prefix}postmeta WHERE post_id = $object_id", ARRAY_A);
2059 $object_meta_key = array_column($get_object_meta, 'meta_key');
2060 $object_meta_value = array_column($get_object_meta, 'meta_value');
2061 $object_array = array_combine($object_meta_key, $object_meta_value);
2062
2063 $menu_item_type = $object_array['_menu_item_type'];
2064 $menu_item_object = $object_array['_menu_item_object'];
2065 $menu_object_item_id = $object_array['_menu_item_object_id'];
2066
2067 if(($menu_item_type == 'post_type') && ($menu_item_object == 'post' || $menu_item_object == 'page')){
2068 $menu_object_item_title = $wpdb->get_var("SELECT post_title FROM {$wpdb->prefix}posts WHERE ID = $menu_object_item_id AND post_type = '$menu_item_object' ");
2069 }
2070 elseif($menu_item_type == 'custom' && $menu_item_object == 'custom'){
2071 $menu_object_item_title = $wpdb->get_var("SELECT post_title FROM {$wpdb->prefix}posts WHERE ID = $menu_object_item_id AND post_type = 'nav_menu_item' ");
2072 }
2073 elseif($menu_item_type == 'taxonomy'){
2074 $category_data = get_term_by('id', $menu_object_item_id, $menu_item_object);
2075 $menu_object_item_title = $category_data->name;
2076 }
2077 else{
2078 $menu_object_item_title = $menu_object_item_id;
2079 }
2080
2081 $menu_item_types .= $menu_item_type . ',';
2082 $menu_object_ids .= $menu_object_item_title . ',';
2083 $menu_objects .= $menu_item_object . ',';
2084 $menu_urls .= $object_array['_menu_item_url'] . ',';
2085 }
2086
2087 WooCommerceExport::$export_instance->data[$term_id]['menu_title'] = $term_name;
2088 WooCommerceExport::$export_instance->data[$term_id]['_menu_item_type'] = rtrim($menu_item_types, ',');
2089 WooCommerceExport::$export_instance->data[$term_id]['_menu_item_object_id'] = rtrim($menu_object_ids, ',');
2090 WooCommerceExport::$export_instance->data[$term_id]['_menu_item_object'] = rtrim($menu_objects, ',');
2091 WooCommerceExport::$export_instance->data[$term_id]['_menu_item_url'] = rtrim($menu_urls, ',');
2092
2093 $get_nav_options = get_option("nav_menu_options");
2094 if(!empty($get_nav_options['auto_add'])){
2095 if(in_array($term_id, $get_nav_options['auto_add'])){
2096 WooCommerceExport::$export_instance->data[$term_id]['menu_auto_add'] = 'yes';
2097 }else{
2098 WooCommerceExport::$export_instance->data[$term_id]['menu_auto_add'] = 'no';
2099 }
2100 }
2101 else{
2102 WooCommerceExport::$export_instance->data[$term_id]['menu_auto_add'] = 'no';
2103 }
2104
2105 $get_navigation_locations = get_nav_menu_locations();
2106 foreach($get_navigation_locations as $nav_keys => $nav_values){
2107 if($nav_values == $term_id){
2108 WooCommerceExport::$export_instance->data[$term_id][$nav_keys] = 'yes';
2109 }else{
2110 WooCommerceExport::$export_instance->data[$term_id][$nav_keys] = 'no';
2111 }
2112 }
2113 }
2114
2115 }
2116
2117 global $woocom_exp_class;
2118 //$woocom_exp_class = WooCommerceExport::getInstance();
2119 $woocom_exp_class = new WooCommerceExport();
2120