Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WooCommerce V3.x.x Compatible #147

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions includes/class-wcdn-print.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
21 changes: 14 additions & 7 deletions includes/class-wcdn-theme.php
Original file line number Diff line number Diff line change
Expand Up @@ -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' )
);
}
Expand All @@ -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
Expand All @@ -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 );
}

?>
Expand All @@ -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";
Expand All @@ -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' );
Expand Down
4 changes: 3 additions & 1 deletion includes/class-wcdn-writepanel.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
?>
<?php foreach( WooCommerce_Delivery_Notes_Print::$template_registrations as $template_registration ) : ?>
<?php if( get_option( 'wcdn_template_type_' . $template_registration['type'] ) == 'yes' && $template_registration['type'] !== 'order' ) : ?>

<a href="<?php echo wcdn_get_print_link( $order->id, $template_registration['type'] ); ?>" class="button tips print-preview-button <?php echo $template_registration['type']; ?>" target="_blank" alt="<?php esc_attr_e( __( $template_registration['labels']['print'], 'woocommerce-delivery-notes' ) ); ?>" data-tip="<?php esc_attr_e( __( $template_registration['labels']['print'], 'woocommerce-delivery-notes' ) ); ?>">
<a href="<?php echo wcdn_get_print_link( $wdn_order_id, $template_registration['type'] ); ?>" class="button tips print-preview-button <?php echo $template_registration['type']; ?>" target="_blank" alt="<?php esc_attr_e( __( $template_registration['labels']['print'], 'woocommerce-delivery-notes' ) ); ?>" data-tip="<?php esc_attr_e( __( $template_registration['labels']['print'], 'woocommerce-delivery-notes' ) ); ?>">
<?php _e( $template_registration['labels']['print'], 'woocommerce-delivery-notes' ); ?>
</a>

Expand Down
50 changes: 35 additions & 15 deletions includes/wcdn-template-functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 )
);
}

Expand All @@ -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
);
}

Expand Down Expand Up @@ -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 );
Expand Down Expand Up @@ -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 ) ) );
}

/**
Expand Down
18 changes: 16 additions & 2 deletions templates/print-order/print-content.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,13 @@

<?php
$product = apply_filters( 'wcdn_order_item_product', $order->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 );
}

?>

<tr>
Expand All @@ -89,7 +95,15 @@

<span class="name"><?php echo apply_filters( 'wcdn_order_item_name', $item['name'], $item ); ?></span>

<?php $item_meta->display(); ?>
<?php
if ( version_compare( get_option( 'woocommerce_version' ), '3.1.0', ">=" ) ) {
$item_meta->get_product();

}else {

$item_meta->display();
}
?>

<dl class="extras">
<?php if( $product && $product->exists() && $product->is_downloadable() && $order->is_download_permitted() ) : ?>
Expand Down