コード例 #1
0
 public function email_replacements($reps, $email_data, $email_order, $email_row)
 {
     global $wpdb, $woocommerce;
     $email_type = $email_row->email_type;
     $order_date = '';
     $order_datetime = '';
     $order_id = '';
     if ($email_order->order_id) {
         $order = new WC_Order($email_order->order_id);
         $order_date = date(get_option('date_format'), strtotime($order->order_date));
         $order_datetime = date(get_option('date_format') . ' ' . get_option('time_format'), strtotime($order->order_date));
         $order_id = apply_filters('woocommerce_order_number', '#' . $email_order->order_id, $order);
         $item = WC_Subscriptions_Order::get_item_by_product_id($order);
         $item_id = WC_Subscriptions_Order::get_items_product_id($item);
         $renewal = WC_Subscriptions_Order::get_next_payment_timestamp($order, $item_id);
         $renew_date = date(get_option('date_format'), $renewal);
         // calc days to renew
         $now = current_time('timestamp');
         $diff = $renewal - $now;
         $days_to_renew = 0;
         if ($diff > 0) {
             $days_to_renew = floor($diff / 86400);
         }
         $item_url = FUE::create_email_url($email_order->id, $email_row->id, $email_data['user_id'], $email_data['email_to'], get_permalink($item_id));
         $categories = '';
         if ($item_id) {
             $cats = get_the_terms($item_id, 'product_cat');
             if (is_array($cats) && !empty($cats)) {
                 foreach ($cats as $cat) {
                     $categories .= $cat->name . ', ';
                 }
                 $categories = rtrim($categories, ', ');
             }
         }
         $reps = array_merge($reps, array($order_id, $order_date, $order_datetime, $email_data['first_name'], $email_data['first_name'] . ' ' . $email_data['last_name'], $email_data['email_to'], $renew_date, $days_to_renew, '<a href="' . $item_url . '">' . get_the_title($item_id) . '</a>', $categories));
     }
     return $reps;
 }
 /**
  * If requesting a payment method change, replace the woocommerce_pay_shortcode() with a change payment form.
  *
  * @since 1.4
  */
 public static function maybe_replace_pay_shortcode()
 {
     global $woocommerce;
     if (!self::$is_request_to_change_payment) {
         return;
     }
     ob_clean();
     do_action('before_woocommerce_pay');
     echo '<div class="woocommerce">';
     if (!empty(self::$woocommerce_errors)) {
         foreach (self::$woocommerce_errors as $error) {
             WC_Subscriptions::add_notice($error, 'error');
         }
     }
     if (!empty(self::$woocommerce_messages)) {
         foreach (self::$woocommerce_messages as $message) {
             WC_Subscriptions::add_notice($message, 'success');
         }
     }
     $subscription_key = $_GET['change_payment_method'];
     $subscription = WC_Subscriptions_Manager::get_subscription($subscription_key);
     if (wp_verify_nonce($_GET['_wpnonce'], __FILE__) === false) {
         WC_Subscriptions::add_notice(__('There was an error with your request. Please try again.', 'woocommerce-subscriptions'), 'error');
         WC_Subscriptions::print_notices();
     } elseif (!WC_Subscriptions_Manager::user_owns_subscription($subscription_key)) {
         WC_Subscriptions::add_notice(__('That doesn\'t appear to be one of your subscriptions.', 'woocommerce-subscriptions'), 'error');
         WC_Subscriptions::print_notices();
     } elseif (empty($subscription)) {
         WC_Subscriptions::add_notice(__('Invalid subscription.', 'woocommerce-subscriptions'), 'error');
         WC_Subscriptions::print_notices();
     } elseif (!WC_Subscriptions_Manager::can_subscription_be_changed_to('new-payment-method', $subscription_key, get_current_user_id())) {
         WC_Subscriptions::add_notice(__('The payment method can not be changed for that subscription.', 'woocommerce-subscriptions'), 'error');
         WC_Subscriptions::print_notices();
     } else {
         $order = new WC_Order($subscription['order_id']);
         $order_id = absint($_GET['order_id']);
         $order_key = isset($_GET['key']) ? $_GET['key'] : $_GET['order'];
         $product_id = $subscription['product_id'];
         $next_payment_timestamp = WC_Subscriptions_Order::get_next_payment_timestamp($order, $product_id);
         if (!empty($next_payment_timestamp)) {
             $next_payment_string = sprintf(__(' Next payment is due %s.', 'woocommerce-subscriptions'), date_i18n(woocommerce_date_format(), $next_payment_timestamp));
         } else {
             $next_payment_string = '';
         }
         WC_Subscriptions::add_notice(sprintf(__('Choose a new payment method.%s', 'woocommerce-subscriptions'), $next_payment_string), 'notice');
         WC_Subscriptions::print_notices();
         if ($order->order_key == $order_key) {
             // Set customer location to order location
             if ($order->billing_country) {
                 $woocommerce->customer->set_country($order->billing_country);
             }
             if ($order->billing_state) {
                 $woocommerce->customer->set_state($order->billing_state);
             }
             if ($order->billing_postcode) {
                 $woocommerce->customer->set_postcode($order->billing_postcode);
             }
             // Show form
             WC_Subscriptions_Order::$recurring_only_price_strings = true;
             woocommerce_get_template('checkout/form-change-payment-method.php', array('order' => $order, 'subscription_key' => $subscription_key), '', plugin_dir_path(WC_Subscriptions::$plugin_file) . 'templates/');
             WC_Subscriptions_Order::$recurring_only_price_strings = false;
         } else {
             WC_Subscriptions::add_notice(__('Invalid order.', 'woocommerce-subscriptions'), 'error');
             WC_Subscriptions::print_notices();
         }
     }
 }
コード例 #3
0
 public function replace_variables($text, $email_order)
 {
     $order = new WC_Order($email_order->order_id);
     $item = WC_Subscriptions_Order::get_item_by_product_id($order);
     $item_id = WC_Subscriptions_Order::get_items_product_id($item);
     $renewal = WC_Subscriptions_Order::get_next_payment_timestamp($order, $item_id);
     $renew_date = date(get_option('date_format'), $renewal);
     // calc days to renew
     $now = current_time('timestamp');
     $diff = $renewal - $now;
     $days_to_renew = 0;
     if ($diff > 0) {
         $days_to_renew = floor($diff / 86400);
     }
     $search = array('{subs_renew_date}', '{days_to_renew}');
     $replacements = array($renew_date, $days_to_renew);
     return str_replace($search, $replacements, $text);
 }