예제 #1
0
    /**
     * Action for manual emails when booking is selected
     */
    public function manual_type_actions()
    {
        $products = array();
        $posts = get_posts(array('post_type' => 'product', 'post_status' => 'publish'));
        foreach ($posts as $post) {
            $product = WC_FUE_Compatibility::wc_get_product($post->ID);
            if ($product->is_type(array('booking'))) {
                $products[] = $product;
            }
        }
        ?>
        <div class="send-type-bookings send-type-div">
            <select id="booking_event_id" name="booking_event_id" class="select2" style="width: 400px;">
                <?php 
        foreach ($products as $product) {
            ?>
                    <option value="<?php 
            echo $product->id;
            ?>
"><?php 
            echo esc_html($product->get_title());
            ?>
</option>
                <?php 
        }
        ?>
            </select>
        </div>
    <?php 
    }
예제 #2
0
    <p>
        <strong><?php 
_e('Select the product that, when bought or added to the cart, will trigger this follow-up email.', 'follow_up_emails');
?>
</strong>
    </p>

    <label for="product_ids"><?php 
_e('Product', 'follow_up_emails');
?>
</label>
    <?php 
$product_id = !empty($email->product_id) ? $email->product_id : '';
$product_name = '';
if (!empty($product_id)) {
    $product = WC_FUE_Compatibility::wc_get_product($product_id);
    if ($product) {
        $product_name = wp_kses_post($product->get_formatted_name());
    }
}
?>
    <input
        type="hidden"
        id="product_id"
        name="product_id"
        class="ajax_select2_products_and_variations"
        data-multiple="false"
        data-placeholder="<?php 
_e('Search for a product&hellip;', 'woocommerce');
?>
"
    /**
     * Fields to show if subscription is selected
     */
    public function manual_type_actions()
    {
        $subscriptions = array();
        $posts = get_posts(array('post_type' => 'product', 'post_status' => 'publish', 'posts_per_page' => -1));
        foreach ($posts as $post) {
            $product = WC_FUE_Compatibility::wc_get_product($post->ID);
            if ($product->is_type(array(WC_Subscriptions::$name, 'subscription_variation', 'variable-subscription'))) {
                $subscriptions[] = $product;
            }
        }
        ?>
        <div class="send-type-subscription send-type-div">
            <select id="subscription_id" name="subscription_id" class="select2" style="width: 400px;">
                <?php 
        foreach ($subscriptions as $subscription) {
            ?>
                <option value="<?php 
            echo $subscription->id;
            ?>
"><?php 
            echo esc_html($subscription->get_title());
            ?>
</option>
                <?php 
        }
        ?>
            </select>
        </div>
        <?php 
    }
 /**
  * Get the correct name of a product
  * @param int|WC_Product $product
  * @return string
  */
 public static function get_product_name($product)
 {
     if (is_numeric($product)) {
         $product = WC_FUE_Compatibility::wc_get_product($product);
     }
     return $product->get_title();
 }
 /**
  * Test will pass if the customer has bought all of the products
  * specified in the condition
  *
  * @param FUE_Sending_Queue_Item $item
  * @param array $condition
  * @return bool|WP_Error
  */
 public function test_bought_products_condition($item, $condition)
 {
     $wpdb = Follow_Up_Emails::instance()->wpdb;
     $products = array_filter(array_map('absint', explode(',', $condition['products'])));
     $customer = fue_get_customer_from_order($item->order_id);
     $result = true;
     if (!$customer) {
         return new WP_Error('fue_email_conditions', sprintf(__('Customer data could not be found (Order #%d)', 'follow_up_emails'), $item->order_id));
     }
     if (!empty($products)) {
         foreach ($products as $product) {
             if (!$this->fue_wc->customer_purchased_product($customer, $product)) {
                 // no purchases found for this product
                 $wc_product = WC_FUE_Compatibility::wc_get_product($product);
                 return new WP_Error('fue_email_conditions', sprintf(__('Customer has not purchased a required product (#%d - %s)', 'follow_up_emails'), $product, $wc_product->get_formatted_name()));
             }
         }
     }
     return true;
 }
예제 #6
0
 function sfn_get_product($product_id)
 {
     _deprecated_function('sfn_get_product', '3.7', 'WC_FUE_Compatibility::wc_get_product');
     return WC_FUE_Compatibility::wc_get_product($product_id);
 }
 /**
  * Get replacement data for product and reminder emails
  *
  * @param array     $replacements
  * @param array     $email_data
  * @param object    $queue_item
  * @param FUE_Email $email
  *
  * @return array
  */
 private function get_replacement_data_for_product($replacements, $email_data, $queue_item, $email)
 {
     $categories = '';
     $item_name = '';
     $item_price = '';
     if (!empty($queue_item->product_id)) {
         $item = WC_FUE_Compatibility::wc_get_product($queue_item->product_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, ', ');
         }
         $item_url = FUE_Sending_Mailer::create_email_url($queue_item->id, $queue_item->id, $email_data['user_id'], $email_data['email_to'], get_permalink($queue_item->product_id));
         $item_name = '<a href="' . $item_url . '">' . get_the_title($queue_item->product_id) . '</a>';
         $order = WC_FUE_Compatibility::wc_get_order($queue_item->order_id);
         if ($order instanceof WC_Order) {
             foreach ($order->get_items() as $order_item) {
                 if ($order_item['product_id'] == $queue_item->product_id) {
                     $replacements['item_quantity'] = $order_item['qty'];
                     break;
                 }
             }
         }
         $item_price = strip_tags($item->get_price_html());
     }
     $replacements['item_name'] = $item_name;
     $replacements['item_price'] = $item_price;
     return $replacements;
 }