Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class Wpestate_Global_Payments {
- public $stripe_payments;
- public $is_woo;
- public $userID;
- public $user_email;
- function __construct() {
- $this->is_woo = wprentals_get_option('wp_estate_enable_woo','') ;
- $current_user = wp_get_current_user();
- $this->userID = $current_user->ID;
- $this->user_email = $current_user->user_email;
- add_filter( 'woocommerce_cart_item_permalink','__return_false');
- add_action( 'wp_ajax_wpestate_woo_pay', array( $this, 'wpestate_woo_pay') );
- add_action( 'wp_ajax_mopriv_wpestate_woo_pay', array( $this, 'wpestate_woo_pay') );
- add_filter( 'woocommerce_thankyou_order_received_text', array($this, 'wpestate_woocommerce_thankyou_order_received_text'),10,2 );
- add_action( 'woocommerce_before_single_product', array($this, 'wpestate_product_redirect') );
- add_action( 'woocommerce_product_query', array($this, 'wpestate_custom_pre_get_posts_query' ));
- add_action( 'woocommerce_order_status_completed', array($this, 'wpestate_payment_complete') );
- add_action( 'woocommerce_order_status_processing', array($this, 'wpestate_payment_complete') );
- //EVERYTHING WORKS ONLY WHEN THE 3 LINES BELOW ARE COMMENTED OUT
- //add_action( 'woocommerce_thankyou', array($this,'order_attach') );
- //add_filter( 'woocommerce_checkout_fields', array($this,'custom_override_checkout_fields') );
- //add_filter('woocommerce_create_account_default_checked', '__return_true');
- // END
- require_once WPESTATE_PLUGIN_PATH.'classes/wpestate_stripe_payments.php';
- $this->stripe_payments=new Wpestate_stripe_payments();
- }
- function custom_override_checkout_fields( $fields ) {
- unset($fields['billing']['billing_company']);
- unset($fields['billing']['billing_address_1']);
- unset($fields['billing']['billing_address_2']);
- unset($fields['billing']['billing_city']);
- unset($fields['billing']['billing_postcode']);
- unset($fields['billing']['billing_country']);
- unset($fields['billing']['billing_state']);
- return $fields;
- }
- function order_attach( $order_id ) {
- $current_user = wp_get_current_user();
- $user_id = $current_user->ID;
- $order = new WC_Order($order_id);
- $products = $order->get_items();
- foreach($products as $prod){
- $product_id = $prod['product_id'];
- $wpestate_propid = intval( get_post_meta( $product_id, '_prop_id', true) );
- $bookid = intval( get_post_meta( $product_id, '_booking_id', true) );
- $invoice_no = intval( get_post_meta( $product_id, '_invoice_id', true) );
- $depozit = floatval ( get_post_meta( $product_id, '_price', true) );
- $arg = array(
- 'ID' => $bookid,
- 'post_author' => $user_id,
- );
- wp_update_post( $arg );
- update_post_meta($invoice_no, 'buyer_id', $the_id);
- $owner_id = wpsestate_get_author($wpestate_propid);
- $receiver = get_userdata($user_id);
- $receiver_email = $receiver->user_email;
- $receiver_login = $receiver->user_login;
- $from = $owner_id;
- $to = $user_id;
- $subject = esc_html__( 'New Invoice','wprentals');
- $description = esc_html__( 'A new invoice was generated for your booking request','wprentals');
- wpestate_add_to_inbox($user_id,$user_id,$to,$subject,$description,1);
- wpestate_send_booking_email('newinvoice',$receiver_email);
- }
- }
- function wpestate_woocommerce_thankyou_order_received_text ( $thank_you_msg,$order_id ) {
- $order = wc_get_order( $order_id );
- $products = $order->get_items();
- foreach($products as $prod){
- $product_id = $prod['product_id'];
- $product_bought = wc_get_product( $product_id );
- $is_submit = get_post_meta( $product_id, '_is_submit', true );
- $listing_id = get_post_meta( $product_id, '_prop_id', true );
- if($is_submit==1){
- $url= wpestate_get_template_link('user_dashboard.php') ;
- $thank_you_msg.='</br><a href="'.$url.'" class="return_woo_button " >'.esc_html__('Return to Dashboard','wprentals-core').'</a>';
- }else{
- $url = wpestate_get_template_link('user_dashboard_my_reservations.php');
- $thank_you_msg.='</br><a href="'.$url.'" class="return_woo_button " >'.esc_html__('Return to My Reservations','wprentals-core').'</a>';
- }
- }
- return $thank_you_msg;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement