Advertisement
Guest User

Untitled

a guest
Nov 10th, 2019
506
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 5.07 KB | None | 0 0
  1. <?php
  2.  
  3. class Wpestate_Global_Payments {
  4.    
  5.     public $stripe_payments;
  6.     public $is_woo;  
  7.     public $userID;
  8.     public $user_email;
  9.    
  10.     function __construct() {
  11.        
  12.         $this->is_woo   =   wprentals_get_option('wp_estate_enable_woo','') ;
  13.         $current_user   =   wp_get_current_user();
  14.  
  15.         $this->userID                  =    $current_user->ID;
  16.         $this->user_email              =    $current_user->user_email;
  17.         add_filter( 'woocommerce_cart_item_permalink','__return_false');
  18.         add_action( 'wp_ajax_wpestate_woo_pay',                 array( $this, 'wpestate_woo_pay') );
  19.         add_action( 'wp_ajax_mopriv_wpestate_woo_pay',          array( $this, 'wpestate_woo_pay') );
  20.         add_filter( 'woocommerce_thankyou_order_received_text', array($this, 'wpestate_woocommerce_thankyou_order_received_text'),10,2 );
  21.         add_action( 'woocommerce_before_single_product',        array($this, 'wpestate_product_redirect') );
  22.         add_action( 'woocommerce_product_query',                array($this, 'wpestate_custom_pre_get_posts_query' ));  
  23.         add_action( 'woocommerce_order_status_completed',       array($this, 'wpestate_payment_complete') );
  24.         add_action( 'woocommerce_order_status_processing',      array($this, 'wpestate_payment_complete') );
  25.        
  26. //EVERYTHING WORKS ONLY WHEN THE 3 LINES BELOW ARE COMMENTED OUT
  27. //add_action( 'woocommerce_thankyou', array($this,'order_attach') );
  28. //add_filter( 'woocommerce_checkout_fields', array($this,'custom_override_checkout_fields') );
  29. //add_filter('woocommerce_create_account_default_checked', '__return_true');
  30. // END
  31.  
  32.         require_once WPESTATE_PLUGIN_PATH.'classes/wpestate_stripe_payments.php';
  33.         $this->stripe_payments=new Wpestate_stripe_payments();
  34.        
  35.     }
  36.    
  37.    
  38.     function custom_override_checkout_fields( $fields ) {
  39.        
  40.         unset($fields['billing']['billing_company']);
  41.         unset($fields['billing']['billing_address_1']);
  42.         unset($fields['billing']['billing_address_2']);
  43.         unset($fields['billing']['billing_city']);
  44.         unset($fields['billing']['billing_postcode']);
  45.         unset($fields['billing']['billing_country']);
  46.         unset($fields['billing']['billing_state']);
  47.  
  48.          return $fields;
  49.     }
  50.  
  51.    
  52.     function order_attach( $order_id ) {
  53.         $current_user   =   wp_get_current_user();
  54.         $user_id        =   $current_user->ID;
  55.  
  56.         $order      =   new WC_Order($order_id);
  57.         $products   =   $order->get_items();
  58.  
  59.         foreach($products as $prod){
  60.             $product_id         =   $prod['product_id'];
  61.  
  62.             $wpestate_propid    =  intval(  get_post_meta( $product_id, '_prop_id', true) );
  63.             $bookid             =  intval(  get_post_meta( $product_id, '_booking_id', true) );
  64.             $invoice_no         =  intval( get_post_meta( $product_id, '_invoice_id', true) );
  65.             $depozit            =  floatval ( get_post_meta( $product_id, '_price', true) );  
  66.  
  67.  
  68.             $arg = array(
  69.                 'ID' => $bookid,
  70.                 'post_author' => $user_id,
  71.             );
  72.             wp_update_post( $arg );
  73.  
  74.             update_post_meta($invoice_no, 'buyer_id', $the_id);
  75.  
  76.             $owner_id          =   wpsestate_get_author($wpestate_propid);
  77.             $receiver          =   get_userdata($user_id);
  78.             $receiver_email    =   $receiver->user_email;
  79.             $receiver_login    =   $receiver->user_login;
  80.             $from              =   $owner_id;
  81.             $to                =   $user_id;
  82.             $subject           =   esc_html__( 'New Invoice','wprentals');
  83.             $description       =   esc_html__( 'A new invoice was generated for your booking request','wprentals');
  84.             wpestate_add_to_inbox($user_id,$user_id,$to,$subject,$description,1);
  85.             wpestate_send_booking_email('newinvoice',$receiver_email);
  86.         }
  87.  
  88.     }
  89.    
  90.    
  91.     function wpestate_woocommerce_thankyou_order_received_text ( $thank_you_msg,$order_id ) {
  92.  
  93.         $order = wc_get_order( $order_id );
  94.         $products   =   $order->get_items();
  95.  
  96.         foreach($products as $prod){
  97.             $product_id         =   $prod['product_id'];
  98.             $product_bought     =   wc_get_product( $product_id );
  99.             $is_submit          =   get_post_meta( $product_id, '_is_submit', true );
  100.             $listing_id         =   get_post_meta( $product_id, '_prop_id', true );
  101.              
  102.             if($is_submit==1){
  103.                 $url= wpestate_get_template_link('user_dashboard.php') ;
  104.                 $thank_you_msg.='</br><a href="'.$url.'" class="return_woo_button  " >'.esc_html__('Return to Dashboard','wprentals-core').'</a>';
  105.                
  106.             }else{
  107.                 $url = wpestate_get_template_link('user_dashboard_my_reservations.php');
  108.                 $thank_you_msg.='</br><a href="'.$url.'" class="return_woo_button  " >'.esc_html__('Return to My Reservations','wprentals-core').'</a>';
  109.             }
  110.            
  111.         }
  112.        
  113.        
  114.  
  115.     return $thank_you_msg;
  116. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement