Skip to content

Commit

Permalink
Changes to support HPOS.
Browse files Browse the repository at this point in the history
  • Loading branch information
anderly committed Aug 10, 2023
1 parent af6e27a commit 3ae95a0
Showing 1 changed file with 42 additions and 6 deletions.
48 changes: 42 additions & 6 deletions includes/class-ss-wc-mailchimp-handler.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,41 @@ final class SS_WC_MailChimp_Handler {

/**
*
*
* Plugin singleton instance
* Class singleton instance
*
* @var SS_WC_MailChimp_Handler
*/
private static $instance = null;

/**
*
* Main Plugin instance
*
* @var SS_WC_MailChimp_Plugin
*/
private $sswcmc = null;

/**
* Id
*
* @var string
*/
private $id = null;

/**
* Namespace
*
* @var string
*/
private $namespace = null;

/**
* Label
*
* @var string
*/
private $label = null;

/**
* Constructor
*
Expand Down Expand Up @@ -123,7 +151,7 @@ public function order_status_changed( $id, $status = 'new', $new_status = 'pendi
$order = $this->wc_get_order( $id );

// Get the ss_wc_mailchimp_opt_in value from the post meta ("order_custom_fields" was removed with WooCommerce 2.1).
$subscribe_customer = get_post_meta( $id, 'ss_wc_mailchimp_opt_in', true );
$subscribe_customer = $order->get_meta( 'ss_wc_mailchimp_opt_in', true );

$order_id = method_exists( $order, 'get_id' ) ? $order->get_id() : $order->id;
$order_billing_email = method_exists( $order, 'get_billing_email' ) ? $order->get_billing_email() : $order->billing_email;
Expand Down Expand Up @@ -395,8 +423,10 @@ private function get_message( $message, $type = 'error' ) {
*/
public function maybe_subscribe( $order_id ) {

// Get the ss_wc_mailchimp_opt_in value from the post meta ("order_custom_fields" was removed with WooCommerce 2.1).
$subscribe_customer = get_post_meta( $order_id, 'ss_wc_mailchimp_opt_in', true );
$order = $this->wc_get_order( $order_id );

// Get the ss_wc_mailchimp_opt_in value from the order meta ("order_custom_fields" was removed with WooCommerce 2.1).
$subscribe_customer = $order->get_meta( 'ss_wc_mailchimp_opt_in', true );

// Get the subscribe options.
$subscribe_options = $this->sswcmc->get_subscribe_options_for_order( $order_id );
Expand Down Expand Up @@ -512,7 +542,13 @@ public function maybe_save_checkout_fields( $order_id ) {
if ( $this->sswcmc->display_opt_in() ) {
$opt_in = isset( $_POST['ss_wc_mailchimp_opt_in'] ) ? 'yes' : 'no';

update_post_meta( $order_id, 'ss_wc_mailchimp_opt_in', $opt_in );
$order = $this->wc_get_order( $order_id );

// update_post_meta( $order_id, 'ss_wc_mailchimp_opt_in', $opt_in );

$order->update_meta_data( 'ss_wc_mailchimp_opt_in', $opt_in );
$order->save();

}
}

Expand Down

0 comments on commit 3ae95a0

Please sign in to comment.