get_settings( 'fcm_server_key' ); $order = new WC_Order( $order_id ); if ( ! empty( $fcm_key ) && APPMAKER_WC::$api->get_settings( 'enable_order_push', true ) ) { $fcm = new Appmaker_WC_FCM_Helper( $fcm_key ); $user_id = $order->user_id; if ( class_exists( 'WC_Seq_Order_Number' ) ) { $display_order_id = $order->order_number; } elseif ( method_exists( $order, 'get_id' ) ) { $display_order_id = $order->get_id(); } else { $display_order_id = $order->id; } if ( ! empty( $user_id ) && get_user_meta( $user_id, 'appmaker_wc_user_login_from_app' ) ) { sprintf( __( 'Order updated #%s', 'appmaker-woocommerce-mobile-app-manager' ), $display_order_id); $fcm->setTopic( "user-$user_id" ) ->setMessage( sprintf( __( 'Order updated #%s', 'appmaker-woocommerce-mobile-app-manager' ), $display_order_id), sprintf( __( 'Order status changed to %s', 'appmaker-woocommerce-mobile-app-manager' ), $order->get_status())) ->setAction( array( 'type' => 'OPEN_ORDER', 'params' => array( 'orderId' => $order_id, ), ) ) ->send(); } } if( get_post_meta( self::get_id( $order ), 'from_app' ) && ! get_post_meta( self::get_id( $order ), 'send_order_analytics_request' )) { $this->send_order_analytics_request( $order ); add_post_meta( self::get_id($order), 'send_order_analytics_request', true ); } } public static function get_id( $object ){ if ( method_exists( $object, 'get_id' ) ){ return $object->get_id(); }else{ return $object->id; } } public function hook_stripe_enable_headers() { $output = ' '; echo $output; } public function hook_payment_footer() { $gateway = isset( $_GET['payment_gateway'] ) ? $_GET['payment_gateway'] : ''; $output = ' '; echo $output; } /** * Load the persistent cart make cart sync with app * * @return void|bool */ public function load_persistent_cart() { global $current_user; if ( ! $current_user ) { return false; } $saved_cart = get_user_meta( $current_user->ID, '_woocommerce_persistent_cart', true ); if ( $saved_cart && is_array( $saved_cart ) && isset( $saved_cart['cart'] ) ) { WC()->session->set( 'cart', $saved_cart['cart'] ); } return true; } /** * @param WC_Order $order */ public function send_order_analytics_request( $order ) { $path_to_appmaker = 'https://us-central1-appmaker-woo-analytics.cloudfunctions.net/addOrder'; $store_location = wc_get_base_location(); $options = get_option( 'appmaker_wc_settings' ); $country = $order->get_shipping_country(); $order_completed_date = $order->get_date_completed(); if(!empty($order)) { $fields = array( 'value' => array( 'url' => get_home_url(), 'project_id' => isset( $options['project_id'] ) ? $options['project_id'] : '', 'order_date' => ! empty( $order_completed_date ) ? $order_completed_date->date( 'd/m/Y' ) : date('d/m/Y'), 'order_currency' => $order->get_currency(), 'order_total' => $order->get_total(), 'shop_country' => isset( $store_location['country'] ) ? $store_location['country'] : null, 'customer_country' => ! empty( $country ) ? $country : $order->get_billing_country(), 'products_count' => $order->get_item_count() ) ); }; $headers = array( // 'Authorization:key=' . $api_secret, 'Content-Type:application/json' ); $data = json_encode( $fields ); $ch = curl_init(); curl_setopt( $ch, CURLOPT_URL, $path_to_appmaker ); curl_setopt( $ch, CURLOPT_POST, true ); curl_setopt( $ch, CURLOPT_HTTPHEADER, $headers ); curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true ); curl_setopt( $ch, CURLOPT_SSL_VERIFYPEER, false ); curl_setopt( $ch, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4 ); curl_setopt( $ch, CURLOPT_POSTFIELDS, $data ); $res = curl_exec( $ch ); curl_close( $ch ); } } new APPMAKER_WC_General_hooks();