id = 'afs_analytics'; $this->method_title = __( 'AFS Analytics', $this->text_domain); $this->method_description = __( 'AFS Analytics is a service that generates detailed statistics about the visitors to a website.', $this->text_domain); //delete undated config delete_option("woocommerce_afs_analytics_settings"); $this->init_form_fields(); self::$instance=$this; add_action( 'woocommerce_update_options_integration_' . $this->id, array( $this, 'process_admin_options' ) ); add_action( 'woocommerce_update_options_integration_' . $this->id, array( $this, 'get_new_options') ); add_action( 'woocommerce_thankyou', array( $this, 'afs_thankpage')); add_filter( 'woocommerce_get_return_url', array( $this, 'utm_nooverride' ) ); } public function sendmessage($message) { print ""; } public function get_new_options($settings) { if (!empty($_REQUEST)) { if (isset($_REQUEST['woocommerce_afs_analytics_afs_account'])) { $accountstr=$_REQUEST['woocommerce_afs_analytics_afs_account']; $accountstr=trim($accountstr); if (strcasecmp($accountstr,"NULL")==0) update_option('afs_account',""); else { $num=intval($accountstr); if ($num!=0) { $accountstr=sprintf("%08d",$num); update_option('afs_account',$accountstr); $this->sendmessage("update".$accountstr); } } } if (isset($_REQUEST['woocommerce_afs_analytics_afs_woocommerce_usertracking'])) { update_option( 'afs_woocommerce_usertracking',$_REQUEST['woocommerce_afs_analytics_afs_woocommerce_usertracking']); } } } public function init_form_fields() { $this->form_fields = array( 'afs_account' => array( 'title' => __( 'AFS Analytics Website ID', $this->text_domain), 'description' => __( 'Your AFS Analytics website ID', $this->text_domain ), 'type' => 'text', 'placeholder' => 'XXXXXXXX', 'default' => get_option( 'afs_account' ) // Backwards compat ), 'afs_woocommerce_usertracking' => array( 'title' => __( 'Tracking customer profile', $this->text_domain ), 'label' => __( 'Enable Tracking', $this->text_domain ), 'description' => __( 'Tracking Customer and User entire profile.', $this->text_domain ), 'type' => 'select', 'css' => 'min-height:40px;', 'options' => array( 0 => __( 'Disabled', 'afs' ), 1 => __( 'Enabled', 'afs' ), ), 'default' => intval(get_option( 'afs_woocommerce_usertracking' )) ) ); } private static function product_get_category_line( $_product ) { $category_str="none"; $variation_data = version_compare( WC_VERSION, '3.0', '<' ) ? $_product->variation_data : ( $_product->is_type( 'variation' ) ? wc_get_product_variation_attributes( $_product->get_id() ) : '' ); if ( is_array( $variation_data ) && ! empty( $variation_data ) ) { $category_str =esc_js( wc_get_formatted_variation( $variation_data, true ) ); } else { $out = array(); $categories = get_the_terms( $_product->get_id(), 'product_cat' ); if ( $categories ) { $category_str=""; foreach ( $categories as $category ) { $category_str.=$category->name; $category_str.=","; } } } return $category_str; } public function afs_thankpage($order_id) { $order = wc_get_order( $order_id ); $order_data = $order->get_data(); $order_status = $order_data['status']; $order_number = esc_js($order_data['number']); $shop_name=esc_js(get_bloginfo( 'name' ) ); //cancelled, refunded and failed pending, processing, on-hold, completed if (stristr($order_status, "failed")) return; if (stristr($order_status, "cancelled")) return; if (stristr($order_status, "refunded")) return; $order_id = $order_data['id']; $total = $order->get_total(); $total_tax= $order_data['total_tax']; $shipping=$order->get_total_shipping(); $order_currency = $order_data['currency']; $totalht=$total-$total_tax; print "\n"; } public static function get_instance() { return self::$instance; } public function utm_nooverride( $return_url ) { // We don't know if the URL already has the parameter so we should remove it just in case $return_url = remove_query_arg( 'utm_nooverride', $return_url ); // Now add the utm_nooverride query arg to the URL $return_url = add_query_arg( 'utm_nooverride', '1', $return_url ); return $return_url; } } endif;