Skip to content

Commit

Permalink
Added fallback methods for woocommerce version 2.6.14
Browse files Browse the repository at this point in the history
Signed-off-by: Faishal Saiyed <[email protected]>
  • Loading branch information
faishal committed Apr 16, 2018
1 parent aeab473 commit ed93368
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 7 deletions.
7 changes: 6 additions & 1 deletion admin/class-wcemails-admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -558,6 +558,11 @@ function do_email_actions( $post_id, $post ) {
// Order data saved, now get it so we can manipulate status.
$order = wc_get_order( $post_id );

if (method_exists($order, 'get_id')){
$order_id = $order->get_id();
} else {
$order_id = $order->id;
}
$action = wc_clean( $_POST['wc_order_action'] );

$wcemails_email_details = get_option( 'wcemails_email_details', array() );
Expand All @@ -570,7 +575,7 @@ function do_email_actions( $post_id, $post ) {
if ( $id == $action ) {
WC()->payment_gateways();
WC()->shipping();
WC()->mailer()->emails['WCustom_Emails_'.$id.'_Email']->trigger( $order->get_id(), $order );
WC()->mailer()->emails['WCustom_Emails_'.$id.'_Email']->trigger( $order_id, $order );
}
}
}
Expand Down
51 changes: 45 additions & 6 deletions admin/class-wcemails-instance.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,22 @@ function trigger( $order_id ) {
$send_to_customer = ('on' == $this->send_customer);

if ( $order_id ) {
if ( ! $this->object ) {
$this->object = wc_get_order( $order_id );
}
if ( method_exists( $this->object, 'get_billing_email' ) ) {
$billing_email = $this->object->get_billing_email();
} else {
$billing_email = $this->object->billing_email;
}

$this->object = wc_get_order( $order_id );
if ( $send_to_customer ) {
$this->bcc = $this->recipient;
$this->recipient = $this->object->get_billing_email();
$this->recipient = $billing_email;
} else {
$recipients = explode( ',', $this->recipient );
array_push( $recipients, $this->object->get_billing_email() );
array_push( $recipients, $billing_email );
$this->recipient = implode( ',', $recipients );
}

Expand Down Expand Up @@ -220,12 +229,42 @@ function add_actions() {

function convert_template() {

if ( method_exists( $this->object, 'get_billing_first_name' ) ) {
$billing_first_name = $this->object->get_billing_first_name();
} else {
$billing_first_name = $this->object->billing_first_name;
}

if ( method_exists( $this->object, 'get_billing_last_name' ) ) {
$billing_last_name = $this->object->get_billing_last_name();
} else {
$billing_last_name = $this->object->billing_last_name;
}

if ( method_exists( $this->object, 'get_billing_email' ) ) {
$billing_email = $this->object->get_billing_email();
} else {
$billing_email = $this->object->billing_email;
}

if ( method_exists( $this->object, 'get_billing_phone' ) ) {
$billing_phone = $this->object->get_billing_phone();
} else {
$billing_phone = $this->object->billing_phone;
}

if(function_exists('wc_get_email_order_items')){
$item_table = wc_get_email_order_items( $this->object );
} else {
$item_table = $this->object->email_order_items_table();
}

$this->placeholders['{woocommerce_email_order_meta}'] = $this->woocommerce_email_order_meta();
$this->placeholders['{order_billing_name}'] = $this->object->get_billing_first_name() . ' ' . $this->object->get_billing_last_name();
$this->placeholders['{email_order_items_table}'] = wc_get_email_order_items( $this->object );
$this->placeholders['{order_billing_name}'] = $billing_first_name . ' ' . $billing_last_name;
$this->placeholders['{email_order_items_table}'] = $item_table;
$this->placeholders['{email_order_total_footer}'] = $this->email_order_total_footer();
$this->placeholders['{order_billing_email}'] = $this->object->get_billing_email();
$this->placeholders['{order_billing_phone}'] = $this->object->get_billing_phone();
$this->placeholders['{order_billing_email}'] = $billing_email;
$this->placeholders['{order_billing_phone}'] = $billing_phone;
$this->placeholders['{email_addresses}'] = $this->get_email_addresses();
$this->placeholders['{site_title}'] = get_bloginfo('name');

Expand Down

0 comments on commit ed93368

Please sign in to comment.