From e66288b3f3abfff6a293febd0f9698e4723dc176 Mon Sep 17 00:00:00 2001 From: bhavik Date: Fri, 14 Jul 2017 10:40:28 +0530 Subject: [PATCH] WooCommerce V3.x.x Compatible In this commit we have fixed the warning displyed on the Print screens, on the admin side it was shwoing notice on the WC orders columns. Also, when customer click on the print view from the email then the notices was displayed Also, the My Account page was showing the notices on the Print All these notices has been fixed. It is also made compatible with the latest WC version as well as with Older version --- includes/class-wcdn-print.php | 8 +++- includes/class-wcdn-theme.php | 21 +++++++---- includes/class-wcdn-writepanel.php | 4 +- includes/wcdn-template-functions.php | 50 +++++++++++++++++-------- templates/print-order/print-content.php | 18 ++++++++- 5 files changed, 74 insertions(+), 27 deletions(-) diff --git a/includes/class-wcdn-print.php b/includes/class-wcdn-print.php index acaef37..64d133a 100644 --- a/includes/class-wcdn-print.php +++ b/includes/class-wcdn-print.php @@ -388,14 +388,18 @@ private function populate_orders() { foreach( $posts as $post ) { $order = new WC_Order( $post->ID ); + $wdn_order_id = ( version_compare( get_option( 'woocommerce_version' ), '3.0.0', ">=" ) ) ? $order->get_id() : $order->id; // Logged in users - if( is_user_logged_in() && ( !current_user_can( 'edit_shop_orders' ) && !current_user_can( 'view_order', $order->id ) ) ) { + if( is_user_logged_in() && ( !current_user_can( 'edit_shop_orders' ) && !current_user_can( 'view_order', $wdn_order_id ) ) ) { $this->orders = null; return false; } + $wdn_order_billing_id = ( version_compare( get_option( 'woocommerce_version' ), '3.0.0', ">=" ) ) ? $order->get_billing_email() : $order->billing_email; + + // An email is required for not logged in users - if( !is_user_logged_in() && ( empty( $this->order_email ) || strtolower( $order->billing_email ) != $this->order_email ) ) { + if( !is_user_logged_in() && ( empty( $this->order_email ) || strtolower( $wdn_order_billing_id ) != $this->order_email ) ) { $this->orders = null; return false; } diff --git a/includes/class-wcdn-theme.php b/includes/class-wcdn-theme.php index b41c90d..1475265 100644 --- a/includes/class-wcdn-theme.php +++ b/includes/class-wcdn-theme.php @@ -51,8 +51,9 @@ public function add_scripts() { public function create_print_button_account_page( $actions, $order ) { if( get_option( 'wcdn_print_button_on_my_account_page' ) == 'yes' ) { // Add the print button + $wdn_order_id = ( version_compare( get_option( 'woocommerce_version' ), '3.0.0', ">=" ) ) ? $order->get_id() : $order->id; $actions['print'] = array( - 'url' => wcdn_get_print_link( $order->id, $this->get_template_type( $order ) ), + 'url' => wcdn_get_print_link( $wdn_order_id, $this->get_template_type( $order ) ), 'name' => __( 'Print', 'woocommerce-delivery-notes' ) ); } @@ -64,7 +65,7 @@ public function create_print_button_account_page( $actions, $order ) { */ public function create_print_button_order_page( $order_id ) { $order = new WC_Order( $order_id ); - + $wdn_order_billing_id = ( version_compare( get_option( 'woocommerce_version' ), '3.0.0', ">=" ) ) ? $order->get_billing_email() : $order->billing_email; // Output the button only when the option is enabled if( get_option( 'wcdn_print_button_on_view_order_page' ) == 'yes' ) { // Default button for all pages and logged in users @@ -80,10 +81,10 @@ public function create_print_button_order_page( $order_id ) { // Thank you page if( is_order_received_page() && !is_user_logged_in() ) { // Don't output the butten when there is no email - if( !$order->billing_email ) { + if( !$wdn_order_billing_id ) { return; } - $print_url = wcdn_get_print_link( $order_id, $this->get_template_type( $order ), $order->billing_email ); + $print_url = wcdn_get_print_link( $order_id, $this->get_template_type( $order ), $wdn_order_billing_id ); } ?> @@ -99,8 +100,11 @@ public function create_print_button_order_page( $order_id ) { */ public function add_email_print_url( $order, $sent_to_admin = true, $plain_text = false ) { if( get_option( 'wcdn_email_print_link' ) == 'yes' ) { - if( $order->billing_email && !$sent_to_admin ) { - $url = wcdn_get_print_link( $order->id, $this->get_template_type( $order ), $order->billing_email, true ); + $wdn_order_billing_id = ( version_compare( get_option( 'woocommerce_version' ), '3.0.0', ">=" ) ) ? $order->get_billing_email() : $order->billing_email; + if( $wdn_order_billing_id && !$sent_to_admin ) { + $wdn_order_id = ( version_compare( get_option( 'woocommerce_version' ), '3.0.0', ">=" ) ) ? $order->get_id() : $order->id; + + $url = wcdn_get_print_link( $wdn_order_id, $this->get_template_type( $order ), $wdn_order_billing_id, true ); if( $plain_text ) : echo __( 'Print your order', 'woocommerce-delivery-notes' ) . "\n\n"; @@ -119,7 +123,10 @@ public function add_email_print_url( $order, $sent_to_admin = true, $plain_text * Get the print button template type depnding on order status */ public function get_template_type( $order ) { - if( $order->status == 'completed' ) { + + $wdn_order_status = ( version_compare( get_option( 'woocommerce_version' ), '3.0.0', ">=" ) ) ? $order->get_status() : $order->status; + + if( $wdn_order_status == 'completed' ) { $type = apply_filters( 'wcdn_theme_print_button_template_type_complete_status', 'invoice' ); } else { $type = apply_filters( 'wcdn_theme_print_button_template_type', 'order' ); diff --git a/includes/class-wcdn-writepanel.php b/includes/class-wcdn-writepanel.php index 6f4b396..fb298f1 100644 --- a/includes/class-wcdn-writepanel.php +++ b/includes/class-wcdn-writepanel.php @@ -87,11 +87,13 @@ public function is_order_post_page() { * Add print actions to the orders listing */ public function add_listing_actions( $order ) { + + $wdn_order_id = ( version_compare( get_option( 'woocommerce_version' ), '3.0.0', ">=" ) ) ? $order->get_id() : $order->id; ?> - + diff --git a/includes/wcdn-template-functions.php b/includes/wcdn-template-functions.php index 59a47cf..facca28 100644 --- a/includes/wcdn-template-functions.php +++ b/includes/wcdn-template-functions.php @@ -230,17 +230,28 @@ function wcdn_get_order_info( $order ) { $fields = array(); $create_invoice_number = get_option( 'wcdn_create_invoice_number' ); - if( wcdn_get_template_type() == 'invoice' && !empty( $create_invoice_number ) && $create_invoice_number == 'yes' ) { + + + $wdn_order_id = ( version_compare( get_option( 'woocommerce_version' ), '3.0.0', ">=" ) ) ? $order->get_id() : $order->id; + $order_post = get_post( $wdn_order_id ); + + $wdn_order_order_date = ( version_compare( get_option( 'woocommerce_version' ), '3.0.0', ">=" ) ) ? $order_post->post_date : $order->order_date; + $wdn_order_payment_method_title = ( version_compare( get_option( 'woocommerce_version' ), '3.0.0', ">=" ) ) ? $order->get_payment_method_title() : $order->payment_method_title; + $wdn_order_billing_id = ( version_compare( get_option( 'woocommerce_version' ), '3.0.0', ">=" ) ) ? $order->get_billing_email() : $order->billing_email; + $wdn_order_billing_phone = ( version_compare( get_option( 'woocommerce_version' ), '3.0.0', ">=" ) ) ? $order->get_billing_phone() : $order->billing_phone; + + if( wcdn_get_template_type() == 'invoice' && !empty( $create_invoice_number ) && $create_invoice_number == 'yes' ) { + $fields['invoice_number'] = array( 'label' => __( 'Invoice Number', 'woocommerce-delivery-notes' ), - 'value' => wcdn_get_order_invoice_number( $order->id ) + 'value' => wcdn_get_order_invoice_number( $wdn_order_id ) ); } if( wcdn_get_template_type() == 'invoice' ) { $fields['invoice_date'] = array( 'label' => __( 'Invoice Date', 'woocommerce-delivery-notes' ), - 'value' => wcdn_get_order_invoice_date( $order->id ) + 'value' => wcdn_get_order_invoice_date( $wdn_order_id ) ); } @@ -251,25 +262,25 @@ function wcdn_get_order_info( $order ) { $fields['order_date'] = array( 'label' => __( 'Order Date', 'woocommerce-delivery-notes' ), - 'value' => date_i18n( get_option( 'date_format' ), strtotime( $order->order_date ) ) + 'value' => date_i18n( get_option( 'date_format' ), strtotime( $wdn_order_order_date ) ) ); $fields['payment_method'] = array( 'label' => __( 'Payment Method', 'woocommerce-delivery-notes' ), - 'value' => __( $order->payment_method_title, 'woocommerce' ) + 'value' => __( $wdn_order_payment_method_title, 'woocommerce' ) ); - if( $order->billing_email ) { + if( $wdn_order_billing_id ) { $fields['billing_email'] = array( 'label' => __( 'Email', 'woocommerce-delivery-notes' ), - 'value' => $order->billing_email + 'value' => $wdn_order_billing_id ); } - if( $order->billing_phone ) { + if( $wdn_order_billing_phone ) { $fields['billing_phone'] = array( 'label' => __( 'Telephone', 'woocommerce-delivery-notes' ), - 'value' => $order->billing_phone + 'value' => $wdn_order_billing_phone ); } @@ -342,19 +353,26 @@ function wcdn_has_refund( $order ) { function wcdn_get_formatted_item_price( $order, $item, $tax_display = '' ) { if ( ! $tax_display ) { - $tax_display = $order->tax_display_cart; + $tax_display = get_option( 'woocommerce_tax_display_cart' ); } if ( ! isset( $item['line_subtotal'] ) || ! isset( $item['line_subtotal_tax'] ) ) { return ''; } + $wdn_order_currency = ( version_compare( get_option( 'woocommerce_version' ), '3.0.0', ">=" ) ) ? $order->get_currency() : $order->get_order_currency(); + if ( 'excl' == $tax_display ) { - $ex_tax_label = $order->prices_include_tax ? 1 : 0; - - $subtotal = wc_price( $order->get_item_subtotal( $item ), array( 'ex_tax_label' => $ex_tax_label, 'currency' => $order->get_order_currency() ) ); + if ( version_compare( get_option( 'woocommerce_version' ), '3.0.0', ">=" ) ){ + $ex_tax_label = wc_prices_include_tax() ? 1 : 0; + }else{ + $ex_tax_label = $order->prices_include_tax ? 1 : 0; + } + + + $subtotal = wc_price( $order->get_item_subtotal( $item ), array( 'ex_tax_label' => $ex_tax_label, 'currency' => $wdn_order_currency ) ); } else { - $subtotal = wc_price( $order->get_item_subtotal( $item, true ), array('currency' => $order->get_order_currency()) ); + $subtotal = wc_price( $order->get_item_subtotal( $item, true ), array('currency' => $wdn_order_currency ) ); } return apply_filters( 'wcdn_formatted_item_price', $subtotal, $item, $order ); @@ -455,7 +473,9 @@ function wcdn_remove_payment_method_from_totals( $total_rows, $order ) { */ function wcdn_get_customer_notes( $order ) { global $wcdn; - return stripslashes( wpautop( wptexturize( $order->customer_note ) ) ); + + $wdn_order_customer_notes = ( version_compare( get_option( 'woocommerce_version' ), '3.0.0', ">=" ) ) ? $order->get_customer_note() : $order->customer_note; + return stripslashes( wpautop( wptexturize( $wdn_order_customer_notes ) ) ); } /** diff --git a/templates/print-order/print-content.php b/templates/print-order/print-content.php index e2b95bd..19a6db2 100644 --- a/templates/print-order/print-content.php +++ b/templates/print-order/print-content.php @@ -80,7 +80,13 @@ get_product_from_item( $item ), $item ); - $item_meta = new WC_Order_Item_Meta( $item['item_meta'], $product ); + + if ( version_compare( get_option( 'woocommerce_version' ), '3.1.0', ">=" ) ) { + $item_meta = new WC_Order_Item_Product( $item['item_meta'], $product ); + }else{ + $item_meta = new WC_Order_Item_Meta( $item['item_meta'], $product ); + } + ?> @@ -89,7 +95,15 @@ - display(); ?> + =" ) ) { + $item_meta->get_product(); + + }else { + + $item_meta->display(); + } + ?>
exists() && $product->is_downloadable() && $order->is_download_permitted() ) : ?>