Advertisement
Guest User

Untitled

a guest
Jan 23rd, 2020
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.28 KB | None | 0 0
  1. /* get product data */
  2.  
  3. public function get_products_data($product_id){
  4. pgs_woo_api_hook_remove_tax_in_price_html();//Remove include tax in price html
  5.  
  6. $wcp = wc_get_product($product_id);
  7. $wce = new WC_Product_External($product_id);
  8.  
  9. $rewards_message = '';
  10. $is_reward_points_active = pgs_woo_api_is_reward_points_active();
  11. if($is_reward_points_active){
  12. $rewards_Product = new PGS_WOO_API_RewardsController();
  13. $rewards_msg = $rewards_Product->get_single_product_rewards_message($wcp);
  14. if(isset($rewards_msg) && !empty($rewards_msg)){
  15. $rewards_message = $rewards_msg;
  16. }
  17. }
  18.  
  19. $get_price = $wcp->get_price();
  20. $regular_price = $wcp->get_regular_price();
  21. $sale_price = $wcp->get_sale_price();
  22. $wc_tax_enabled = wc_tax_enabled();
  23. $tax_status = 'none';
  24. $tax_class = '';
  25. if($wc_tax_enabled){
  26. $tax_price = wc_get_price_to_display( $wcp ); //tax
  27. $price_including_tax = wc_get_price_including_tax( $wcp );
  28. $price_excluding_tax = wc_get_price_excluding_tax( $wcp );
  29. $tax_status = $wcp->get_tax_status();
  30. $tax_class = $wcp->get_tax_class();
  31. }
  32.  
  33. if($this->is_currency_switcher_active){
  34. $regular_price = $this->pgs_woo_api_update_currency_rate($regular_price);
  35. $sale_price = $this->pgs_woo_api_update_currency_rate($sale_price);
  36. $get_price = $this->pgs_woo_api_update_currency_rate($get_price);
  37. if($wc_tax_enabled){
  38. $tax_price = $this->pgs_woo_api_update_currency_rate($tax_price);
  39. $price_including_tax = $this->pgs_woo_api_update_currency_rate($price_including_tax);
  40. $price_excluding_tax = $this->pgs_woo_api_update_currency_rate($price_excluding_tax);
  41. }
  42. }
  43. $addition_info_html = '';
  44. $addition_info_data = array_filter( $wcp->get_attributes(), 'wc_attributes_array_filter_visible' );
  45. if ( $wcp && ( $wcp->has_attributes() || apply_filters( 'wc_product_enable_dimensions_display', $wcp->has_weight() || $wcp->has_dimensions() ) ) ) {
  46. $addition_info_html = $this->pgs_woo_api_get_addition_info_data($addition_info_data,$wcp);
  47. }
  48.  
  49. $tax_price = (isset($tax_price))?$tax_price:'';
  50. $price_including_tax = (isset($price_including_tax))?$price_including_tax:'';
  51. $price_excluding_tax = (isset($price_excluding_tax))?$price_excluding_tax:'';
  52.  
  53. $featured_video = (object)array();
  54. if($this->is_yith_featured_video_active){
  55. $featured_video = $this->pgs_woo_api_get_yith_featured_video($wcp,$product_id);
  56. }
  57.  
  58. $data = array(
  59. 'id' => $wcp->get_id(),
  60. 'name' => $wcp->get_name(),
  61. 'slug' => $wcp->get_slug(),
  62. 'permalink' => $wcp->get_permalink(),
  63. 'date_created' => wc_rest_prepare_date_response( $wcp->get_date_created(), false ),
  64. 'date_created_gmt' => wc_rest_prepare_date_response( $wcp->get_date_created() ),
  65. 'date_modified' =>wc_rest_prepare_date_response( $wcp->get_date_modified(), false ),
  66. 'date_modified_gmt' => wc_rest_prepare_date_response( $wcp->get_date_modified() ),
  67. 'type' => $wcp->get_type(),
  68. 'status' => $wcp->get_status(),
  69. 'featured' => $wcp->get_featured(),
  70. 'catalog_visibility' => $wcp->get_catalog_visibility(),
  71. 'description' => wpautop($wcp->get_description()),
  72. 'description' => wpautop($wcp->get_description()),
  73. 'short_description' => $wcp->get_short_description(),
  74. 'sku' => $wcp->get_sku(),
  75. 'price' => $get_price,
  76. 'tax_price'=> $tax_price, //tax
  77. 'price_excluding_tax' => $price_excluding_tax,
  78. 'price_including_tax' => $price_including_tax,
  79. 'regular_price' => $regular_price,
  80. 'sale_price' => $sale_price,
  81. 'date_on_sale_from' => wc_rest_prepare_date_response($wcp->get_date_on_sale_from()),
  82. 'date_on_sale_from_gmt' => wc_rest_prepare_date_response($wcp->get_date_on_sale_from()),
  83. 'date_on_sale_to' => wc_rest_prepare_date_response($wcp->get_date_on_sale_to()),
  84. 'date_on_sale_to_gmt' => wc_rest_prepare_date_response($wcp->get_date_on_sale_to()),
  85. 'price_html' => $wcp->get_price_html(),
  86. 'on_sale' => $wcp->is_on_sale(),
  87. 'purchasable' => $wcp->is_purchasable(),
  88. 'total_sales' => $wcp->get_total_sales(),
  89. 'virtual' => $wcp->get_virtual(),
  90. 'downloadable' => $wcp->get_downloadable(),
  91. 'downloads' => $wcp->get_downloads(),
  92. 'download_limit' => $wcp->get_download_limit(),
  93. 'download_expiry' => $wcp->get_download_expiry(),
  94. 'external_url' => $wce->get_product_url(),
  95. 'button_text' => $wce->get_button_text(),
  96. 'tax_status' => $tax_status,
  97. 'tax_class' => $tax_class,
  98. 'manage_stock' => $wcp->get_manage_stock(),
  99. 'stock_quantity' => $wcp->get_stock_quantity(),
  100. 'in_stock' => $wcp->is_in_stock(),
  101. 'backorders' => $wcp->get_backorders(),
  102. 'backorders_allowed' => $wcp->backorders_allowed(),
  103. 'backordered' => $wcp->backorders_allowed(),
  104. 'sold_individually' => $wcp->get_sold_individually(),
  105. 'weight' => $wcp->get_weight(),
  106. 'dimensions' => array(
  107. 'length' => $wcp->get_length(),
  108. 'width' => $wcp->get_width(),
  109. 'height' => $wcp->get_height(),
  110. ),
  111. 'shipping_required' => $wcp->needs_shipping(),
  112. 'shipping_taxable' => $wcp->is_shipping_taxable(),
  113. 'shipping_class' => $wcp->get_shipping_class(),
  114. 'shipping_class_id' => $wcp->get_shipping_class_id(),
  115. 'reviews_allowed' => $wcp->get_reviews_allowed(),
  116. 'average_rating' => $wcp->get_average_rating(),
  117. 'rating_count' => $wcp->get_review_count(),
  118. 'related_ids' => array_map( 'absint', array_values( wc_get_related_products( $wcp->get_id() ) ) ),
  119. 'upsell_ids' => array_map( 'absint', $wcp->get_upsell_ids() ),
  120. 'cross_sell_ids' => array_map( 'absint', $wcp->get_cross_sell_ids() ),
  121. 'parent_id' => $wcp->get_parent_id(),
  122. 'purchase_note' => wpautop( do_shortcode( wp_kses_post( $wcp->get_purchase_note() ) ) ),
  123. 'categories' => $this->get_taxonomy_terms( $wcp ),
  124. 'tags' => $this->get_taxonomy_terms( $wcp, 'tag' ),
  125. 'images' => $this->get_images( $wcp ),
  126. 'app_thumbnail' => $this->get_app_thumbnail($wcp),
  127. 'attributes' => $this->get_attributes( $wcp ),
  128. 'default_attributes' => $this->get_default_attributes( $wcp ),
  129. 'variations' => array(),
  130. 'grouped_products' => array(),
  131. 'menu_order' => $wcp->get_menu_order(),
  132. 'meta_data' => $wcp->get_meta_data(),
  133. 'rewards_message' => $rewards_message,
  134. 'addition_info_html' => (isset($addition_info_html) && !empty($addition_info_html))?$addition_info_html:'',
  135. 'featured_video' => $featured_video
  136. );
  137.  
  138. // Add variations to variable products.
  139. if ( $wcp->is_type( 'variable' ) && $wcp->has_child() ) {
  140. $data['variations'] = $wcp->get_children();
  141. }
  142.  
  143. // Add grouped products data.
  144. if ( $wcp->is_type( 'grouped' ) && $wcp->has_child() ) {
  145. $data['grouped_products'] = $wcp->get_children();
  146. }
  147. return $data;
  148. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement