Skip to content

Commit

Permalink
Merge pull request #88 from thrivedesk/fix/woocommerce-products-issue
Browse files Browse the repository at this point in the history
Fix/woocommerce products issue
  • Loading branch information
shamsbd71 authored May 16, 2024
2 parents cc83b2c + 967634d commit e540219
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 34 deletions.
2 changes: 1 addition & 1 deletion includes/views/partials/integrations.php
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
'connected' => $wppostsync->get_plugin_data( 'connected' ),
],
[
'namespace' => 'wp-marketing-automations',
'namespace' => 'autonami',
'name' => __( 'FunnelKit', 'thrivedesk' ),
'image' => 'autonami.png',
'category' => 'CRM',
Expand Down
6 changes: 5 additions & 1 deletion readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Contributors: thrivedesk
Tags: helpdesk, support ticket, livechat, support plugin, ticket system chat, chatbot, knowledge base, support, help center, customer care, woocommerce, surecart, freemius, thrivedesk
Requires at least: 4.9
Tested up to: 6.4
Stable Tag: 2.0.2
Stable Tag: 2.0.3
Requires PHP: 5.5
License: GNU General Public License v2.0 or later

Expand Down Expand Up @@ -232,6 +232,10 @@ Privacy is our utmost priority, and we designed ThriveDesk in a way that aligned
- Easy setup: Setup your Shared Inbox in less than a minute.

== Changelog ==
= 2.0.3 =
- Fix: WooCommerce product data missing issue
- Fix : FunnelKit namespace issue

= 2.0.2 =
- Update: Enhanced WooCommerce integration

Expand Down
14 changes: 13 additions & 1 deletion src/Api.php
Original file line number Diff line number Diff line change
Expand Up @@ -227,12 +227,18 @@ public function get_woocommerce_product_list() {

foreach ( $products as $product_id ) {
$product = wc_get_product( $product_id );
$thumbnail_id = get_post_thumbnail_id( $product_id );
$image_src_array = [];

if( $thumbnail_id){
$image_src_array = wp_get_attachment_image_src( $thumbnail_id );
}

$productInfo = array(
"product_id" => $product_id,
"title" => $product->get_name(),
"product_permalink" => get_permalink( $product_id ),
"image" => wp_get_attachment_image_src( get_post_thumbnail_id( $product_id ) )[0],
"image" => is_array( $image_src_array ) && ! empty( $image_src_array ) ? $image_src_array[0] : '',
"sale_price" => get_woocommerce_currency_symbol() . $product->get_regular_price(),
"stock" => ( 'instock' === $product->get_stock_status() ) ? 'In Stock' : 'Out of Stock',
);
Expand Down Expand Up @@ -270,6 +276,12 @@ public function wc_order_add_new_item( string $order_id, $item ) {
$item->set_product_id( $product->id );
$item->set_subtotal( $product->price ?? 0 );
$item->set_total( $product->price * $this->quantity ?? 0 );

// if(is_plugin_active('wt-woocommerce-sequential-order-numbers-pro/wt-advanced-order-number-pro.php'))
// {
// if customer use this type of plugin, wc doesn't have the same order number as the plugin.
// }

$order = wc_get_order( $order_id );
$order->add_item( $item );
$order->calculate_totals();
Expand Down
59 changes: 30 additions & 29 deletions src/Plugins/WooCommerce.php
Original file line number Diff line number Diff line change
Expand Up @@ -342,8 +342,8 @@ public function get_order_items( $order ): array {
}

foreach ( $items as $item ) {

$product_id = $item->get_variation_id() ?? $item->get_product_id();
$productInfo = [];
$product_id = $item->get_variation_id() ? $item->get_variation_id() : $item->get_product_id();
$product = wc_get_product($product_id);

if ( class_exists( 'WC_Subscriptions_Product' ) && WC_Subscriptions_Product::is_subscription( $product ) ) {
Expand All @@ -357,33 +357,34 @@ public function get_order_items( $order ): array {
"expiration_date" => WC_Subscriptions_Product::get_expiration_date( $product ),
];
}

$productInfo = array(
"product_id" => $product_id,
"title" => $product->get_name(),
"product_permalink" => get_permalink($product_id),
"quantity" => $item["quantity"],
"total_tax" => $this->get_formated_amount( (float) $item["total_tax"] ),
"image" => wp_get_attachment_image_src( get_post_thumbnail_id($product_id) )[0],
"type" => $product->get_type(),
"status" => $product->get_status(),
"sku" => $product->get_sku(),
"price" => $this->get_formated_amount( (float) $item["subtotal"] ),
"regular_price" => $this->get_formated_amount( (float) $product->get_regular_price() ),
"sale_price" => $this->get_formated_amount( (float) $product->get_sale_price() ),
"tax_status" => $product->get_tax_status(),
"stock" => $product->get_stock_quantity(),
"stock_status" => $product->get_stock_status(),
"weight" => $product->get_weight(),
"discount" => $this->get_formated_amount( (float) $item->get_total() ),
"subscription" => $subscription_info,

);

$subscription_info = [];

if ( array_key_exists( $item->get_id(), $license_info ) ) {
$productInfo['license'] = $license_info[ $item->get_id() ];

if($product){
$productInfo = array(
"product_id" => $product_id,
"title" => $product->get_name(),
"product_permalink" => get_permalink($product_id),
"quantity" => $item["quantity"],
"total_tax" => $this->get_formated_amount( (float) $item["total_tax"] ),
"image" => wp_get_attachment_image_src( get_post_thumbnail_id($product_id) )[0],
"type" => $product->get_type(),
"status" => $product->get_status(),
"sku" => $product->get_sku(),
"price" => $this->get_formated_amount( (float) $item["subtotal"] ),
"regular_price" => $this->get_formated_amount( (float) $product->get_regular_price() ),
"sale_price" => $this->get_formated_amount( (float) $product->get_sale_price() ),
"tax_status" => $product->get_tax_status(),
"stock" => $product->get_stock_quantity(),
"stock_status" => $product->get_stock_status(),
"weight" => $product->get_weight(),
"discount" => $this->get_formated_amount( (float) $item->get_total() ),
"subscription" => $subscription_info,
);

$subscription_info = [];

if ( array_key_exists( $item->get_id(), $license_info ) ) {
$productInfo['license'] = $license_info[ $item->get_id() ];
}
}

array_push( $download_item, $productInfo );
Expand Down
4 changes: 2 additions & 2 deletions thrivedesk.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* Description: Live Chat, Help Desk & Knowledge Base plugin for WordPress
* Plugin URI: https://www.thrivedesk.com/?utm_source=wp-plugins&utm_campaign=plugin-uri&utm_medium=wp-dash
* Tags: live chat, helpdesk, free live chat, knowledge base, thrivedesk
* Version: 2.0.2
* Version: 2.0.3
* Author: ThriveDesk
* Author URI: https://profiles.wordpress.org/thrivedesk/
* Text Domain: thrivedesk
Expand Down Expand Up @@ -51,7 +51,7 @@ final class ThriveDesk
*
* @var string
*/
public $version = '2.0.2';
public $version = '2.0.3';

/**
* The single instance of this class
Expand Down

0 comments on commit e540219

Please sign in to comment.