Skip to content

Commit

Permalink
Merge pull request #28 from sumathi3399/PRESS4-300_Analytics_data
Browse files Browse the repository at this point in the history
PRESS4-300 analytics data
  • Loading branch information
circlecube authored Sep 12, 2023
2 parents 3bacb2a + 2eaff2f commit 0c83bfd
Show file tree
Hide file tree
Showing 3 changed files with 388 additions and 14 deletions.
163 changes: 154 additions & 9 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

79 changes: 79 additions & 0 deletions src/Listeners/Commerce.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ public function register_hooks() {
add_action( 'woocommerce_order_status_processing', array( $this, 'on_payment' ), 10, 2 );
add_filter( 'newfold_wp_data_module_cron_data_filter', array( $this, 'products_count' ) );
add_filter( 'newfold_wp_data_module_cron_data_filter', array( $this, 'orders_count' ) );
add_filter('woocommerce_before_cart', array( $this, 'site_cart_views'));
add_filter('woocommerce_before_checkout_form', array( $this, 'checkout_views'));
add_filter('woocommerce_thankyou', array( $this, 'thank_you_page'));
}

/**
Expand Down Expand Up @@ -70,4 +73,80 @@ public function orders_count( $data ) {

return $data;
}

/**
* Site Cart View, send data to Hiive
*
* @return void
*/
public function site_cart_views() {
if( WC()->cart->get_cart_contents_count() !== 0){
$data = array(
"category" => "commerce",
"data" => array(
"product_count" => WC()->cart->get_cart_contents_count(),
"cart_total" => floatval(WC()->cart->get_cart_contents_total()),
"currency" => get_woocommerce_currency(),
),
);

$this->push(
"site_cart_view",
$data
);
}
}


/**
* Checkout view, send data to Hiive
*
* @return void
*/
public function checkout_views() {
$data = array(
"category" => "commerce",
"data" => array(
"product_count" => WC()->cart->get_cart_contents_count(),
"cart_total" => floatval(WC()->cart->get_cart_contents_total()),
"currency" => get_woocommerce_currency(),
"payment_method" => WC()->payment_gateways()->get_available_payment_gateways()
),
);

$this->push(
"site_checkout_view",
$data
);
}

/**
* Thank you page, send data to Hiive
*
* @param int $order_id
*
* @return void
*/
public function thank_you_page($order_id ) {
$order = wc_get_order( $order_id );
$line_items = $order->get_items();

// This loops over line items
foreach ( $line_items as $item ) {
$qty = $item['qty'];
}
$data = array(
"category" => "commerce",
"data" => array(
"product_count" => $qty,
"order_total" => floatval($order->get_total()),
"currency" => get_woocommerce_currency(),
),
);

$this->push(
"site_thank_you_view",
$data
);
}
}
Loading

0 comments on commit 0c83bfd

Please sign in to comment.