Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* get product data */
- public function get_products_data($product_id){
- pgs_woo_api_hook_remove_tax_in_price_html();//Remove include tax in price html
- $wcp = wc_get_product($product_id);
- $wce = new WC_Product_External($product_id);
- $rewards_message = '';
- $is_reward_points_active = pgs_woo_api_is_reward_points_active();
- if($is_reward_points_active){
- $rewards_Product = new PGS_WOO_API_RewardsController();
- $rewards_msg = $rewards_Product->get_single_product_rewards_message($wcp);
- if(isset($rewards_msg) && !empty($rewards_msg)){
- $rewards_message = $rewards_msg;
- }
- }
- $get_price = $wcp->get_price();
- $regular_price = $wcp->get_regular_price();
- $sale_price = $wcp->get_sale_price();
- $wc_tax_enabled = wc_tax_enabled();
- $tax_status = 'none';
- $tax_class = '';
- if($wc_tax_enabled){
- $tax_price = wc_get_price_to_display( $wcp ); //tax
- $price_including_tax = wc_get_price_including_tax( $wcp );
- $price_excluding_tax = wc_get_price_excluding_tax( $wcp );
- $tax_status = $wcp->get_tax_status();
- $tax_class = $wcp->get_tax_class();
- }
- if($this->is_currency_switcher_active){
- $regular_price = $this->pgs_woo_api_update_currency_rate($regular_price);
- $sale_price = $this->pgs_woo_api_update_currency_rate($sale_price);
- $get_price = $this->pgs_woo_api_update_currency_rate($get_price);
- if($wc_tax_enabled){
- $tax_price = $this->pgs_woo_api_update_currency_rate($tax_price);
- $price_including_tax = $this->pgs_woo_api_update_currency_rate($price_including_tax);
- $price_excluding_tax = $this->pgs_woo_api_update_currency_rate($price_excluding_tax);
- }
- }
- $addition_info_html = '';
- $addition_info_data = array_filter( $wcp->get_attributes(), 'wc_attributes_array_filter_visible' );
- if ( $wcp && ( $wcp->has_attributes() || apply_filters( 'wc_product_enable_dimensions_display', $wcp->has_weight() || $wcp->has_dimensions() ) ) ) {
- $addition_info_html = $this->pgs_woo_api_get_addition_info_data($addition_info_data,$wcp);
- }
- $tax_price = (isset($tax_price))?$tax_price:'';
- $price_including_tax = (isset($price_including_tax))?$price_including_tax:'';
- $price_excluding_tax = (isset($price_excluding_tax))?$price_excluding_tax:'';
- $featured_video = (object)array();
- if($this->is_yith_featured_video_active){
- $featured_video = $this->pgs_woo_api_get_yith_featured_video($wcp,$product_id);
- }
- $data = array(
- 'id' => $wcp->get_id(),
- 'name' => $wcp->get_name(),
- 'slug' => $wcp->get_slug(),
- 'permalink' => $wcp->get_permalink(),
- 'date_created' => wc_rest_prepare_date_response( $wcp->get_date_created(), false ),
- 'date_created_gmt' => wc_rest_prepare_date_response( $wcp->get_date_created() ),
- 'date_modified' =>wc_rest_prepare_date_response( $wcp->get_date_modified(), false ),
- 'date_modified_gmt' => wc_rest_prepare_date_response( $wcp->get_date_modified() ),
- 'type' => $wcp->get_type(),
- 'status' => $wcp->get_status(),
- 'featured' => $wcp->get_featured(),
- 'catalog_visibility' => $wcp->get_catalog_visibility(),
- 'description' => wpautop($wcp->get_description()),
- 'description' => wpautop($wcp->get_description()),
- 'short_description' => $wcp->get_short_description(),
- 'sku' => $wcp->get_sku(),
- 'price' => $get_price,
- 'tax_price'=> $tax_price, //tax
- 'price_excluding_tax' => $price_excluding_tax,
- 'price_including_tax' => $price_including_tax,
- 'regular_price' => $regular_price,
- 'sale_price' => $sale_price,
- 'date_on_sale_from' => wc_rest_prepare_date_response($wcp->get_date_on_sale_from()),
- 'date_on_sale_from_gmt' => wc_rest_prepare_date_response($wcp->get_date_on_sale_from()),
- 'date_on_sale_to' => wc_rest_prepare_date_response($wcp->get_date_on_sale_to()),
- 'date_on_sale_to_gmt' => wc_rest_prepare_date_response($wcp->get_date_on_sale_to()),
- 'price_html' => $wcp->get_price_html(),
- 'on_sale' => $wcp->is_on_sale(),
- 'purchasable' => $wcp->is_purchasable(),
- 'total_sales' => $wcp->get_total_sales(),
- 'virtual' => $wcp->get_virtual(),
- 'downloadable' => $wcp->get_downloadable(),
- 'downloads' => $wcp->get_downloads(),
- 'download_limit' => $wcp->get_download_limit(),
- 'download_expiry' => $wcp->get_download_expiry(),
- 'external_url' => $wce->get_product_url(),
- 'button_text' => $wce->get_button_text(),
- 'tax_status' => $tax_status,
- 'tax_class' => $tax_class,
- 'manage_stock' => $wcp->get_manage_stock(),
- 'stock_quantity' => $wcp->get_stock_quantity(),
- 'in_stock' => $wcp->is_in_stock(),
- 'backorders' => $wcp->get_backorders(),
- 'backorders_allowed' => $wcp->backorders_allowed(),
- 'backordered' => $wcp->backorders_allowed(),
- 'sold_individually' => $wcp->get_sold_individually(),
- 'weight' => $wcp->get_weight(),
- 'dimensions' => array(
- 'length' => $wcp->get_length(),
- 'width' => $wcp->get_width(),
- 'height' => $wcp->get_height(),
- ),
- 'shipping_required' => $wcp->needs_shipping(),
- 'shipping_taxable' => $wcp->is_shipping_taxable(),
- 'shipping_class' => $wcp->get_shipping_class(),
- 'shipping_class_id' => $wcp->get_shipping_class_id(),
- 'reviews_allowed' => $wcp->get_reviews_allowed(),
- 'average_rating' => $wcp->get_average_rating(),
- 'rating_count' => $wcp->get_review_count(),
- 'related_ids' => array_map( 'absint', array_values( wc_get_related_products( $wcp->get_id() ) ) ),
- 'upsell_ids' => array_map( 'absint', $wcp->get_upsell_ids() ),
- 'cross_sell_ids' => array_map( 'absint', $wcp->get_cross_sell_ids() ),
- 'parent_id' => $wcp->get_parent_id(),
- 'purchase_note' => wpautop( do_shortcode( wp_kses_post( $wcp->get_purchase_note() ) ) ),
- 'categories' => $this->get_taxonomy_terms( $wcp ),
- 'tags' => $this->get_taxonomy_terms( $wcp, 'tag' ),
- 'images' => $this->get_images( $wcp ),
- 'app_thumbnail' => $this->get_app_thumbnail($wcp),
- 'attributes' => $this->get_attributes( $wcp ),
- 'default_attributes' => $this->get_default_attributes( $wcp ),
- 'variations' => array(),
- 'grouped_products' => array(),
- 'menu_order' => $wcp->get_menu_order(),
- 'meta_data' => $wcp->get_meta_data(),
- 'rewards_message' => $rewards_message,
- 'addition_info_html' => (isset($addition_info_html) && !empty($addition_info_html))?$addition_info_html:'',
- 'featured_video' => $featured_video
- );
- // Add variations to variable products.
- if ( $wcp->is_type( 'variable' ) && $wcp->has_child() ) {
- $data['variations'] = $wcp->get_children();
- }
- // Add grouped products data.
- if ( $wcp->is_type( 'grouped' ) && $wcp->has_child() ) {
- $data['grouped_products'] = $wcp->get_children();
- }
- return $data;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement