| 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 |
|
| 10 |
if ( ! defined( 'ABSPATH' ) ) |
| 11 |
exit; // Exit if accessed directly |
| 12 |
|
| 13 |
/** |
| 14 |
* Class WooCommerceExport |
| 15 |
* @package Smackcoders\WCSV |
| 16 |
*/ |
| 17 |
class WooCommerceExport extends ExportExtension{ |
| 18 |
|
| 19 |
protected static $instance = null,$mapping_instance,$export_handler,$export_instance,$post_export; |
| 20 |
private $offset = 0; |
| 21 |
public $limit = 1000; |
| 22 |
public $totalRowCount; |
| 23 |
public static function getInstance() { |
| 24 |
if ( null == self::$instance ) { |
| 25 |
self::$instance = new self; |
| 26 |
WooCommerceExport::$export_instance = ExportExtension::getInstance(); |
| 27 |
WooCommerceExport::$post_export = PostExport::getInstance(); |
| 28 |
} |
| 29 |
return self::$instance; |
| 30 |
} |
| 31 |
|
| 32 |
/** |
| 33 |
* WooCommerceExport constructor. |
| 34 |
*/ |
| 35 |
public function __construct() { |
| 36 |
$this->plugin = Plugin::getInstance(); |
| 37 |
} |
| 38 |
|
| 39 |
/** |
| 40 |
* Export woocommerce orders |
| 41 |
* @param $id |
| 42 |
* @param $type |
| 43 |
* @param $optional |
| 44 |
* @return bool |
| 45 |
*/ |
| 46 |
public function getWooComOrderData($id, $type, $optional) |
| 47 |
{ |
| 48 |
// return true; |
| 49 |
global $wpdb; |
| 50 |
$orderid = self::$export_instance->data[$id]['ID']; |
| 51 |
$table1 = $wpdb->prefix."woocommerce_order_items"; |
| 52 |
$table2 = $wpdb->prefix."woocommerce_order_itemmeta"; |
| 53 |
$query = $wpdb->prepare("SELECT * FROM $table1 where order_id = %d", $orderid); |
| 54 |
$result = $wpdb->get_results($query); |
| 55 |
$order_itemname = $order_itemtype = $product_id = $var_id = $line_subtotal = $line_subtotal_tax = $line_total_tax = $line_total = $line_tax_data = $qty = $tx_cls = ""; |
| 56 |
$feename = $feetype = $fee_subtotal = $fee_subtotal_tax = $fee_total_tax = $fee_total = $fee_tax_data = $fee_tx_cls = ""; |
| 57 |
$shipname = $method_id = $cost = $taxes = ""; |
| 58 |
if(!empty($result)){ |
| 59 |
foreach ($result as $key => $value) { |
| 60 |
$orderitem = $value->order_item_id; |
| 61 |
if($value->order_item_type != 'fee' && $value->order_item_type != 'shipping' && $value->order_item_type != ' fee'){ |
| 62 |
$order_itemname .= $value->order_item_name.','; |
| 63 |
$order_itemtype .= $value->order_item_type.','; |
| 64 |
} |
| 65 |
if($value->order_item_type == 'fee'){ |
| 66 |
$feename .= $value->order_item_name.','; |
| 67 |
$feetype .= $value->order_item_type.','; |
| 68 |
} |
| 69 |
if($value->order_item_type == 'shipping'){ |
| 70 |
$shipname .= $value->order_item_name.','; |
| 71 |
} |
| 72 |
$query2 = $wpdb->prepare("SELECT * FROM $table2 where order_item_id = %d", $orderitem); |
| 73 |
$result2 = $wpdb->get_results($query2); |
| 74 |
foreach ($result2 as $key2 => $value2) { |
| 75 |
if($value->order_item_type != 'fee' && $value->order_item_type != 'shipping' && $value->order_item_type != ' fee' ){ |
| 76 |
if($value2->meta_key == '_product_id'){ |
| 77 |
$product_id .= $value2->meta_value.','; |
| 78 |
} |
| 79 |
if($value2->meta_key == '_variation_id'){ |
| 80 |
$var_id .= $value2->meta_value.','; |
| 81 |
} |
| 82 |
if($value2->meta_key == '_line_subtotal'){ |
| 83 |
$line_subtotal .= $value2->meta_value.','; |
| 84 |
} |
| 85 |
if($value2->meta_key == '_line_subtotal_tax'){ |
| 86 |
$line_subtotal_tax .= $value2->meta_value.','; |
| 87 |
} |
| 88 |
if($value2->meta_key == '_line_total'){ |
| 89 |
$line_total .= $value2->meta_value.','; |
| 90 |
} |
| 91 |
if($value2->meta_key == '_line_tax'){ |
| 92 |
$line_total_tax .= $value2->meta_value.','; |
| 93 |
} |
| 94 |
if($value2->meta_key == '_line_tax_data'){ |
| 95 |
$line_tax_data .= $value2->meta_value.','; |
| 96 |
} |
| 97 |
if($value2->meta_key == '_qty'){ |
| 98 |
$qty .= $value2->meta_value.','; |
| 99 |
} |
| 100 |
if($value2->meta_key == '_tax_class'){ |
| 101 |
$tx_cls .= $value2->meta_value.','; |
| 102 |
} |
| 103 |
} |
| 104 |
if($value->order_item_type == 'fee'){ |
| 105 |
if($value2->meta_key == '_line_subtotal'){ |
| 106 |
$fee_subtotal .= $value2->meta_value.','; |
| 107 |
} |
| 108 |
if($value2->meta_key == '_line_subtotal_tax'){ |
| 109 |
$fee_subtotal_tax .= $value2->meta_value.','; |
| 110 |
} |
| 111 |
if($value2->meta_key == '_line_total'){ |
| 112 |
$fee_total .= $value2->meta_value.','; |
| 113 |
} |
| 114 |
if($value2->meta_key == '_line_tax'){ |
| 115 |
$fee_total_tax .= $value2->meta_value.','; |
| 116 |
} |
| 117 |
if($value2->meta_key == '_line_tax_data'){ |
| 118 |
$fee_tax_data .= $value2->meta_value.','; |
| 119 |
} |
| 120 |
if($value2->meta_key == '_tax_class'){ |
| 121 |
$fee_tx_cls .= $value2->meta_value.','; |
| 122 |
} |
| 123 |
} |
| 124 |
if($value->order_item_type == 'shipping'){ |
| 125 |
if($value2->meta_key == 'method_id'){ |
| 126 |
$method_id .= $value2->meta_value.','; |
| 127 |
} |
| 128 |
if($value2->meta_key == 'cost'){ |
| 129 |
$cost .= $value2->meta_value.','; |
| 130 |
} |
| 131 |
if($value2->meta_key == 'taxes'){ |
| 132 |
$taxes .= $value2->meta_value.','; |
| 133 |
} |
| 134 |
} |
| 135 |
} |
| 136 |
} |
| 137 |
} |
| 138 |
//itemdata |
| 139 |
self::$export_instance->data[$id]['item_name'] = substr($order_itemname, 0, -1); |
| 140 |
self::$export_instance->data[$id]['item_type'] = substr($order_itemtype, 0, -1); |
| 141 |
self::$export_instance->data[$id]['item_product_id'] = substr($product_id, 0, -1); |
| 142 |
self::$export_instance->data[$id]['item_variation_id'] = substr($var_id, 0, -1); |
| 143 |
self::$export_instance->data[$id]['item_line_subtotal'] = substr($line_subtotal, 0, -1); |
| 144 |
self::$export_instance->data[$id]['item_line_subtotal_tax'] = substr($line_subtotal_tax, 0, -1); |
| 145 |
self::$export_instance->data[$id]['item_line_total'] = substr($line_total, 0, -1); |
| 146 |
self::$export_instance->data[$id]['item_line_tax'] = substr($line_total_tax, 0, -1); |
| 147 |
self::$export_instance->data[$id]['item_line_tax_data'] = substr($line_tax_data, 0, -1); |
| 148 |
self::$export_instance->data[$id]['item_qty'] = substr($qty, 0, -1); |
| 149 |
self::$export_instance->data[$id]['item_tax_class'] = substr($tx_cls, 0, -1); |
| 150 |
//fee data |
| 151 |
self::$export_instance->data[$id]['fee_name'] = substr($feename, 0, -1); |
| 152 |
self::$export_instance->data[$id]['fee_type'] = substr($feetype, 0, -1); |
| 153 |
self::$export_instance->data[$id]['fee_line_subtotal'] = substr($fee_subtotal, 0, -1); |
| 154 |
self::$export_instance->data[$id]['fee_line_subtotal_tax'] = substr($fee_subtotal_tax, 0, -1); |
| 155 |
self::$export_instance->data[$id]['fee_line_total'] = substr($fee_total, 0, -1); |
| 156 |
self::$export_instance->data[$id]['fee_line_tax'] = substr($fee_total_tax, 0, -1); |
| 157 |
self::$export_instance->data[$id]['fee_line_tax_data'] = substr($fee_tax_data, 0, -1); |
| 158 |
self::$export_instance->data[$id]['fee_tax_class'] = substr($fee_tx_cls, 0, -1); |
| 159 |
// shipment data |
| 160 |
self::$export_instance->data[$id]['shipment_name'] = substr($shipname, 0, -1); |
| 161 |
self::$export_instance->data[$id]['shipment_method_id'] = substr($method_id, 0, -1); |
| 162 |
self::$export_instance->data[$id]['shipment_cost'] = substr($cost, 0, -1); |
| 163 |
self::$export_instance->data[$id]['shipment_taxes'] = substr($taxes, 0, -1); |
| 164 |
} |
| 165 |
|
| 166 |
/** |
| 167 |
* Code for Woocommerce Refund export |
| 168 |
* @param $id |
| 169 |
* @param $type |
| 170 |
* @param $optionalType |
| 171 |
*/ |
| 172 |
public function getWooComCustomerUser($id, $type, $optionalType) |
| 173 |
{ |
| 174 |
global $wpdb; |
| 175 |
$parent = WooCommerceExport::$export_instance->data[$id]['post_parent']; |
| 176 |
$query = $wpdb->prepare("SELECT post_id,meta_key,meta_value FROM {$wpdb->prefix}postmeta where post_id = %d", $parent); |
| 177 |
$result = $wpdb->get_results($query); |
| 178 |
if(!empty($result)){ |
| 179 |
foreach ($result as $key => $value) { |
| 180 |
if($value->meta_key == '_customer_user'){ |
| 181 |
$cus_user = $value->meta_value; |
| 182 |
} |
| 183 |
} |
| 184 |
} |
| 185 |
WooCommerceExport::$export_instance->data[$id]['customer_user'] = $cus_user; |
| 186 |
} |
| 187 |
|
| 188 |
/** |
| 189 |
* Export woocommerce product and variation |
| 190 |
* @param $id |
| 191 |
* @param $type |
| 192 |
* @param $optionalType |
| 193 |
*/ |
| 194 |
public function getProductData($id, $type, $optionalType) |
| 195 |
{ |
| 196 |
global $wpdb; |
| 197 |
|
| 198 |
$query = $wpdb->prepare("SELECT post_id,meta_key,meta_value FROM {$wpdb->prefix}postmeta where post_id = %d", $id); |
| 199 |
$result = $wpdb->get_results($query); |
| 200 |
|
| 201 |
$term_relationship_arr = []; |
| 202 |
$term_relationship = $wpdb->get_results("SELECT term_taxonomy_id FROM {$wpdb->prefix}term_relationships WHERE object_id = $id"); |
| 203 |
foreach($term_relationship as $relationship_value){ |
| 204 |
$term_relationship_arr[] = $relationship_value->term_taxonomy_id; |
| 205 |
} |
| 206 |
|
| 207 |
$attname = $attvalue = $attvisible = $attvar = $atttype = $attpos = ""; |
| 208 |
$attlabel = $atttaxo = ""; |
| 209 |
|
| 210 |
if(!empty($result)){ |
| 211 |
foreach ($result as $key => $value) { |
| 212 |
|
| 213 |
if($value->meta_key == '_product_attributes'){ |
| 214 |
$attArray = unserialize($value->meta_value); |
| 215 |
|
| 216 |
foreach ($attArray as $key1 => $value1) { |
| 217 |
|
| 218 |
$pa_value = get_term( $value1['name'] ); |
| 219 |
$result = $wpdb->get_results("SELECT term_id FROM {$wpdb->prefix}term_taxonomy where taxonomy = '{$value1['name']}'",ARRAY_A); |
| 220 |
$attvalues = $attrmeta = ''; |
| 221 |
foreach ($result as $key => $value) { |
| 222 |
$value = $value['term_id']; |
| 223 |
|
| 224 |
if(in_array($value , $term_relationship_arr)){ |
| 225 |
$querys = $wpdb->get_results("SELECT name FROM {$wpdb->prefix}terms where term_id =$value ",ARRAY_A); |
| 226 |
if(!empty($querys['0']['name'])){ |
| 227 |
$attvalues .= $querys['0']['name'].'|'; |
| 228 |
if (is_plugin_active('variation-swatches-for-woocommerce/variation-swatches-for-woocommerce.php')) { |
| 229 |
$term_meta_id = $wpdb->get_col($wpdb->prepare("select term_id from {$wpdb->prefix}terms where name = %s",$querys['0']['name'])); |
| 230 |
|
| 231 |
$attr_con = $wpdb->get_col($wpdb->prepare("select meta_value from {$wpdb->prefix}termmeta where term_id = %s GROUP BY meta_key HAVING meta_key NOT LIKE 'order_pa%' ",$term_meta_id[0])); |
| 232 |
$meta_value = $attr_con[0]; |
| 233 |
if(is_numeric($meta_value)){ |
| 234 |
$get_guid =$wpdb->get_results("select guid from {$wpdb->prefix}posts where ID= '$attr_con[0]'" ,ARRAY_A); |
| 235 |
$link =$get_guid[0]['guid']; |
| 236 |
if(!empty($link)){ |
| 237 |
$attrmeta .= $link.'|'; |
| 238 |
} |
| 239 |
else{ |
| 240 |
$attrmeta .= $attr_con[0].'|'; |
| 241 |
|
| 242 |
} |
| 243 |
} |
| 244 |
else{ |
| 245 |
$attrmeta .= $attr_con[0].'|'; |
| 246 |
} |
| 247 |
} |
| 248 |
} |
| 249 |
} |
| 250 |
} |
| 251 |
|
| 252 |
if(!empty($attvalues)){ |
| 253 |
if (is_plugin_active('variation-swatches-for-woocommerce/variation-swatches-for-woocommerce.php')) { |
| 254 |
$attvalue .= rtrim($attvalues , '|') . '>'. rtrim($attrmeta , '|'). ','; |
| 255 |
} |
| 256 |
else{ |
| 257 |
$attvalue .= rtrim($attvalues , '|') . ','; |
| 258 |
} |
| 259 |
} |
| 260 |
|
| 261 |
$get_all_taxonomies = $wpdb->get_results($query); |
| 262 |
|
| 263 |
$attriname = substr($value1['name'] , 3); |
| 264 |
$attr_name = $wpdb->get_var("SELECT attribute_label FROM {$wpdb->prefix}woocommerce_attribute_taxonomies WHERE attribute_name = '$attriname' "); |
| 265 |
|
| 266 |
$attname .= $attr_name.'|'; |
| 267 |
$attr_type = $wpdb->get_var("SELECT attribute_type FROM {$wpdb->prefix}woocommerce_attribute_taxonomies WHERE attribute_name = '$attriname' "); |
| 268 |
$atttype .= $attr_type.'|'; |
| 269 |
$attvisible .= $value1['is_visible'].'|'; |
| 270 |
$attvar .= $value1['is_variation'].'|'; |
| 271 |
$attpos .= $value1['position'].'|'; |
| 272 |
$atttaxo .= $value1['is_taxonomy'].'|'; |
| 273 |
|
| 274 |
$attlabel .= $value1['name'].'|'; |
| 275 |
} |
| 276 |
} |
| 277 |
if($value->meta_key == '_low_stock_amount'){ |
| 278 |
WooCommerceExport::$export_instance->data[$id]['low_stock_threshold'] = $value->meta_value; |
| 279 |
} |
| 280 |
if($value->meta_key == '_sku'){ |
| 281 |
WooCommerceExport::$export_instance->data[$id]['PARENTSKU'] = $value->meta_value; |
| 282 |
} |
| 283 |
if($value->meta_key == '_sku'){ |
| 284 |
WooCommerceExport::$export_instance->data[$id]['PARENTSKU'] = $value->meta_value; |
| 285 |
} |
| 286 |
if($value->meta_key == '_thumbnail_id'){ |
| 287 |
$get_attachment = $wpdb->prepare("select guid from {$wpdb->prefix}posts where ID = %d AND post_type = %s", $value->meta_value, 'attachment'); |
| 288 |
$attachment = $wpdb->get_results($get_attachment); |
| 289 |
$value->meta_value = $attachment[0]->guid; |
| 290 |
WooCommerceExport::$export_instance->data[$id]['thumbnail_id'] = $value->meta_value; |
| 291 |
} |
| 292 |
if($value->meta_key == '_stock'){ |
| 293 |
WooCommerceExport::$export_instance->data[$id]['stock_qty'] = $value->meta_value; |
| 294 |
} |
| 295 |
if($value->meta_key == '_regular_price'){ |
| 296 |
WooCommerceExport::$export_instance->data[$id]['regular_price'] = $value->meta_value; |
| 297 |
} |
| 298 |
if($value->meta_key == '_price'){ |
| 299 |
WooCommerceExport::$export_instance->data[$id]['price'] = $value->meta_value; |
| 300 |
} |
| 301 |
if($value->meta_key == '_sale_price'){ |
| 302 |
WooCommerceExport::$export_instance->data[$id]['sale_price'] = $value->meta_value; |
| 303 |
} |
| 304 |
if($value->meta_key == '_wc_pb_base_regular_price'){ |
| 305 |
WooCommerceExport::$export_instance->data[$id]['pb_regular_price'] = $value->meta_value; |
| 306 |
} |
| 307 |
if($value->meta_key == '_wc_pb_base_sale_price'){ |
| 308 |
WooCommerceExport::$export_instance->data[$id]['pb_sale_price'] = $value->meta_value; |
| 309 |
} |
| 310 |
if($value->meta_key == '_wc_pb_layout_style'){ |
| 311 |
$layout = $value->meta_value; |
| 312 |
if($layout == 'default'){ |
| 313 |
WooCommerceExport::$export_instance->data[$id]['layout'] = 'Standard'; |
| 314 |
}elseif($layout == 'tabular'){ |
| 315 |
WooCommerceExport::$export_instance->data[$id]['layout'] = 'Tabular'; |
| 316 |
}elseif($layout == 'grid'){ |
| 317 |
WooCommerceExport::$export_instance->data[$id]['layout'] = 'Grid'; |
| 318 |
} |
| 319 |
} |
| 320 |
if($value->meta_key == '_wc_pb_add_to_cart_form_location'){ |
| 321 |
$form_location = $value->meta_value; |
| 322 |
if($form_location == 'default'){ |
| 323 |
WooCommerceExport::$export_instance->data[$id]['form_location'] = 'Default'; |
| 324 |
}elseif($form_location == 'after_summary'){ |
| 325 |
WooCommerceExport::$export_instance->data[$id]['form_location'] = 'Before Tabs'; |
| 326 |
} |
| 327 |
} |
| 328 |
if($value->meta_key == '_wc_pb_group_mode'){ |
| 329 |
$group_mode = $value->meta_value; |
| 330 |
if($group_mode == 'parent'){ |
| 331 |
WooCommerceExport::$export_instance->data[$id]['item_grouping'] = 'Grouped'; |
| 332 |
}elseif($group_mode == 'noindent'){ |
| 333 |
WooCommerceExport::$export_instance->data[$id]['item_grouping'] = 'Flat'; |
| 334 |
}elseif($group_mode == 'none'){ |
| 335 |
WooCommerceExport::$export_instance->data[$id]['item_grouping'] = 'None'; |
| 336 |
} |
| 337 |
} |
| 338 |
if($value->meta_key == '_wc_pb_edit_in_cart'){ |
| 339 |
$edit_cart = $value->meta_value; |
| 340 |
if($edit_cart == 'yes'){ |
| 341 |
WooCommerceExport::$export_instance->data[$id]['edit_in_cart'] = 'Yes'; |
| 342 |
}elseif($edit_cart == 'no'){ |
| 343 |
WooCommerceExport::$export_instance->data[$id]['edit_in_cart'] = 'No'; |
| 344 |
} |
| 345 |
} |
| 346 |
|
| 347 |
} |
| 348 |
} |
| 349 |
if(is_plugin_active('woocommerce-product-bundles/woocommerce-product-bundles.php')){ |
| 350 |
$bundle_query = $wpdb->prepare("SELECT product_id FROM {$wpdb->prefix}woocommerce_bundled_items where bundle_id = %d", $id); |
| 351 |
$bundle_results = $wpdb->get_results($bundle_query); |
| 352 |
|
| 353 |
if(!empty($bundle_results)){ |
| 354 |
foreach($bundle_results as $bundle_value){ |
| 355 |
$product_bundle_query = $wpdb->prepare("SELECT post_title FROM {$wpdb->prefix}posts where id = %d", $bundle_value->product_id); |
| 356 |
$product_bundle_value=$wpdb->get_results($product_bundle_query); |
| 357 |
$bundle_item[] = $product_bundle_value[0]->post_title; |
| 358 |
} |
| 359 |
|
| 360 |
$bundle_items = implode('|', $bundle_item); |
| 361 |
WooCommerceExport::$export_instance->data[$id]['product_bundle_items'] = $bundle_items; |
| 362 |
} |
| 363 |
|
| 364 |
$bundle_meta = $wpdb->prepare("SELECT bundled_item_id FROM {$wpdb->prefix}woocommerce_bundled_items where bundle_id = %d", $id); |
| 365 |
$bundle_meta_result = $wpdb->get_results($bundle_meta); |
| 366 |
|
| 367 |
if(!empty($bundle_meta_result)){ |
| 368 |
foreach($bundle_meta_result as $bundle_meta_value){ |
| 369 |
$bundle_fields = $bundle_meta_value->bundled_item_id; |
| 370 |
|
| 371 |
$bundle_field = $wpdb->prepare("SELECT meta_key,meta_value FROM {$wpdb->prefix}woocommerce_bundled_itemmeta where bundled_item_id = %d", $bundle_fields); |
| 372 |
$bundle_field_result = $wpdb->get_results($bundle_field); |
| 373 |
if(!empty($bundle_field_result)){ |
| 374 |
foreach($bundle_field_result as $bundle_field_value){ |
| 375 |
if($bundle_field_value->meta_key == 'optional'){ |
| 376 |
$optional = $bundle_field_value->meta_value; |
| 377 |
if($optional == 'yes'){ |
| 378 |
$optional_value[] = 'Yes'; |
| 379 |
}elseif($optional == 'no'){ |
| 380 |
$optional_value[] = 'No'; |
| 381 |
} |
| 382 |
} |
| 383 |
if($bundle_field_value->meta_key == 'quantity_min'){ |
| 384 |
$q_min[] = $bundle_field_value->meta_value; |
| 385 |
} |
| 386 |
if($bundle_field_value->meta_key == 'quantity_max'){ |
| 387 |
$q_max[] = $bundle_field_value->meta_value; |
| 388 |
} |
| 389 |
if($bundle_field_value->meta_key == 'priced_individually'){ |
| 390 |
$priced_individually = $bundle_field_value->meta_value; |
| 391 |
if($priced_individually == 'yes'){ |
| 392 |
$price_value[] = 'Yes'; |
| 393 |
}elseif($priced_individually == 'no'){ |
| 394 |
$price_value[] = 'No'; |
| 395 |
} |
| 396 |
} |
| 397 |
if($bundle_field_value->meta_key == 'discount'){ |
| 398 |
$discount_value[] = $bundle_field_value->meta_value; |
| 399 |
} |
| 400 |
if($bundle_field_value->meta_key == 'single_product_visibility'){ |
| 401 |
$single_product_visibility = $bundle_field_value->meta_value; |
| 402 |
if($single_product_visibility == 'visible'){ |
| 403 |
$product_value[] = 'Yes'; |
| 404 |
}elseif($single_product_visibility == 'hidden'){ |
| 405 |
$product_value[] = 'No'; |
| 406 |
} |
| 407 |
} |
| 408 |
if($bundle_field_value->meta_key == 'cart_visibility'){ |
| 409 |
$cart_visibility = $bundle_field_value->meta_value; |
| 410 |
if($cart_visibility == 'visible'){ |
| 411 |
$cart[] = 'Yes'; |
| 412 |
}elseif($cart_visibility == 'hidden'){ |
| 413 |
$cart[] = 'No'; |
| 414 |
} |
| 415 |
} |
| 416 |
if($bundle_field_value->meta_key == 'order_visibility'){ |
| 417 |
$order_visibility = $bundle_field_value->meta_value; |
| 418 |
if($order_visibility == 'visible'){ |
| 419 |
$order[] = 'Yes'; |
| 420 |
}elseif($order_visibility == 'hidden'){ |
| 421 |
$order[] = 'No'; |
| 422 |
} |
| 423 |
} |
| 424 |
if($bundle_field_value->meta_key == 'hide_thumbnail'){ |
| 425 |
$hide_thumbnail = $bundle_field_value->meta_value; |
| 426 |
if($hide_thumbnail == 'yes'){ |
| 427 |
$thumb[] = 'Yes'; |
| 428 |
}elseif($hide_thumbnail == 'no'){ |
| 429 |
$thumb[] = 'No'; |
| 430 |
} |
| 431 |
} |
| 432 |
if($bundle_field_value->meta_key == 'override_title'){ |
| 433 |
$override_title = $bundle_field_value->meta_value; |
| 434 |
if($override_title == 'yes'){ |
| 435 |
$override[] = 'Yes'; |
| 436 |
}elseif($override_title == 'no'){ |
| 437 |
$override[] = 'No'; |
| 438 |
} |
| 439 |
} |
| 440 |
if($bundle_field_value->meta_key == 'override_description'){ |
| 441 |
$override_description = $bundle_field_value->meta_value; |
| 442 |
if($override_description == 'yes'){ |
| 443 |
$description[] = 'Yes'; |
| 444 |
}elseif($override_description == 'no'){ |
| 445 |
$description[] = 'No'; |
| 446 |
} |
| 447 |
} |
| 448 |
if($bundle_field_value->meta_key == 'title'){ |
| 449 |
$override_title_value[] = $bundle_field_value->meta_value; |
| 450 |
} |
| 451 |
if($bundle_field_value->meta_key == 'description'){ |
| 452 |
$override_description_value[] = $bundle_field_value->meta_value; |
| 453 |
} |
| 454 |
} |
| 455 |
} |
| 456 |
} |
| 457 |
|
| 458 |
$optionals = implode('|', $optional_value); |
| 459 |
WooCommerceExport::$export_instance->data[$id]['optional'] = $optionals; |
| 460 |
$q_minimum = implode('|', $q_min); |
| 461 |
WooCommerceExport::$export_instance->data[$id]['quantity_min'] = $q_minimum; |
| 462 |
$q_maximum = implode('|', $q_max); |
| 463 |
WooCommerceExport::$export_instance->data[$id]['quantity_max'] = $q_maximum; |
| 464 |
$price_values = implode('|', $price_value); |
| 465 |
WooCommerceExport::$export_instance->data[$id]['priced_individually'] = $price_values; |
| 466 |
$discount_values = implode('|', $discount_value); |
| 467 |
WooCommerceExport::$export_instance->data[$id]['discount'] = $discount_values; |
| 468 |
$product_values = implode('|', $product_value); |
| 469 |
//WooCommerceExport::$export_instance->data[$id]['product_details'] = $product_values; |
| 470 |
WooCommerceExport::$export_instance->data[$id]['single_product_visibility'] = $product_values; |
| 471 |
$cart_values = implode('|', $cart); |
| 472 |
//WooCommerceExport::$export_instance->data[$id]['cart_checkout'] = $cart_values; |
| 473 |
WooCommerceExport::$export_instance->data[$id]['cart_visibility'] = $cart_values; |
| 474 |
$order_values = implode('|', $order); |
| 475 |
//WooCommerceExport::$export_instance->data[$id]['order_details'] = $order_values; |
| 476 |
WooCommerceExport::$export_instance->data[$id]['order_visibility'] = $order_values; |
| 477 |
$thumbs = implode('|', $thumb); |
| 478 |
WooCommerceExport::$export_instance->data[$id]['hide_thumbnail'] = $thumbs; |
| 479 |
$overrides = implode('|', $override); |
| 480 |
WooCommerceExport::$export_instance->data[$id]['override_title'] = $overrides; |
| 481 |
$descriptions = implode('|', $description); |
| 482 |
WooCommerceExport::$export_instance->data[$id]['override_description'] = $descriptions; |
| 483 |
$override_titles = implode('|', $override_title_value); |
| 484 |
WooCommerceExport::$export_instance->data[$id]['override_title_value'] = $override_titles; |
| 485 |
$override_descriptions = implode('|', $override_description_value); |
| 486 |
WooCommerceExport::$export_instance->data[$id]['override_description_value'] = $override_descriptions; |
| 487 |
|
| 488 |
} |
| 489 |
} |
| 490 |
WooCommerceExport::$export_instance->data[$id]['product_attribute_name'] = substr($attname, 0, -1); |
| 491 |
WooCommerceExport::$export_instance->data[$id]['product_attribute_type'] = substr($atttype, 0, -1); |
| 492 |
WooCommerceExport::$export_instance->data[$id]['product_attribute_value'] = substr($attvalue, 0, -1); |
| 493 |
WooCommerceExport::$export_instance->data[$id]['product_attribute_visible'] = substr($attvisible, 0, -1); |
| 494 |
WooCommerceExport::$export_instance->data[$id]['product_attribute_variation'] = substr($attvar, 0, -1); |
| 495 |
WooCommerceExport::$export_instance->data[$id]['product_attribute_position'] = substr($attpos, 0, -1); |
| 496 |
WooCommerceExport::$export_instance->data[$id]['product_attribute_taxonomy'] = substr($atttaxo, 0, -1); |
| 497 |
if(!empty($attlabel)){ |
| 498 |
$cus = explode('|', substr($attlabel, 0, -1)); |
| 499 |
$cusAttr = ""; |
| 500 |
if(!empty($cus[0])){ |
| 501 |
foreach ($cus as $cus1) { |
| 502 |
$name = 'attribute_'.$cus1; |
| 503 |
$custname = substr($cus1 , 3); |
| 504 |
$cust_name = $wpdb->get_var("SELECT attribute_label FROM {$wpdb->prefix}woocommerce_attribute_taxonomies WHERE attribute_name = '$custname' "); |
| 505 |
$slug = WooCommerceExport::$export_instance->data[$id][$name]; |
| 506 |
$cust_val = $wpdb->get_var("SELECT name FROM {$wpdb->prefix}terms WHERE slug = '$slug' "); |
| 507 |
$cusAttr .= $cust_name.'|'.$cust_val.','; |
| 508 |
} |
| 509 |
} |
| 510 |
WooCommerceExport::$export_instance->data[$id]['custom_attributes'] = substr($cusAttr, 0, -1); |
| 511 |
} |
| 512 |
$query = $wpdb->prepare("SELECT post_id,meta_key,meta_value FROM {$wpdb->prefix}postmeta where post_id = %d", $id); |
| 513 |
$result = $wpdb->get_results($query); |
| 514 |
if(!empty($result)){ |
| 515 |
foreach ($result as $key => $value) { |
| 516 |
if($value->meta_key == '_sale_price_dates_from'){ |
| 517 |
$woo_sales_price_dates_value = ''; |
| 518 |
if(!empty($value->meta_value)){ |
| 519 |
$woo_sales_price_dates_value = date('Y-m-d', $value->meta_value); |
| 520 |
} |
| 521 |
WooCommerceExport::$export_instance->data[$id]['sale_price_dates_from'] = $woo_sales_price_dates_value; |
| 522 |
} |
| 523 |
if($value->meta_key == '_sale_price_dates_to'){ |
| 524 |
$woo_sales_price_datesto_value = ''; |
| 525 |
if(!empty($value->meta_value)){ |
| 526 |
$woo_sales_price_datesto_value = date('Y-m-d', $value->meta_value); |
| 527 |
} |
| 528 |
WooCommerceExport::$export_instance->data[$id]['sale_price_dates_to'] = $woo_sales_price_datesto_value; |
| 529 |
} |
| 530 |
if($value->meta_key == '_downloadable_files'){ |
| 531 |
$downfiles = unserialize($value->meta_value); |
| 532 |
$down_file = ''; |
| 533 |
if(!empty($downfiles)){ |
| 534 |
foreach($downfiles as $dk => $dv){ |
| 535 |
$down_file .= $dv['name'].','.$dv['file'].'|'; |
| 536 |
} |
| 537 |
} |
| 538 |
WooCommerceExport::$export_instance->data[$id]['downloadable_files'] = rtrim($down_file,"|"); |
| 539 |
} |
| 540 |
if($value->meta_key == '_variation_description'){ |
| 541 |
WooCommerceExport::$export_instance->data[$id]['description'] = $value->meta_value; |
| 542 |
} |
| 543 |
if($value->meta_key == '_sku'){ |
| 544 |
WooCommerceExport::$export_instance->data[$id]['sku'] = $value->meta_value; |
| 545 |
} |
| 546 |
} |
| 547 |
} |
| 548 |
if($type == 'WooCommerce'){ |
| 549 |
$product = new \WC_Product($id); |
| 550 |
$get_catalog_visibility = $product->get_catalog_visibility(); |
| 551 |
if($get_catalog_visibility == 'visible'){ |
| 552 |
WooCommerceExport::$export_instance->data[$id]['visibility'] = '1'; |
| 553 |
} |
| 554 |
elseif($get_catalog_visibility == 'catalog'){ |
| 555 |
WooCommerceExport::$export_instance->data[$id]['visibility'] = '2'; |
| 556 |
} |
| 557 |
elseif($get_catalog_visibility == 'search'){ |
| 558 |
WooCommerceExport::$export_instance->data[$id]['visibility'] = '3'; |
| 559 |
} |
| 560 |
elseif($get_catalog_visibility == 'hidden'){ |
| 561 |
WooCommerceExport::$export_instance->data[$id]['visibility'] = '4'; |
| 562 |
} |
| 563 |
$result = $wpdb->get_results("SELECT * |
| 564 |
FROM {$wpdb->prefix}terms as t |
| 565 |
JOIN {$wpdb->prefix}term_taxonomy AS tt ON t.term_id = tt.term_id |
| 566 |
JOIN {$wpdb->prefix}term_relationships AS tr ON tt.term_taxonomy_id = tr.term_taxonomy_id |
| 567 |
WHERE t.name = 'featured' |
| 568 |
AND tr.object_id = $id"); |
| 569 |
if(!empty($result)){ |
| 570 |
WooCommerceExport::$export_instance->data[$id]['featured_product'] = '1'; |
| 571 |
} |
| 572 |
} |
| 573 |
|
| 574 |
$product_type = WooCommerceExport::$export_instance->data[$id]['product_type']; |
| 575 |
if($product_type == 'simple'){ |
| 576 |
WooCommerceExport::$export_instance->data[$id]['product_type'] = '1'; |
| 577 |
}elseif($product_type == 'grouped'){ |
| 578 |
WooCommerceExport::$export_instance->data[$id]['product_type'] = '2'; |
| 579 |
}elseif($product_type == 'external'){ |
| 580 |
WooCommerceExport::$export_instance->data[$id]['product_type'] = '3'; |
| 581 |
}elseif($product_type == 'variable'){ |
| 582 |
WooCommerceExport::$export_instance->data[$id]['product_type'] = '4'; |
| 583 |
}elseif($product_type == 'bundle'){ |
| 584 |
WooCommerceExport::$export_instance->data[$id]['product_type'] = '7'; |
| 585 |
} |
| 586 |
} |
| 587 |
|
| 588 |
/** |
| 589 |
* Fetch Terms & Taxonomies |
| 590 |
* @param $mode |
| 591 |
* @param $module |
| 592 |
* @param $optionalType |
| 593 |
* @return array |
| 594 |
*/ |
| 595 |
public function FetchTaxonomies($module, $optionalType, $mode = null) { |
| 596 |
|
| 597 |
global $wpdb; |
| 598 |
$terms_table = $wpdb->prefix."terms"; |
| 599 |
$terms_taxo_table = $wpdb->prefix."term_taxonomy"; |
| 600 |
self::$export_instance->generateHeaders($module, $optionalType); |
| 601 |
$taxonomy = $optionalType; |
| 602 |
$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); |
| 603 |
|
| 604 |
$get_all_taxonomies = $wpdb->get_results($query); |
| 605 |
self::$export_instance->totalRowCount = count($get_all_taxonomies); |
| 606 |
if(!empty($get_all_taxonomies)) { |
| 607 |
foreach( $get_all_taxonomies as $termKey => $termValue ) { |
| 608 |
$termID = $termValue->term_id; |
| 609 |
$termMeta = get_term_meta($termID); |
| 610 |
//wpsc_meta data starts |
| 611 |
if(in_array('wp-e-commerce/wp-shopping-cart.php', self::$export_instance->get_active_plugins())) { |
| 612 |
$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'); |
| 613 |
$wpsc_meta = $wpdb->get_results($wpsc_query,ARRAY_A); |
| 614 |
foreach($wpsc_meta as $mk => $mv){ |
| 615 |
if($mv['meta_key'] == 'image'){ |
| 616 |
if($mv['meta_value']){ |
| 617 |
$udir = wp_upload_dir(); |
| 618 |
$img_path = $udir['baseurl'] . "/wpsc/category_images/".$mv['meta_value']; |
| 619 |
self::$export_instance->data[$termID]['category_image'] = $img_path; |
| 620 |
}else{ |
| 621 |
self::$export_instance->data[$termID]['category_image'] = ''; |
| 622 |
} |
| 623 |
}elseif($mv['meta_key'] == 'display_type'){ |
| 624 |
self::$export_instance->data[$termID]['catelog_view'] = $mv['meta_value']; |
| 625 |
}elseif($mv['meta_key'] == 'uses_billing_address'){ |
| 626 |
self::$export_instance->data[$termID]['address_calculate'] = $mv['meta_value']; }elseif($mv['meta_key'] == 'image_width'){ |
| 627 |
self::$export_instance->data[$termID]['category_image_width'] = $mv['meta_value']; }elseif($mv['meta_key'] == 'image_height'){ |
| 628 |
self::$export_instance->data[$termID]['category_image_height'] = $mv['meta_value']; }else{ |
| 629 |
self::$export_instance->data[$termID][$mv['meta_key']] = $mv['meta_value']; |
| 630 |
} |
| 631 |
} |
| 632 |
} |
| 633 |
//wpsc_meta data ends |
| 634 |
//woocommerce meta data starts |
| 635 |
if(in_array('woocommerce/woocommerce.php', self::$export_instance->get_active_plugins())){ |
| 636 |
if(isset($termMeta['thumbnail_id'][0])){ |
| 637 |
$thum_id = $termMeta['thumbnail_id'][0]; |
| 638 |
self::$export_instance->data[$termID]['image'] = self::$export_instance->getAttachment($thum_id); |
| 639 |
} |
| 640 |
if(!empty($termMeta['display_type'][0])){ |
| 641 |
self::$export_instance->data[$termID]['display_type'] = $termMeta['display_type'][0]; |
| 642 |
} |
| 643 |
if(!empty($termMeta['cat_meta'][0])){ |
| 644 |
$cat_meta = unserialize($termMeta['cat_meta'][0]); |
| 645 |
self::$export_instance->data[$termID]['top_content'] = $cat_meta['cat_header']; |
| 646 |
self::$export_instance->data[$termID]['bottom_content'] = $cat_meta['cat_footer']; |
| 647 |
} |
| 648 |
} |
| 649 |
//woocommerce meta data ends |
| 650 |
$termName = $termValue->name; |
| 651 |
$termSlug = $termValue->slug; |
| 652 |
$termDesc = $termValue->description; |
| 653 |
$termParent = $termValue->parent; |
| 654 |
if($termParent == 0) { |
| 655 |
self::$export_instance->data[$termID]['name'] = $termName; |
| 656 |
} else { |
| 657 |
$termParentName = get_cat_name( $termParent ); |
| 658 |
self::$export_instance->data[$termID]['name'] = $termParentName . '|' . $termName; |
| 659 |
} |
| 660 |
self::$export_instance->data[$termID]['slug'] = $termSlug; |
| 661 |
self::$export_instance->data[$termID]['description'] = $termDesc; |
| 662 |
self::$export_instance->data[$termID]['TERMID'] = $termID; |
| 663 |
self::$export_instance->data[$termID]['parent'] = $termParent; |
| 664 |
self::$export_instance->getWPMLData($termID,$optionalType,$module); |
| 665 |
|
| 666 |
WooCommerceExport::$post_export->getPostsMetaDataBasedOnRecordId($termID, $module, $optionalType); |
| 667 |
|
| 668 |
if(in_array('wordpress-seo/wp-seo.php', self::$export_instance->get_active_plugins())) { |
| 669 |
$seo_yoast_taxonomies = get_option( 'wpseo_taxonomy_meta' ); |
| 670 |
if ( isset( $seo_yoast_taxonomies[$optionalType] ) ) { |
| 671 |
self::$export_instance->data[ $termID ]['title'] = $seo_yoast_taxonomies[$optionalType][$termID]['wpseo_title']; |
| 672 |
self::$export_instance->data[ $termID ]['meta_desc'] = $seo_yoast_taxonomies[$optionalType][$termID]['wpseo_desc']; |
| 673 |
self::$export_instance->data[ $termID ]['canonical'] = $seo_yoast_taxonomies[$optionalType][$termID]['wpseo_canonical']; |
| 674 |
self::$export_instance->data[ $termID ]['bctitle'] = $seo_yoast_taxonomies[$optionalType][$termID]['wpseo_bctitle']; |
| 675 |
self::$export_instance->data[ $termID ]['meta-robots-noindex'] = $seo_yoast_taxonomies[$optionalType][$termID]['wpseo_noindex']; |
| 676 |
self::$export_instance->data[ $termID ]['sitemap-include'] = $seo_yoast_taxonomies[$optionalType][$termID]['wpseo_sitemap_include']; |
| 677 |
self::$export_instance->data[ $termID ]['opengraph-title'] = $seo_yoast_taxonomies[$optionalType][$termID]['wpseo_opengraph-title']; |
| 678 |
self::$export_instance->data[ $termID ]['opengraph-description'] = $seo_yoast_taxonomies[$optionalType][$termID]['wpseo_opengraph-description']; |
| 679 |
self::$export_instance->data[ $termID ]['opengraph-image'] = $seo_yoast_taxonomies[$optionalType][$termID]['wpseo_opengraph-image']; |
| 680 |
self::$export_instance->data[ $termID ]['twitter-title'] = $seo_yoast_taxonomies[$optionalType][$termID]['wpseo_twitter-title']; |
| 681 |
self::$export_instance->data[ $termID ]['twitter-description'] = $seo_yoast_taxonomies[$optionalType][$termID]['wpseo_twitter-description']; |
| 682 |
self::$export_instance->data[ $termID ]['twitter-image'] = $seo_yoast_taxonomies[$optionalType][$termID]['wpseo_twitter-image']; |
| 683 |
self::$export_instance->data[ $termID ]['focus_keyword'] = $seo_yoast_taxonomies[$optionalType][$termID]['wpseo_focuskw']; |
| 684 |
|
| 685 |
} |
| 686 |
} |
| 687 |
} |
| 688 |
} |
| 689 |
$result = self::$export_instance->finalDataToExport(self::$export_instance->data , $module); |
| 690 |
if($mode == null) |
| 691 |
self::$export_instance->proceedExport($result); |
| 692 |
else |
| 693 |
return $result; |
| 694 |
} |
| 695 |
|
| 696 |
public function getCourseData($id) |
| 697 |
{ |
| 698 |
global $wpdb; |
| 699 |
|
| 700 |
$get_section_details = $wpdb->get_results("SELECT section_id, section_name, section_description FROM {$wpdb->prefix}learnpress_sections WHERE section_course_id = $id ", ARRAY_A); |
| 701 |
$section_names = ''; |
| 702 |
$section_descriptions = ''; |
| 703 |
$get_lesson_name = ''; |
| 704 |
$get_lesson_description = ''; |
| 705 |
$get_lesson_duration = ''; |
| 706 |
$get_lesson_preview = ''; |
| 707 |
$get_quiz_name = ''; |
| 708 |
$get_quiz_description = ''; |
| 709 |
$get_quiz_meta = []; |
| 710 |
|
| 711 |
foreach($get_section_details as $section_details){ |
| 712 |
$section_names .= $section_details['section_name'] . '|'; |
| 713 |
$section_descriptions .= $section_details['section_description'] . '|'; |
| 714 |
|
| 715 |
$section_id = $section_details['section_id']; |
| 716 |
$get_section_item_details = $wpdb->get_results("SELECT item_id, item_type FROM {$wpdb->prefix}learnpress_section_items WHERE section_id = $section_id ", ARRAY_A); |
| 717 |
|
| 718 |
$lesson_name = ''; |
| 719 |
$lesson_description = ''; |
| 720 |
$quiz_name = ''; |
| 721 |
$quiz_description = ''; |
| 722 |
$lesson_duration = ''; |
| 723 |
$lesson_preview = ''; |
| 724 |
$quiz_metas = []; |
| 725 |
|
| 726 |
foreach($get_section_item_details as $section_item_details){ |
| 727 |
$section_item_id = $section_item_details['item_id']; |
| 728 |
if($section_item_details['item_type'] == 'lp_lesson'){ |
| 729 |
$lesson_name .= $wpdb->get_var("SELECT post_title FROM {$wpdb->prefix}posts WHERE ID = $section_item_id ") . ', '; |
| 730 |
$lesson_description .= $wpdb->get_var("SELECT post_content FROM {$wpdb->prefix}posts WHERE ID = $section_item_id "). ', '; |
| 731 |
$lesson_duration .= $wpdb->get_var("SELECT meta_value FROM {$wpdb->prefix}postmeta WHERE post_id = $section_item_id AND meta_key = '_lp_duration' ") . ', '; |
| 732 |
$lesson_preview .= $wpdb->get_var("SELECT meta_value FROM {$wpdb->prefix}postmeta WHERE post_id = $section_item_id AND meta_key = '_lp_preview' ") . ', '; |
| 733 |
} |
| 734 |
elseif($section_item_details['item_type'] == 'lp_quiz'){ |
| 735 |
$quiz_name .= $wpdb->get_var("SELECT post_title FROM {$wpdb->prefix}posts WHERE ID = $section_item_id ") . ', '; |
| 736 |
$quiz_description .= $wpdb->get_var("SELECT post_content FROM {$wpdb->prefix}posts WHERE ID = $section_item_id "). ', '; |
| 737 |
|
| 738 |
$quiz_meta = $wpdb->get_results("SELECT meta_key, meta_value FROM {$wpdb->prefix}postmeta WHERE post_id = $section_item_id AND meta_key LIKE '_lp_%' ", ARRAY_A); |
| 739 |
foreach($quiz_meta as $quiz_meta_values){ |
| 740 |
$quiz_key = $quiz_meta_values['meta_key']; |
| 741 |
$quiz_value = $quiz_meta_values['meta_value'] . ', '; |
| 742 |
|
| 743 |
if($quiz_key != '_lp_hidden_questions'){ |
| 744 |
if($quiz_key == '_lp_retake_count'){ |
| 745 |
$quiz_key = '_lp_quiz_retake_count'; |
| 746 |
} |
| 747 |
$quiz_metas[$quiz_key] = $quiz_value; |
| 748 |
} |
| 749 |
} |
| 750 |
} |
| 751 |
} |
| 752 |
|
| 753 |
$get_lesson_name .= rtrim($lesson_name, ', ') . '|'; |
| 754 |
$get_lesson_description .= rtrim($lesson_description, ', ') . '|'; |
| 755 |
$get_quiz_name .= rtrim($quiz_name, ', ') . '|'; |
| 756 |
$get_quiz_description .= rtrim($quiz_description, ', ') . '|'; |
| 757 |
$get_lesson_duration .= rtrim($lesson_duration, ', ') . '|'; |
| 758 |
$get_lesson_preview .= rtrim($lesson_preview, ', ') . '|'; |
| 759 |
|
| 760 |
foreach($quiz_metas as $quiz_meta_keys => $quiz_meta_values){ |
| 761 |
$get_quiz_meta[$quiz_meta_keys] = rtrim($quiz_meta_values, ', ') . '|'; |
| 762 |
} |
| 763 |
} |
| 764 |
|
| 765 |
WooCommerceExport::$export_instance->data[$id]['curriculum_name'] = rtrim($section_names, '|'); |
| 766 |
WooCommerceExport::$export_instance->data[$id]['curriculum_description'] = rtrim($section_descriptions, '|'); |
| 767 |
WooCommerceExport::$export_instance->data[$id]['lesson_name'] = rtrim($get_lesson_name, '|'); |
| 768 |
WooCommerceExport::$export_instance->data[$id]['lesson_description'] = rtrim($get_lesson_description, '|'); |
| 769 |
WooCommerceExport::$export_instance->data[$id]['quiz_name'] = rtrim($get_quiz_name, '|'); |
| 770 |
WooCommerceExport::$export_instance->data[$id]['quiz_description'] = rtrim($get_quiz_description, '|'); |
| 771 |
WooCommerceExport::$export_instance->data[$id]['_lp_lesson_duration'] = rtrim($get_lesson_duration, '|'); |
| 772 |
WooCommerceExport::$export_instance->data[$id]['_lp_preview'] = rtrim($get_lesson_preview, '|'); |
| 773 |
|
| 774 |
foreach($get_quiz_meta as $get_quiz_meta_keys => $get_quiz_meta_values){ |
| 775 |
WooCommerceExport::$export_instance->data[$id][$get_quiz_meta_keys] = rtrim($get_quiz_meta_values, '|'); |
| 776 |
} |
| 777 |
} |
| 778 |
|
| 779 |
public function getLessonData($id){ |
| 780 |
global $wpdb; |
| 781 |
$lesson_duration = $wpdb->get_var("SELECT meta_value FROM {$wpdb->prefix}postmeta WHERE post_id = $id AND meta_key = '_lp_duration' "); |
| 782 |
WooCommerceExport::$export_instance->data[$id]['_lp_lesson_duration'] = $lesson_duration; |
| 783 |
|
| 784 |
$get_section_id = $wpdb->get_var("SELECT section_id FROM {$wpdb->prefix}learnpress_section_items WHERE item_id = $id AND item_type = 'lp_lesson' "); |
| 785 |
if(!empty($get_section_id)){ |
| 786 |
$get_section_name = $wpdb->get_var("SELECT section_name FROM {$wpdb->prefix}learnpress_sections WHERE section_id = $get_section_id "); |
| 787 |
$get_section_course_id = $wpdb->get_var("SELECT section_course_id FROM {$wpdb->prefix}learnpress_sections WHERE section_id = $get_section_id "); |
| 788 |
|
| 789 |
WooCommerceExport::$export_instance->data[$id]['curriculum_name'] = $get_section_name; |
| 790 |
WooCommerceExport::$export_instance->data[$id]['course_id'] = $get_section_course_id; |
| 791 |
} |
| 792 |
} |
| 793 |
|
| 794 |
public function getQuizData($id){ |
| 795 |
global $wpdb; |
| 796 |
$quiz_retake_count = $wpdb->get_var("SELECT meta_value FROM {$wpdb->prefix}postmeta WHERE post_id = $id AND meta_key = '_lp_retake_count' "); |
| 797 |
WooCommerceExport::$export_instance->data[$id]['_lp_quiz_retake_count'] = $quiz_retake_count; |
| 798 |
|
| 799 |
$get_section_id = $wpdb->get_var("SELECT section_id FROM {$wpdb->prefix}learnpress_section_items WHERE item_id = $id AND item_type = 'lp_quiz' "); |
| 800 |
if(!empty($get_section_id)){ |
| 801 |
$get_section_name = $wpdb->get_var("SELECT section_name FROM {$wpdb->prefix}learnpress_sections WHERE section_id = $get_section_id "); |
| 802 |
$get_section_course_id = $wpdb->get_var("SELECT section_course_id FROM {$wpdb->prefix}learnpress_sections WHERE section_id = $get_section_id "); |
| 803 |
|
| 804 |
WooCommerceExport::$export_instance->data[$id]['curriculum_name'] = $get_section_name; |
| 805 |
WooCommerceExport::$export_instance->data[$id]['course_id'] = $get_section_course_id; |
| 806 |
} |
| 807 |
|
| 808 |
$get_question_title = ''; |
| 809 |
$get_question_content = ''; |
| 810 |
$get_question_mark = ''; |
| 811 |
$get_question_explanation = ''; |
| 812 |
$get_question_hint = ''; |
| 813 |
$get_question_type = ''; |
| 814 |
$get_option_value = ''; |
| 815 |
|
| 816 |
$get_question_ids = $wpdb->get_results("SELECT question_id FROM {$wpdb->prefix}learnpress_quiz_questions WHERE quiz_id = $id ", ARRAY_A); |
| 817 |
foreach($get_question_ids as $question_ids){ |
| 818 |
$question_id = $question_ids['question_id']; |
| 819 |
$get_question_title .= $wpdb->get_var("SELECT post_title FROM {$wpdb->prefix}posts WHERE ID = $question_id ") . ','; |
| 820 |
$get_question_content .= $wpdb->get_var("SELECT post_content FROM {$wpdb->prefix}posts WHERE ID = $question_id ") . ','; |
| 821 |
|
| 822 |
$get_question_mark .= $wpdb->get_var("SELECT meta_value FROM {$wpdb->prefix}postmeta WHERE post_id = $question_id AND meta_key = '_lp_mark' ") . ', '; |
| 823 |
$get_question_explanation .= $wpdb->get_var("SELECT meta_value FROM {$wpdb->prefix}postmeta WHERE post_id = $question_id AND meta_key = '_lp_explanation' ") . ','; |
| 824 |
$get_question_hint .= $wpdb->get_var("SELECT meta_value FROM {$wpdb->prefix}postmeta WHERE post_id = $question_id AND meta_key = '_lp_hint' ") . ','; |
| 825 |
$get_question_type .= $wpdb->get_var("SELECT meta_value FROM {$wpdb->prefix}postmeta WHERE post_id = $question_id AND meta_key = '_lp_type' ") . ','; |
| 826 |
|
| 827 |
$get_question_options = $wpdb->get_results("SELECT * FROM {$wpdb->prefix}learnpress_question_answers WHERE question_id = $question_id ", ARRAY_A); |
| 828 |
$option_value = ''; |
| 829 |
foreach($get_question_options as $question_option){ |
| 830 |
//$get_answer_data = unserialize($question_options['answer_data']); |
| 831 |
if(empty($question_option['is_true'])){ |
| 832 |
$question_option['is_true'] = 'no'; |
| 833 |
} |
| 834 |
|
| 835 |
$option_value .= $question_option['title'] .'|'. $question_option['is_true'] . '->'; |
| 836 |
} |
| 837 |
$get_option_value .= rtrim($option_value, '->') . ','; |
| 838 |
} |
| 839 |
|
| 840 |
WooCommerceExport::$export_instance->data[$id]['question_title'] = rtrim($get_question_title, ','); |
| 841 |
WooCommerceExport::$export_instance->data[$id]['question_description'] = rtrim($get_question_content, ','); |
| 842 |
WooCommerceExport::$export_instance->data[$id]['_lp_mark'] = rtrim($get_question_mark, ', '); |
| 843 |
WooCommerceExport::$export_instance->data[$id]['_lp_explanation'] = rtrim($get_question_explanation, ','); |
| 844 |
WooCommerceExport::$export_instance->data[$id]['_lp_hint'] = rtrim($get_question_hint, ','); |
| 845 |
WooCommerceExport::$export_instance->data[$id]['_lp_type'] = rtrim($get_question_type, ','); |
| 846 |
WooCommerceExport::$export_instance->data[$id]['question_options'] = rtrim($get_option_value, ','); |
| 847 |
|
| 848 |
} |
| 849 |
|
| 850 |
public function getQuestionData($id){ |
| 851 |
global $wpdb; |
| 852 |
$get_quiz_id = $wpdb->get_var("SELECT quiz_id FROM {$wpdb->prefix}learnpress_quiz_questions WHERE question_id = $id "); |
| 853 |
|
| 854 |
$get_question_options = $wpdb->get_results("SELECT * FROM {$wpdb->prefix}learnpress_question_answers WHERE question_id = $id ", ARRAY_A); |
| 855 |
$option_value = ''; |
| 856 |
foreach($get_question_options as $question_options){ |
| 857 |
//$get_answer_data = unserialize($question_options['answer_data']); |
| 858 |
if(empty($question_options['is_true'])){ |
| 859 |
$question_options['is_true'] = 'no'; |
| 860 |
} |
| 861 |
$option_value .= $question_options['title'] .'|'. $question_options['is_true'] . '->'; |
| 862 |
} |
| 863 |
|
| 864 |
if(!empty($get_quiz_id)){ |
| 865 |
$get_section_id = $wpdb->get_var("SELECT section_id FROM {$wpdb->prefix}learnpress_section_items WHERE item_id = $get_quiz_id AND item_type = 'lp_quiz' "); |
| 866 |
if(!empty($get_section_id)){ |
| 867 |
$get_section_name = $wpdb->get_var("SELECT section_name FROM {$wpdb->prefix}learnpress_sections WHERE section_id = $get_section_id "); |
| 868 |
$get_section_course_id = $wpdb->get_var("SELECT section_course_id FROM {$wpdb->prefix}learnpress_sections WHERE section_id = $get_section_id "); |
| 869 |
|
| 870 |
WooCommerceExport::$export_instance->data[$id]['curriculum_name'] = $get_section_name; |
| 871 |
WooCommerceExport::$export_instance->data[$id]['course_id'] = $get_section_course_id; |
| 872 |
} |
| 873 |
WooCommerceExport::$export_instance->data[$id]['quiz_id'] = $get_quiz_id; |
| 874 |
} |
| 875 |
|
| 876 |
WooCommerceExport::$export_instance->data[$id]['question_options'] = rtrim($option_value, '->'); |
| 877 |
} |
| 878 |
|
| 879 |
public function getOrderData($id){ |
| 880 |
global $wpdb; |
| 881 |
|
| 882 |
$order_status = $wpdb->get_var("SELECT post_status FROM {$wpdb->prefix}posts WHERE ID = $id "); |
| 883 |
$order_date = $wpdb->get_var("SELECT post_date FROM {$wpdb->prefix}posts WHERE ID = $id "); |
| 884 |
$order_total = $wpdb->get_var("SELECT meta_value FROM {$wpdb->prefix}postmeta WHERE post_id = $id AND meta_key = '_order_total' "); |
| 885 |
$order_subtotal = $wpdb->get_var("SELECT meta_value FROM {$wpdb->prefix}postmeta WHERE post_id = $id AND meta_key = '_order_subtotal' "); |
| 886 |
$user_id = $wpdb->get_var("SELECT meta_value FROM {$wpdb->prefix}postmeta WHERE post_id = $id AND meta_key = '_user_id' "); |
| 887 |
|
| 888 |
$get_order_items = $wpdb->get_results("SELECT order_item_id FROM {$wpdb->prefix}learnpress_order_items WHERE order_id = $id ",ARRAY_A); |
| 889 |
$course_id = ''; |
| 890 |
$item_quantity = ''; |
| 891 |
$item_total = ''; |
| 892 |
$item_subtotal = ''; |
| 893 |
foreach($get_order_items as $get_order_values){ |
| 894 |
$order_item_id = $get_order_values['order_item_id']; |
| 895 |
|
| 896 |
$course_id .= $wpdb->get_var("SELECT meta_value FROM {$wpdb->prefix}learnpress_order_itemmeta WHERE learnpress_order_item_id = $order_item_id AND meta_key = '_course_id' ") . ', '; |
| 897 |
$item_quantity .= $wpdb->get_var("SELECT meta_value FROM {$wpdb->prefix}learnpress_order_itemmeta WHERE learnpress_order_item_id = $order_item_id AND meta_key = '_quantity' ") . ', '; |
| 898 |
$item_total .= $wpdb->get_var("SELECT meta_value FROM {$wpdb->prefix}learnpress_order_itemmeta WHERE learnpress_order_item_id = $order_item_id AND meta_key = '_subtotal' ") . ', '; |
| 899 |
$item_subtotal .= $wpdb->get_var("SELECT meta_value FROM {$wpdb->prefix}learnpress_order_itemmeta WHERE learnpress_order_item_id = $order_item_id AND meta_key = '_total' ") . ', '; |
| 900 |
} |
| 901 |
|
| 902 |
WooCommerceExport::$export_instance->data[$id]['order_status'] = $order_status; |
| 903 |
WooCommerceExport::$export_instance->data[$id]['order_date'] = $order_date; |
| 904 |
WooCommerceExport::$export_instance->data[$id]['_order_total'] = $order_total; |
| 905 |
WooCommerceExport::$export_instance->data[$id]['_order_subtotal'] = $order_subtotal; |
| 906 |
WooCommerceExport::$export_instance->data[$id]['user_id'] = $user_id; |
| 907 |
WooCommerceExport::$export_instance->data[$id]['item_id'] = rtrim($course_id, ', '); |
| 908 |
WooCommerceExport::$export_instance->data[$id]['item_quantity'] = rtrim($item_quantity, ', '); |
| 909 |
WooCommerceExport::$export_instance->data[$id]['_item_total'] = rtrim($item_total, ', '); |
| 910 |
WooCommerceExport::$export_instance->data[$id]['_item_subtotal'] = rtrim($item_subtotal, ', '); |
| 911 |
} |
| 912 |
|
| 913 |
public function getMenuData($term_id){ |
| 914 |
global $wpdb; |
| 915 |
$term_name = get_term( $term_id )->name; |
| 916 |
$get_object_ids = $wpdb->get_results("SELECT p.* FROM {$wpdb->prefix}posts AS p |
| 917 |
LEFT JOIN {$wpdb->prefix}term_relationships AS tr ON tr.object_id = p.ID |
| 918 |
LEFT JOIN {$wpdb->prefix}term_taxonomy AS tt ON tt.term_taxonomy_id = tr.term_taxonomy_id |
| 919 |
WHERE p.post_type = 'nav_menu_item' |
| 920 |
AND tt.term_id = $term_id ", ARRAY_A); |
| 921 |
|
| 922 |
$menu_item_types = ''; |
| 923 |
$menu_object_ids = ''; |
| 924 |
$menu_objects = ''; |
| 925 |
$menu_urls = ''; |
| 926 |
foreach($get_object_ids as $object_ids){ |
| 927 |
$object_id = $object_ids['ID']; |
| 928 |
|
| 929 |
$get_object_meta = $wpdb->get_results("SELECT meta_key , meta_value FROM {$wpdb->prefix}postmeta WHERE post_id = $object_id", ARRAY_A); |
| 930 |
$object_meta_key = array_column($get_object_meta, 'meta_key'); |
| 931 |
$object_meta_value = array_column($get_object_meta, 'meta_value'); |
| 932 |
$object_array = array_combine($object_meta_key, $object_meta_value); |
| 933 |
|
| 934 |
$menu_item_type = $object_array['_menu_item_type']; |
| 935 |
$menu_item_object = $object_array['_menu_item_object']; |
| 936 |
$menu_object_item_id = $object_array['_menu_item_object_id']; |
| 937 |
|
| 938 |
if(($menu_item_type == 'post_type') && ($menu_item_object == 'post' || $menu_item_object == 'page')){ |
| 939 |
$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' "); |
| 940 |
} |
| 941 |
elseif($menu_item_type == 'custom' && $menu_item_object == 'custom'){ |
| 942 |
$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' "); |
| 943 |
} |
| 944 |
elseif($menu_item_type == 'taxonomy'){ |
| 945 |
$category_data = get_term_by('id', $menu_object_item_id, $menu_item_object); |
| 946 |
$menu_object_item_title = $category_data->name; |
| 947 |
} |
| 948 |
else{ |
| 949 |
$menu_object_item_title = $menu_object_item_id; |
| 950 |
} |
| 951 |
|
| 952 |
$menu_item_types .= $menu_item_type . ','; |
| 953 |
$menu_object_ids .= $menu_object_item_title . ','; |
| 954 |
$menu_objects .= $menu_item_object . ','; |
| 955 |
$menu_urls .= $object_array['_menu_item_url'] . ','; |
| 956 |
} |
| 957 |
|
| 958 |
WooCommerceExport::$export_instance->data[$term_id]['menu_title'] = $term_name; |
| 959 |
WooCommerceExport::$export_instance->data[$term_id]['_menu_item_type'] = rtrim($menu_item_types, ','); |
| 960 |
WooCommerceExport::$export_instance->data[$term_id]['_menu_item_object_id'] = rtrim($menu_object_ids, ','); |
| 961 |
WooCommerceExport::$export_instance->data[$term_id]['_menu_item_object'] = rtrim($menu_objects, ','); |
| 962 |
WooCommerceExport::$export_instance->data[$term_id]['_menu_item_url'] = rtrim($menu_urls, ','); |
| 963 |
|
| 964 |
$get_nav_options = get_option("nav_menu_options"); |
| 965 |
if(!empty($get_nav_options['auto_add'])){ |
| 966 |
if(in_array($term_id, $get_nav_options['auto_add'])){ |
| 967 |
WooCommerceExport::$export_instance->data[$term_id]['menu_auto_add'] = 'yes'; |
| 968 |
}else{ |
| 969 |
WooCommerceExport::$export_instance->data[$term_id]['menu_auto_add'] = 'no'; |
| 970 |
} |
| 971 |
} |
| 972 |
else{ |
| 973 |
WooCommerceExport::$export_instance->data[$term_id]['menu_auto_add'] = 'no'; |
| 974 |
} |
| 975 |
|
| 976 |
$get_navigation_locations = get_nav_menu_locations(); |
| 977 |
foreach($get_navigation_locations as $nav_keys => $nav_values){ |
| 978 |
if($nav_values == $term_id){ |
| 979 |
WooCommerceExport::$export_instance->data[$term_id][$nav_keys] = 'yes'; |
| 980 |
}else{ |
| 981 |
WooCommerceExport::$export_instance->data[$term_id][$nav_keys] = 'no'; |
| 982 |
} |
| 983 |
} |
| 984 |
} |
| 985 |
|
| 986 |
} |
| 987 |
|
| 988 |
global $woocom_exp_class; |
| 989 |
$woocom_exp_class = WooCommerceExport::getInstance(); |