Skip to content

Commit

Permalink
Merge pull request #52 from newfold-labs/remove-bad-cart-hook
Browse files Browse the repository at this point in the history
Remove bad add to cart event
  • Loading branch information
circlecube authored Dec 12, 2023
2 parents 3bdc70e + af5d020 commit fe15524
Showing 1 changed file with 27 additions and 46 deletions.
73 changes: 27 additions & 46 deletions includes/Listeners/Commerce.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ public function register_hooks() {
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_action('woocommerce_cart_updated',array( $this, 'site_product_add_to_cart_data'));
add_filter('woocommerce_thankyou', array( $this, 'thank_you_page'));
add_filter( 'pre_update_option_nfd_ecommerce_captive_flow_razorpay', array( $this, 'razorpay_connection' ), 10, 2 );
add_filter( 'pre_update_option_nfd_ecommerce_captive_flow_shippo', array( $this, 'shippo_connection' ), 10, 2 );
Expand Down Expand Up @@ -88,55 +87,37 @@ public function orders_count( $data ) {
*
* @return void
*/
public function site_cart_views() {
public function site_cart_views() {
if( WC()->cart->get_cart_contents_count() !== 0){
$data = array(
$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(
public function checkout_views() {
$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
);
}

/**
* Added to cart, send data to Hiive
*
* @return void
*/
public function site_product_add_to_cart_data() {
$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_product_add_to_cart",
$this->push(
"site_checkout_view",
$data
);
}
Expand All @@ -145,23 +126,23 @@ public function site_product_add_to_cart_data() {
* Thank you page, send data to Hiive
*
* @param int $order_id
*
*
* @return void
*/
public function thank_you_page($order_id ) {
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(
$data = array(
"product_count" => $qty,
"order_total" => floatval($order->get_total()),
"currency" => get_woocommerce_currency(),
);

$this->push(
"site_thank_you_view",
$data
Expand All @@ -177,14 +158,14 @@ public function thank_you_page($order_id ) {
* @return string The new option value
*/
public function razorpay_connection( $new_option, $old_option ) {
$url = is_ssl() ? "https://" : "http://";
$url = is_ssl() ? "https://" : "http://";
$url .= $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
$data = array(
$data = array(
"label_key" => "provider",
"provider" => "razorpay",
"page" => $url
);
if ( $new_option !== $old_option && ! empty( $new_option ) ) {
if ( $new_option !== $old_option && ! empty( $new_option ) ) {
$this->push(
"payment_connected",
$data
Expand All @@ -203,14 +184,14 @@ public function razorpay_connection( $new_option, $old_option ) {
* @return string The new option value
*/
public function shippo_connection( $new_option, $old_option ) {
$url = is_ssl() ? "https://" : "http://";
$url = is_ssl() ? "https://" : "http://";
$url .= $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
$data = array(
$data = array(
"label_key" => "provider",
"provider" => "shippo",
"page" => $url
);
if ( $new_option !== $old_option && ! empty( $new_option ) ) {
if ( $new_option !== $old_option && ! empty( $new_option ) ) {
$this->push(
"shipping_connected",
$data
Expand All @@ -229,14 +210,14 @@ public function shippo_connection( $new_option, $old_option ) {
* @return string The new option value
*/
public function stripe_connection( $new_option, $old_option ) {
$url = is_ssl() ? "https://" : "http://";
$url = is_ssl() ? "https://" : "http://";
$url .= $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
$data = array(
$data = array(
"label_key" => "provider",
"provider" => "stripe",
"page" => $url
);
if ( $new_option !== $old_option && ! empty( $new_option ) ) {
if ( $new_option !== $old_option && ! empty( $new_option ) ) {
$this->push(
"payment_connected",
$data
Expand All @@ -255,14 +236,14 @@ public function stripe_connection( $new_option, $old_option ) {
* @return string The new option value
*/
public function paypal_connection( $new_option, $old_option ) {
$url = is_ssl() ? "https://" : "http://";
$url = is_ssl() ? "https://" : "http://";
$url .= $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
$data = array(
$data = array(
"label_key" => "provider",
"provider" => "yith_paypal",
"page" => $url
);
if ( $new_option !== $old_option && ! empty( $new_option ) ) {
if ( $new_option !== $old_option && ! empty( $new_option ) ) {
$this->push(
"payment_connected",
$data
Expand All @@ -271,7 +252,7 @@ public function paypal_connection( $new_option, $old_option ) {

return $new_option;
}

/**
* Ecomdash connection, send data to Hiive
*
Expand Down

0 comments on commit fe15524

Please sign in to comment.