コード例 #1
1
 /**
  * Returns the price including or excluding tax, based on the 'woocommerce_tax_display_shop' setting.
  * Should be safe to remove when we drop WC 2.2 compatibility
  *
  * @param  WC_Product $product the product object
  * @param  string     $price   to calculate, left blank to just use get_price()
  * @param  integer    $qty     passed on to get_price_including_tax() or get_price_excluding_tax()
  * @return string
  */
 public static function get_product_display_price($product, $price = '', $qty = 1)
 {
     if (SV_WC_Plugin_Compatibility::is_wc_version_gte_2_3()) {
         return $product->get_display_price($price, $qty);
     } else {
         if ($price === '') {
             $price = $product->get_price();
         }
         $tax_display_mode = get_option('woocommerce_tax_display_shop');
         $display_price = $tax_display_mode == 'incl' ? $product->get_price_including_tax($qty, $price) : $product->get_price_excluding_tax($qty, $price);
         return $display_price;
     }
 }
 /**
  * Get settings array
  *
  * @since 1.0.0
  * @param string $current_section Optional. Defaults to empty string.
  * @return array Array of settings
  */
 public function get_settings($current_section = '')
 {
     if ('products' == $current_section) {
         /**
          * Filter Memberships products Settings
          *
          * @since 1.0.0
          * @param array $settings Array of the plugin settings
          */
         $settings = apply_filters('wc_memberships_products_settings', array(array('name' => __('Products', WC_Memberships::TEXT_DOMAIN), 'type' => 'title', 'desc' => '', 'id' => 'memberships_products_options'), array('type' => 'checkbox', 'id' => 'wc_memberships_hide_restricted_products', 'name' => __('Hide restricted products', WC_Memberships::TEXT_DOMAIN), 'desc' => __('If enabled, products with viewing restricted will be hidden from the shop catalog. Products will still be accessible directly, unless Content Restriction Mode is "Hide completely".', WC_Memberships::TEXT_DOMAIN), 'default' => 'no'), array('type' => 'sectionend', 'id' => 'memberships_products_options'), array('name' => __('Product Restriction Messages', WC_Memberships::TEXT_DOMAIN), 'type' => 'title', 'desc' => sprintf(__('%s automatically inserts the product(s) needed to gain access. %s inserts the URL to my account page with the login form. HTML is allowed.', WC_Memberships::TEXT_DOMAIN), '<code>{products}</code>', '<code>{login_url}</code>'), 'id' => 'memberships_product_messages'), array('type' => 'textarea', 'id' => 'wc_memberships_product_viewing_restricted_message', 'class' => 'input-text wide-input', 'name' => __('Product Viewing Restricted - Purchase Required', WC_Memberships::TEXT_DOMAIN), 'desc' => __('Displays when purchase is required to view the product.', WC_Memberships::TEXT_DOMAIN), 'default' => __('This product can only be viewed by members. To view or purchase this product, sign up by purchasing {products}.', WC_Memberships::TEXT_DOMAIN), 'desc_tip' => __('Message displayed if viewing is restricted to members but access can be purchased.', WC_Memberships::TEXT_DOMAIN)), array('type' => 'textarea', 'id' => 'wc_memberships_product_viewing_restricted_message_no_products', 'class' => 'input-text wide-input', 'name' => __('Product Viewing Restricted - Membership Required', WC_Memberships::TEXT_DOMAIN), 'desc' => __('Displays if viewing is restricted to a membership that cannot be purchased.', WC_Memberships::TEXT_DOMAIN), 'default' => __('This product can only be viewed by members.', WC_Memberships::TEXT_DOMAIN), 'desc_tip' => __('Message displayed if viewing is restricted to members and no products can grant access.', WC_Memberships::TEXT_DOMAIN)), array('type' => 'textarea', 'id' => 'wc_memberships_product_purchasing_restricted_message', 'class' => 'input-text wide-input', 'name' => __('Product Buying Restricted - Purchase Required', WC_Memberships::TEXT_DOMAIN), 'desc' => __('Displays when purchase is required to buy the product.', WC_Memberships::TEXT_DOMAIN), 'default' => __('This product can only be purchased by members. To purchase this product, sign up by purchasing {products}.', WC_Memberships::TEXT_DOMAIN), 'desc_tip' => __('Message displayed if purchasing is restricted to members but access can be purchased.', WC_Memberships::TEXT_DOMAIN)), array('type' => 'textarea', 'id' => 'wc_memberships_product_purchasing_restricted_message_no_products', 'class' => 'input-text wide-input', 'name' => __('Product Buying Restricted - Membership Required', WC_Memberships::TEXT_DOMAIN), 'desc' => __('Displays if purchasing is restricted to a membership that cannot be purchased.', WC_Memberships::TEXT_DOMAIN), 'default' => __('This product can only be purchased by members.', WC_Memberships::TEXT_DOMAIN), 'desc_tip' => __('Message displayed if purchasing is restricted to members and no products can grant access.', WC_Memberships::TEXT_DOMAIN)), array('type' => 'textarea', 'id' => 'wc_memberships_product_discount_message', 'class' => 'input-text wide-input', 'name' => __('Product Discounted - Purchase Required', WC_Memberships::TEXT_DOMAIN), 'desc' => __('Message displayed to non-members if the product has a member discount.', WC_Memberships::TEXT_DOMAIN), 'default' => __('Want a discount? Become a member by purchasing {products}.', WC_Memberships::TEXT_DOMAIN), 'desc_tip' => __('Displays below add to cart buttons. Leave blank to disable.', WC_Memberships::TEXT_DOMAIN)), array('type' => 'textarea', 'id' => 'wc_memberships_product_discount_message_no_products', 'class' => 'input-text wide-input', 'name' => __('Product Discounted - Membership Required', WC_Memberships::TEXT_DOMAIN), 'desc' => __('Message displayed to non-members if the product has a member discount, but no products can grant access.', WC_Memberships::TEXT_DOMAIN), 'default' => __('Want a discount? Become a member.', WC_Memberships::TEXT_DOMAIN), 'desc_tip' => __('Displays below add to cart buttons. Leave blank to disable.', WC_Memberships::TEXT_DOMAIN)), array('type' => 'sectionend', 'id' => 'memberships_product_messages')));
     } else {
         /**
          * Filter Memberships general Settings
          *
          * @since 1.0.0
          * @param array $settings Array of the plugin settings
          */
         $settings = apply_filters('wc_memberships_general_settings', array(array('name' => __('General', WC_Memberships::TEXT_DOMAIN), 'type' => 'title', 'desc' => '', 'id' => 'memberships_options'), array('type' => 'select', 'id' => 'wc_memberships_restriction_mode', 'name' => __('Content Restriction Mode', WC_Memberships::TEXT_DOMAIN), 'options' => array('hide' => __('Hide completely', WC_Memberships::TEXT_DOMAIN), 'hide_content' => __('Hide content only', WC_Memberships::TEXT_DOMAIN), 'redirect' => __('Redirect to page', WC_Memberships::TEXT_DOMAIN)), 'class' => SV_WC_Plugin_Compatibility::is_wc_version_gte_2_3() ? 'wc-enhanced-select' : 'wc-memberships-chosen_select', 'desc_tip' => __('Specifies the way content is restricted: whether to show nothing, excerpts, or send to a landing page.', WC_Memberships::TEXT_DOMAIN), 'desc' => __('"Hide completely" removes all traces of content for non-members and search engines and 404s restricted pages.<br />"Hide content only" will show items in archives, but protect page or post content and comments.', WC_Memberships::TEXT_DOMAIN), 'default' => 'hide_content'), array('title' => __('Redirect Page', WC_Memberships::TEXT_DOMAIN), 'desc' => __('Select the page to redirect non-members to - should contain the [wcm_content_restricted] shortcode.', WC_Memberships::TEXT_DOMAIN), 'id' => 'wc_memberships_redirect_page_id', 'type' => 'single_select_page', 'class' => SV_WC_Plugin_Compatibility::is_wc_version_gte_2_3() ? 'wc-enhanced-select-nostd js-redirect-page' : 'wc-memberships-chosen_select_nostd js-redirect-page', 'css' => 'min-width:300px;', 'desc_tip' => true), array('type' => 'checkbox', 'id' => 'wc_memberships_show_excerpts', 'name' => __('Show Excerpts', WC_Memberships::TEXT_DOMAIN), 'desc' => __('If enabled, an excerpt of the protected content will be displayed to non-members & search engines.', WC_Memberships::TEXT_DOMAIN), 'default' => 'yes'), array('type' => 'select', 'id' => 'wc_memberships_display_member_login_notice', 'name' => __('Show Member Login Notice', WC_Memberships::TEXT_DOMAIN), 'options' => array('never' => __('Never', WC_Memberships::TEXT_DOMAIN), 'cart' => __('On Cart Page', WC_Memberships::TEXT_DOMAIN), 'checkout' => __('On Checkout Page', WC_Memberships::TEXT_DOMAIN), 'both' => __('On both Cart & Checkout Page', WC_Memberships::TEXT_DOMAIN)), 'class' => SV_WC_Plugin_Compatibility::is_wc_version_gte_2_3() ? 'wc-enhanced-select' : 'wc-memberships-chosen_select', 'desc_tip' => __('Select when & where to display login reminder notice for guests if products in cart have member discounts.', WC_Memberships::TEXT_DOMAIN), 'default' => 'both'), array('type' => 'sectionend', 'id' => 'memberships_options'), array('title' => __('Content Restricted Messages', WC_Memberships::TEXT_DOMAIN), 'type' => 'title', 'desc' => sprintf(__('%s automatically inserts the product(s) needed to gain access. %s inserts the URL to my account page with the login form. HTML is allowed.', WC_Memberships::TEXT_DOMAIN), '<code>{products}</code>', '<code>{login_url}</code>'), 'id' => 'memberships_restriction_messages'), array('type' => 'textarea', 'id' => 'wc_memberships_content_restricted_message', 'class' => 'input-text wide-input', 'name' => __('Content Restricted - Purchase Required', WC_Memberships::TEXT_DOMAIN), 'desc' => __('Displays when purchase is required to view the content.', WC_Memberships::TEXT_DOMAIN), 'default' => __('To access this content, you must purchase {products}.', WC_Memberships::TEXT_DOMAIN), 'desc_tip' => __('Message displayed if visitor does not have access to content, but can purchase it.', WC_Memberships::TEXT_DOMAIN)), array('type' => 'textarea', 'id' => 'wc_memberships_content_restricted_message_no_products', 'class' => 'input-text wide-input', 'name' => __('Content Restricted - Membership Required', WC_Memberships::TEXT_DOMAIN), 'desc' => __('Displays if the content is restricted to a membership that cannot be purchased.', WC_Memberships::TEXT_DOMAIN), 'default' => __('This content is only available to members.', WC_Memberships::TEXT_DOMAIN), 'desc_tip' => __('Message displayed if visitor does not have access to content and no products can grant access.', WC_Memberships::TEXT_DOMAIN)), array('type' => 'sectionend', 'id' => 'memberships_restriction_messages')));
     }
     /**
      * Filter Memberships Settings
      *
      * @since 1.0.0
      * @param array $settings Array of the plugin settings
      */
     return apply_filters('woocommerce_get_settings_' . $this->id, $settings, $current_section);
 }
 /**
  * Constructor
  *
  * Set up membership emails
  *
  * @since 1.0.0
  */
 public function __construct()
 {
     add_filter('woocommerce_email_classes', array($this, 'memberships_emails'));
     if (SV_WC_Plugin_Compatibility::is_wc_version_gte_2_3()) {
         add_action('wc_memberships_new_user_membership_note', array('WC_Emails', 'send_transactional_email'), 10, 10);
     } else {
         add_action('wc_memberships_new_user_membership_note', array(WC(), 'send_transactional_email'), 10, 10);
     }
 }
 /**
  * Constructor
  *
  * @since 1.0.0
  */
 public function __construct()
 {
     // Enqueue JS and styles
     add_action('wp_enqueue_scripts', array($this, 'enqueue_scripts_and_styles'));
     // Handle frontend actions
     if (SV_WC_Plugin_Compatibility::is_wc_version_gte_2_3()) {
         add_action('wp_loaded', array($this, 'cancel_membership'));
         add_action('wp_loaded', array($this, 'renew_membership'));
     } else {
         add_action('init', array($this, 'cancel_membership'));
         add_action('init', array($this, 'renew_membership'));
     }
     // Add cart & checkout notices
     add_action('wp', array($this, 'add_cart_member_login_notice'));
     // optional login/link buttons on checkout / thank you pages
     add_action('woocommerce_before_template_part', array($this, 'maybe_render_checkout_member_login_notice'));
     // Show memberships on my account dashboard
     add_action('woocommerce_before_my_account', array($this, 'my_account_memberships'));
 }
 /**
  * Get the order data for a single CSV row
  *
  * Note items are keyed according to the column header keys above so these can be modified using
  * the provider filter without needing to worry about the array order
  *
  * @since 3.0
  * @param int $order_id the WC_Order ID
  * @return array order data in the format key => content
  */
 private function get_orders_csv_row($order_id)
 {
     $order = wc_get_order($order_id);
     $line_items = $shipping_items = $fee_items = $tax_items = $coupon_items = array();
     // get line items
     foreach ($order->get_items() as $item_id => $item) {
         $product = $order->get_product_from_item($item);
         if (!is_object($product)) {
             $product = new WC_Product(0);
         }
         $item_meta = new WC_Order_Item_Meta(SV_WC_Plugin_Compatibility::is_wc_version_gte_2_4() ? $item : $item['item_meta']);
         $meta = $item_meta->display(true, true);
         if ($meta) {
             // remove newlines
             $meta = str_replace(array("\r", "\r\n", "\n"), '', $meta);
             // switch reserved chars (:;|) to =
             $meta = str_replace(array(': ', ':', ';', '|'), '=', $meta);
         }
         $line_item = array('name' => html_entity_decode($product->get_title() ? $product->get_title() : $item['name'], ENT_NOQUOTES, 'UTF-8'), 'sku' => $product->get_sku(), 'quantity' => $item['qty'], 'total' => wc_format_decimal($order->get_line_total($item), 2), 'refunded' => wc_format_decimal($order->get_total_refunded_for_item($item_id), 2), 'meta' => html_entity_decode($meta, ENT_NOQUOTES, 'UTF-8'));
         // add line item tax
         $line_tax_data = isset($item['line_tax_data']) ? $item['line_tax_data'] : array();
         $tax_data = maybe_unserialize($line_tax_data);
         $line_item['tax'] = isset($tax_data['total']) ? wc_format_decimal(wc_round_tax_total(array_sum((array) $tax_data['total'])), 2) : '';
         /**
          * CSV Order Export Line Item.
          *
          * Filter the individual line item entry for the default export
          *
          * @since 3.0.6
          * @param array $line_item {
          *     line item data in key => value format
          *     the keys are for convenience and not used for exporting. Make
          *     sure to prefix the values with the desired line item entry name
          * }
          *
          * @param array $item WC order item data
          * @param WC_Product $product the product
          * @param WC_Order $order the order
          * @param \WC_Customer_Order_CSV_Export_Generator $this, generator instance
          */
         $line_item = apply_filters('wc_customer_order_csv_export_order_line_item', $line_item, $item, $product, $order, $this);
         if ('default_one_row_per_item' !== $this->order_format && is_array($line_item)) {
             foreach ($line_item as $name => $value) {
                 $line_item[$name] = $name . ':' . $value;
             }
             $line_item = implode('|', $line_item);
         }
         if ($line_item) {
             $line_items[] = $line_item;
         }
     }
     foreach ($order->get_shipping_methods() as $_ => $shipping_item) {
         $shipping_items[] = implode('|', array('method:' . $shipping_item['name'], 'total:' . wc_format_decimal($shipping_item['cost'], 2)));
     }
     // get fee items & total
     $fee_total = 0;
     $fee_tax_total = 0;
     foreach ($order->get_fees() as $fee_id => $fee) {
         $fee_items[] = implode('|', array('name:' . $fee['name'], 'total:' . wc_format_decimal($fee['line_total'], 2), 'tax:' . wc_format_decimal($fee['line_tax'], 2)));
         $fee_total += $fee['line_total'];
         $fee_tax_total += $fee['line_tax'];
     }
     // get tax items
     foreach ($order->get_tax_totals() as $tax_code => $tax) {
         $tax_items[] = implode('|', array('code:' . $tax_code, 'total:' . wc_format_decimal($tax->amount, 2)));
     }
     // add coupons
     foreach ($order->get_items('coupon') as $_ => $coupon_item) {
         $coupon = new WC_Coupon($coupon_item['name']);
         $coupon_post = get_post($coupon->id);
         $coupon_items[] = implode('|', array('code:' . $coupon_item['name'], 'description:' . (is_object($coupon_post) ? $coupon_post->post_excerpt : ''), 'amount:' . wc_format_decimal($coupon_item['discount_amount'], 2)));
     }
     $order_data = array('order_id' => $order->id, 'order_number' => $order->get_order_number(), 'order_date' => $order->order_date, 'status' => $order->get_status(), 'shipping_total' => $order->get_total_shipping(), 'shipping_tax_total' => wc_format_decimal($order->get_shipping_tax(), 2), 'fee_total' => wc_format_decimal($fee_total, 2), 'fee_tax_total' => wc_format_decimal($fee_tax_total, 2), 'tax_total' => wc_format_decimal($order->get_total_tax(), 2), 'cart_discount' => SV_WC_Plugin_Compatibility::is_wc_version_gte_2_3() ? wc_format_decimal($order->get_total_discount(), 2) : wc_format_decimal($order->get_cart_discount(), 2), 'order_discount' => SV_WC_Plugin_Compatibility::is_wc_version_gte_2_3() ? wc_format_decimal($order->get_total_discount(), 2) : wc_format_decimal($order->get_order_discount(), 2), 'discount_total' => wc_format_decimal($order->get_total_discount(), 2), 'order_total' => wc_format_decimal($order->get_total(), 2), 'refunded_total' => wc_format_decimal($order->get_total_refunded(), 2), 'order_currency' => $order->get_order_currency(), 'payment_method' => $order->payment_method, 'shipping_method' => $order->get_shipping_method(), 'customer_id' => $order->get_user_id(), 'billing_first_name' => $order->billing_first_name, 'billing_last_name' => $order->billing_last_name, 'billing_company' => $order->billing_company, 'billing_email' => $order->billing_email, 'billing_phone' => $order->billing_phone, 'billing_address_1' => $order->billing_address_1, 'billing_address_2' => $order->billing_address_2, 'billing_postcode' => $order->billing_postcode, 'billing_city' => $order->billing_city, 'billing_state' => $order->billing_state, 'billing_country' => $order->billing_country, 'shipping_first_name' => $order->shipping_first_name, 'shipping_last_name' => $order->shipping_last_name, 'shipping_company' => $order->shipping_company, 'shipping_address_1' => $order->shipping_address_1, 'shipping_address_2' => $order->shipping_address_2, 'shipping_postcode' => $order->shipping_postcode, 'shipping_city' => $order->shipping_city, 'shipping_state' => $order->shipping_state, 'shipping_country' => $order->shipping_country, 'customer_note' => $order->customer_note, 'shipping_items' => implode(';', $shipping_items), 'fee_items' => implode(';', $fee_items), 'tax_items' => implode(';', $tax_items), 'coupon_items' => implode(';', $coupon_items), 'order_notes' => implode('|', $this->get_order_notes($order)), 'download_permissions' => $order->download_permissions_granted ? $order->download_permissions_granted : 0);
     if ('default_one_row_per_item' === $this->order_format) {
         $new_order_data = array();
         foreach ($line_items as $item) {
             $order_data['item_name'] = $item['name'];
             $order_data['item_sku'] = $item['sku'];
             $order_data['item_quantity'] = $item['quantity'];
             $order_data['item_tax'] = $item['tax'];
             $order_data['item_total'] = $item['total'];
             $order_data['item_refunded'] = $item['refunded'];
             $order_data['item_meta'] = $item['meta'];
             /**
              * CSV Order Export Row for One Row per Item.
              *
              * Filter the individual row data for the order export
              *
              * @since 3.3.0
              * @param array $order_data {
              *     order data in key => value format
              *     to modify the row data, ensure the key matches any of the header keys and set your own value
              * }
              * @param array $item
              * @param \WC_Order $order WC Order object
              * @param \WC_Customer_Order_CSV_Export_Generator $this, generator instance
              */
             $new_order_data[] = apply_filters('wc_customer_order_csv_export_order_row_one_row_per_item', $order_data, $item, $order, $this);
         }
         $order_data = $new_order_data;
     } else {
         $order_data['line_items'] = implode(';', $line_items);
     }
     /**
      * CSV Order Export Row.
      *
      * Filter the individual row data for the order export
      *
      * @since 3.0
      * @param array $order_data {
      *     order data in key => value format
      *     to modify the row data, ensure the key matches any of the header keys and set your own value
      * }
      * @param \WC_Order $order WC Order object
      * @param \WC_Customer_Order_CSV_Export_Generator $this, generator instance
      */
     return apply_filters('wc_customer_order_csv_export_order_row', $order_data, $order, $this);
 }
コード例 #6
0
 /**
  * Add contribution settings to product settings page
  *
  * @since 1.0.0
  * @param  array $settings
  * @return array
  */
 public function add_contribution_settings($settings)
 {
     $contribution_settings = $this->get_contribution_settings();
     if (SV_WC_Plugin_Compatibility::is_wc_version_gte_2_3()) {
         $new_settings = array();
         foreach ($settings as $setting) {
             $new_settings[] = $setting;
             if ('product_rating_options' === $setting['id'] && 'title' === $setting['type']) {
                 foreach ($contribution_settings as $contribution_setting) {
                     $new_settings[] = $contribution_setting;
                 }
             }
         }
         $settings = $new_settings;
     } else {
         $insert_key = $end_key = null;
         foreach ($settings as $key => $setting) {
             if ('woocommerce_enable_review_rating' === $setting['id']) {
                 $insert_key = $key;
             }
             if ('product_data_options' === $setting['id']) {
                 $end_key = $key;
             }
         }
         // Break settings into parts
         $before = array_slice($settings, 0, $insert_key);
         $ratings = array_slice($settings, $insert_key, $end_key - $insert_key + 1);
         $after = array_slice($settings, $end_key + 1);
         // Adjust the ratings sectionend ID
         $ratings[count($ratings) - 1]['id'] = 'product_contributions_options';
         // Merge settings together again
         $settings = array_merge($before, $contribution_settings, $ratings, $after);
     }
     return $settings;
 }
コード例 #7
0
/**
 * Display our custom product Area/Volume meta fields in the product
 * variation form
 *
 * @param int $loop the loop index
 * @param array $variation_data the variation data
 * @param WP_Post $variation the variation post object
 */
function wc_price_calculator_product_after_variable_attributes($loop, $variation_data, $variation)
{
    global $post;
    // WooCommerce 2.3 removed meta data from the $variation_data array, let's add it back
    if (SV_WC_Plugin_Compatibility::is_wc_version_gte_2_3()) {
        $variation_data = array_merge(get_post_meta($variation->ID), $variation_data);
    }
    // will use the parent area/volume (if set) as the placeholder
    $parent_data = array('area' => $post ? get_post_meta($post->ID, '_area', true) : null, 'volume' => $post ? get_post_meta($post->ID, '_volume', true) : null);
    // default placeholders
    if (!$parent_data['area']) {
        $parent_data['area'] = '0.00';
    }
    if (!$parent_data['volume']) {
        $parent_data['volume'] = '0';
    }
    if (SV_WC_Plugin_Compatibility::is_wc_version_gte_2_3()) {
        ?>
		<div>
			<p class="form-row form-row-first hide_if_variation_virtual">
				<label><?php 
        _e('Area', WC_Measurement_Price_Calculator::TEXT_DOMAIN) . ' (' . esc_html(get_option('woocommerce_area_unit')) . '):';
        ?>
 <a class="tips" data-tip="<?php 
        _e('Overrides the area calculated from the width/length dimensions for the Measurements Price Calculator.', WC_Measurement_Price_Calculator::TEXT_DOMAIN);
        ?>
" href="#">[?]</a></label>
				<input type="number" size="5" name="variable_area[<?php 
        echo $loop;
        ?>
]" value="<?php 
        if (isset($variation_data['_area'][0])) {
            echo esc_attr($variation_data['_area'][0]);
        }
        ?>
" placeholder="<?php 
        echo $parent_data['area'];
        ?>
" step="any" min="0" />
			</p>
			<p class="form-row form-row-last hide_if_variation_virtual">
				<label><?php 
        _e('Volume', WC_Measurement_Price_Calculator::TEXT_DOMAIN) . ' (' . esc_html(get_option('woocommerce_volume_unit')) . '):';
        ?>
 <a class="tips" data-tip="<?php 
        _e('Overrides the volume calculated from the width/length/height dimensions for the Measurements Price Calculator.', WC_Measurement_Price_Calculator::TEXT_DOMAIN);
        ?>
" href="#">[?]</a></label>
				<input type="number" size="5" name="variable_volume[<?php 
        echo $loop;
        ?>
]" value="<?php 
        if (isset($variation_data['_volume'][0])) {
            echo esc_attr($variation_data['_volume'][0]);
        }
        ?>
" placeholder="<?php 
        echo $parent_data['volume'];
        ?>
" step="any" min="0" />
			</p>
		</div>
	<?php 
    } else {
        ?>
		<tr>
			<td class="hide_if_variation_virtual">
				<label><?php 
        _e('Area', WC_Measurement_Price_Calculator::TEXT_DOMAIN) . ' (' . esc_html(get_option('woocommerce_area_unit')) . '):';
        ?>
 <a class="tips" data-tip="<?php 
        _e('Overrides the area calculated from the width/length dimensions for the Measurements Price Calculator.', WC_Measurement_Price_Calculator::TEXT_DOMAIN);
        ?>
" href="#">[?]</a></label>
				<input type="number" size="5" name="variable_area[<?php 
        echo $loop;
        ?>
]" value="<?php 
        if (isset($variation_data['_area'][0])) {
            echo esc_attr($variation_data['_area'][0]);
        }
        ?>
" placeholder="<?php 
        echo $parent_data['area'];
        ?>
" step="any" min="0" />
			</td>
			<td class="hide_if_variation_virtual">
				<label><?php 
        _e('Volume', WC_Measurement_Price_Calculator::TEXT_DOMAIN) . ' (' . esc_html(get_option('woocommerce_volume_unit')) . '):';
        ?>
 <a class="tips" data-tip="<?php 
        _e('Overrides the volume calculated from the width/length/height dimensions for the Measurements Price Calculator.', WC_Measurement_Price_Calculator::TEXT_DOMAIN);
        ?>
" href="#">[?]</a></label>
				<input type="number" size="5" name="variable_volume[<?php 
        echo $loop;
        ?>
]" value="<?php 
        if (isset($variation_data['_volume'][0])) {
            echo esc_attr($variation_data['_volume'][0]);
        }
        ?>
" placeholder="<?php 
        echo $parent_data['volume'];
        ?>
" step="any" min="0" />
			</td>
		</tr>
	<?php 
    }
}
    ?>
			</select>
		</p>
	</td>

	<td class="content-restriction-objects objects-column">
		<p class="form-field">
			<label for="_content_restriction_rules_<?php 
    echo esc_attr($index);
    ?>
_object_ids"><?php 
    esc_html_e('Title', WC_Memberships::TEXT_DOMAIN);
    ?>
:</label>
			<?php 
    if (SV_WC_Plugin_Compatibility::is_wc_version_gte_2_3()) {
        ?>
				<input type="hidden" class="wc-memberships-object-search js-object-ids" style="width: 50%;" id="_content_restriction_rules_<?php 
        echo esc_attr($index);
        ?>
_object_ids" name="_content_restriction_rules[<?php 
        echo esc_attr($index);
        ?>
][object_ids]" data-placeholder="<?php 
        esc_attr_e('Search&hellip; or leave blank to apply to all', WC_Memberships::TEXT_DOMAIN);
        ?>
" data-action="<?php 
        echo esc_attr($rule->get_object_search_action_name());
        ?>
" data-multiple="true" data-selected="<?php 
        $json_ids = array();
コード例 #9
0
 /**
  * AJAX search handler for chosen fields.  Searches for checkout add-ons
  * and returns the results.
  *
  * @since 1.0
  */
 public function add_json_search_field()
 {
     global $wpdb;
     check_ajax_referer('search-field', 'security');
     // the search term
     $term = isset($_GET['term']) ? urldecode(stripslashes(strip_tags($_GET['term']))) : '';
     // the field to search
     $id = isset($_GET['request_data']['add_on_id']) ? urldecode(stripslashes(strip_tags($_GET['request_data']['add_on_id']))) : '';
     // required parameters
     if (empty($term) || empty($id)) {
         die;
     }
     $default = isset($_GET['request_data']['default']) ? $_GET['request_data']['default'] : '';
     $found_values = SV_WC_Plugin_Compatibility::is_wc_version_gte_2_3() ? array() : array('' => $default);
     $query = $wpdb->prepare("\n\t\t\tSELECT woim_value.meta_value\n\t\t\tFROM {$wpdb->prefix}woocommerce_order_itemmeta woim_id\n\t\t\tJOIN {$wpdb->prefix}woocommerce_order_itemmeta woim_value ON woim_id.order_item_id = woim_value.order_item_id\n\t\t\tWHERE 1=1\n\t\t\t\tAND woim_id.meta_key = '_wc_checkout_add_on_id'\n\t\t\t\tAND woim_id.meta_value = %d\n\t\t\t\tAND woim_value.meta_key = '_wc_checkout_add_on_value'\n\t\t\t\tAND woim_value.meta_value LIKE %s\n\t\t", $id, '%' . $term . '%');
     $results = $wpdb->get_results($query);
     if ($results) {
         foreach ($results as $result) {
             $found_values[$result->meta_value] = $result->meta_value;
         }
     }
     echo json_encode($found_values);
     exit;
 }
コード例 #10
0
 /**
  * AJAX search handler for chosen fields.  Searches for custom order admin fields
  * and returns the results.
  *
  * @since 1.0
  */
 public function add_json_search_field()
 {
     global $wpdb;
     check_ajax_referer('search-field', 'security');
     // the search term
     $term = isset($_GET['term']) ? urldecode(stripslashes(strip_tags($_GET['term']))) : '';
     // the field to search
     $field_name = isset($_GET['request_data']['field_name']) ? urldecode(stripslashes(strip_tags($_GET['request_data']['field_name']))) : '';
     if (empty($term) || empty($field_name)) {
         die;
     }
     $default = isset($_GET['request_data']['default']) ? $_GET['request_data']['default'] : '';
     $found_values = SV_WC_Plugin_Compatibility::is_wc_version_gte_2_3() ? array() : array('' => $default);
     $results = $wpdb->get_results($wpdb->prepare("SELECT meta_value FROM " . $wpdb->postmeta . " WHERE meta_key = %s and meta_value LIKE %s", $field_name, '%' . $term . '%'));
     if ($results) {
         foreach ($results as $result) {
             $found_values[$result->meta_value] = $result->meta_value;
         }
     }
     echo json_encode($found_values);
     die;
 }
コード例 #11
0
 /**
  * Enqueue admin scripts & styles
  *
  * @since 1.0.0
  * @param string $hook_suffix The current URL filename, ie edit.php, post.php, etc
  */
 public function enqueue_scripts_and_styles($hook_suffix)
 {
     global $typenow, $pagenow;
     $load_scripts = false;
     // Post types valid for restriction (and thus, loading out JS/CSS)
     $restrictable_post_types = array_keys($this->get_valid_post_types_for_content_restriction());
     $restrictable_post_types[] = 'product';
     // Only load scripts on appropriate screens
     if (('post.php' === $hook_suffix || 'post-new.php' === $hook_suffix) && in_array($typenow, $restrictable_post_types)) {
         $load_scripts = true;
     } else {
         if (in_array($typenow, array('wc_user_membership', 'wc_membership_plan'))) {
             $load_scripts = true;
         } else {
             if (wc_memberships()->is_plugin_settings()) {
                 $load_scripts = true;
             }
         }
     }
     // Bail out if not a memberships screen (or a post type valid for restriction)
     if (!$load_scripts) {
         return;
     }
     $screen = get_current_screen();
     if ('edit-wc_user_membership' == $screen->id || 'wc_user_membership' == $screen->id) {
         wp_enqueue_style('wp-pointer');
         wp_enqueue_script('wp-pointer');
     }
     // enqueue admin styles
     wp_enqueue_style('wc-memberships-admin', wc_memberships()->get_plugin_url() . '/assets/css/admin/wc-memberships-admin.min.css', WC_Memberships::VERSION);
     if (!SV_WC_Plugin_Compatibility::is_wc_version_gte_2_3()) {
         wp_enqueue_style('wc-memberships-admin-wc-pre-2_3', wc_memberships()->get_plugin_url() . '/assets/css/admin/wc-memberships-admin-wc-pre-2_3.min.css', array('woocommerce_admin_styles'), WC_Memberships::VERSION);
     }
     // enqueue admin scripts
     $dependencies = SV_WC_Plugin_Compatibility::is_wc_version_gte_2_3() ? array('jquery') : array('jquery', 'chosen');
     if ('wc_user_membership' == $typenow && 'post.php' == $pagenow) {
         $dependencies[] = 'jquery-ui-datepicker';
     }
     wp_enqueue_script('wc-memberships-admin', wc_memberships()->get_plugin_url() . '/assets/js/admin/wc-memberships-admin.min.js', $dependencies, WC_Memberships::VERSION);
     wp_localize_script('wc-memberships-admin', 'wc_memberships_admin', array('ajax_url' => admin_url('admin-ajax.php'), 'search_products_nonce' => wp_create_nonce("search-products"), 'search_posts_nonce' => wp_create_nonce("search-posts"), 'search_terms_nonce' => wp_create_nonce("search-terms"), 'wc_plugin_url' => WC()->plugin_url(), 'calendar_image' => WC()->plugin_url() . '/assets/images/calendar.png', 'new_user_membership_url' => admin_url('post-new.php?post_type=wc_user_membership'), 'is_wc_gte_2_3' => SV_WC_Plugin_Compatibility::is_wc_version_gte_2_3(), 'search_customers_nonce' => wp_create_nonce('search-customers'), 'add_user_membership_note_nonce' => wp_create_nonce('add-user-membership-note'), 'delete_user_membership_note_nonce' => wp_create_nonce('delete-user-membership-note'), 'restrictable_post_types' => $restrictable_post_types, 'i18n' => array('select_user' => __('Select user', WC_Memberships::TEXT_DOMAIN), 'add_member' => __('Add Member', WC_Memberships::TEXT_DOMAIN), 'cancel' => __('Cancel', WC_Memberships::TEXT_DOMAIN), 'search_for_user' => __('Search for a user&hellip;', WC_Memberships::TEXT_DOMAIN))));
 }
コード例 #12
0
 /**
  * Load admin js/css
  *
  * @since 1.0.0
  */
 public function load_styles_scripts()
 {
     // Get admin screen id
     $screen = get_current_screen();
     // order status edit screen specific styles & scripts
     if ('wc_order_status' == $screen->id) {
         // color picker script/styles
         wp_enqueue_script('wp-color-picker');
         wp_enqueue_style('wp-color-picker');
         // jquery fonticonpicker
         wp_enqueue_script('jquery-fonticonpicker', wc_order_status_manager()->get_plugin_url() . '/assets/js/jquery-fonticonpicker/jquery.fonticonpicker.min.js', array('jquery'), WC_Order_Status_Manager::VERSION);
         wp_enqueue_style('wc-order-status-manager-jquery-fonticonpicker', wc_order_status_manager()->get_plugin_url() . '/assets/css/admin/wc-order-status-manager-jquery-fonticonpicker.min.css', null, WC_Order_Status_Manager::VERSION);
         wp_enqueue_media();
     }
     if ('edit-shop_order' == $screen->id) {
         // Font Awesome font & classes
         wp_enqueue_style('font-awesome', wc_order_status_manager()->get_plugin_url() . '/assets/css/font-awesome.min.css', null, WC_Order_Status_Manager::VERSION);
     }
     // Load styles and scripts on order status screens
     if ($this->is_order_status_manager_screen()) {
         // load WC admin CSS
         wp_enqueue_style('woocommerce_admin_styles', WC()->plugin_url() . '/assets/css/admin.css');
         // admin CSS
         wp_enqueue_style('wc-order-status-manager-admin', wc_order_status_manager()->get_plugin_url() . '/assets/css/admin/wc-order-status-manager-admin.min.css', array('woocommerce_admin_styles'), WC_Order_Status_Manager::VERSION);
         // WooCommerce font class declarations
         wp_enqueue_style('woocommerce-font-classes', wc_order_status_manager()->get_plugin_url() . '/assets/css/woocommerce-font-classes.min.css', array('woocommerce_admin_styles'), WC_Order_Status_Manager::VERSION);
         // Font Awesome font & classes
         wp_enqueue_style('font-awesome', wc_order_status_manager()->get_plugin_url() . '/assets/css/font-awesome.min.css', null, WC_Order_Status_Manager::VERSION);
         // admin JS
         wp_enqueue_script('wc-order-status-manager-admin', wc_order_status_manager()->get_plugin_url() . '/assets/js/admin/wc-order-status-manager-admin.min.js', array('jquery', 'jquery-tiptip', SV_WC_Plugin_Compatibility::is_wc_version_gte_2_3() ? 'select2' : 'chosen'), WC_Order_Status_Manager::VERSION);
         // localize admin JS
         $order_statuses = array();
         foreach (wc_get_order_statuses() as $slug => $name) {
             $order_statuses[str_replace('wc-', '', $slug)] = $name;
         }
         $script_data = array('ajax_url' => admin_url('admin-ajax.php'), 'order_statuses' => $order_statuses, 'i18n' => array('remove_this_condition' => __('Remove this condition?', WC_Order_Status_Manager::TEXT_DOMAIN), 'from_status' => __('From Status', WC_Order_Status_Manager::TEXT_DOMAIN), 'to_status' => __('To Status', WC_Order_Status_Manager::TEXT_DOMAIN), 'remove' => __('Remove', WC_Order_Status_Manager::TEXT_DOMAIN), 'any' => __('Any', WC_Order_Status_Manager::TEXT_DOMAIN), 'select_icon' => __('Select Icon', WC_Order_Status_Manager::TEXT_DOMAIN), 'all_icon_packages' => __('All icon packages', WC_Order_Status_Manager::TEXT_DOMAIN), 'search_icons' => __('Search Icons', WC_Order_Status_Manager::TEXT_DOMAIN), 'choose_file' => __('Choose a file', WC_Order_Status_Manager::TEXT_DOMAIN)));
         if ('wc_order_status' == $screen->id) {
             // Create a flat list of icon classes for icon options, we
             // do not need the glyphs there
             $icon_options = array();
             foreach (wc_order_status_manager()->icons->get_icon_options() as $package => $icons) {
                 $icon_options[$package] = array_keys($icons);
             }
             $script_data['icon_options'] = $icon_options;
         }
         wp_localize_script('wc-order-status-manager-admin', 'wc_order_status_manager', $script_data);
     }
 }
    /**
     * Display the memberships meta box
     *
     * @param WP_Post $post
     * @since 1.0.0
     */
    public function output(WP_Post $post)
    {
        $product = wc_get_product($post);
        $grant_access_to_plans = $this->get_product_membership_plans($post->ID);
        // Prepare membership plan options
        $membership_plan_options = array();
        $membership_plans = wc_memberships_get_membership_plans(array('post_status' => array('publish', 'private', 'future', 'draft', 'pending', 'trash')));
        if (!empty($membership_plans)) {
            foreach ($membership_plans as $membership_plan) {
                $state = '';
                if ('publish' != $membership_plan->post->post_status) {
                    $state = ' ' . __('(inactive)', WC_Memberships::TEXT_DOMAIN);
                }
                $membership_plan_options[$membership_plan->get_id()] = $membership_plan->get_name() . $state;
            }
        }
        // Prepare access_type options for product restriction rules
        $product_restriction_access_type_options = array('view' => __('view', WC_Memberships::TEXT_DOMAIN), 'purchase' => __('purchase', WC_Memberships::TEXT_DOMAIN));
        // Prepare period options
        $access_schedule_period_toggler_options = array('immediate' => __('immediately', WC_Memberships::TEXT_DOMAIN), 'specific' => __('specify a time', WC_Memberships::TEXT_DOMAIN));
        $period_options = array('days' => __('day(s)', WC_Memberships::TEXT_DOMAIN), 'weeks' => __('week(s)', WC_Memberships::TEXT_DOMAIN), 'months' => __('month(s)', WC_Memberships::TEXT_DOMAIN), 'years' => __('year(s)', WC_Memberships::TEXT_DOMAIN));
        // Get applied restriction rules
        $product_restriction_rules = wc_memberships()->rules->get_rules(array('rule_type' => 'product_restriction', 'object_id' => $post->ID, 'content_type' => 'post_type', 'content_type_name' => $post->post_type, 'exclude_inherited' => false, 'plan_status' => 'any'));
        // Add empty option to create a HTML template for new rules
        $membership_plan_ids = array_keys($membership_plan_options);
        $product_restriction_rules['__INDEX__'] = new WC_Memberships_Membership_Plan_Rule(array('rule_type' => 'product_restriction', 'object_ids' => array($post->ID), 'id' => '', 'membership_plan_id' => array_shift($membership_plan_ids), 'access_schedule' => 'immediate', 'access_type' => ''));
        // Get applied restriction rules
        $purchasing_discount_rules = wc_memberships()->rules->get_rules(array('rule_type' => 'purchasing_discount', 'object_id' => $post->ID, 'content_type' => 'post_type', 'content_type_name' => $post->post_type, 'exclude_inherited' => false, 'plan_status' => 'any'));
        // Add empty option to create a HTML template for new rules
        $purchasing_discount_rules['__INDEX__'] = new WC_Memberships_Membership_Plan_Rule(array('rule_type' => 'purchasing_discount', 'object_ids' => array($post->ID), 'id' => '', 'membership_plan_id' => '', 'discount_type' => '', 'discount_amount' => '', 'active' => ''));
        // prepare product restriction access_type options
        $purchasing_discount_type_options = array('percentage' => '%', 'amount' => '$');
        ?>

		<p class="grouped-notice <?php 
        if (!$product->is_type('grouped')) {
            ?>
hide<?php 
        }
        ?>
">
			<?php 
        esc_html_e("Memberships do not support grouped products.", WC_Memberships::TEXT_DOMAIN);
        ?>
		</p>

		<div class="panel-wrap wc-memberships-data <?php 
        if ($product->is_type('grouped')) {
            ?>
hide<?php 
        }
        ?>
">

			<?php 
        if (!SV_WC_Plugin_Compatibility::is_wc_version_gte_2_3()) {
            ?>
				<div class="wc-tabs-back"></div>
			<?php 
        }
        ?>

			<ul class="memberships_data_tabs wc-tabs">
				<?php 
        /**
         * Filter product memberships data tabs
         *
         * @since 1.0.0
         * @param array $tabs Associative array of memberships data tabs
         */
        $memberships_data_tabs = apply_filters('wc_memberships_product_data_tabs', array('restrict_product' => array('label' => __('Restrict Content', WC_Memberships::TEXT_DOMAIN), 'class' => array('active'), 'target' => 'memberships-data-restrict-product'), 'grant_access' => array('label' => __('Grant Access', WC_Memberships::TEXT_DOMAIN), 'target' => 'memberships-data-grant-access'), 'purchasing_discounts' => array('label' => __('Discounts', WC_Memberships::TEXT_DOMAIN), 'target' => 'memberships-data-purchasing-discounts')));
        foreach ($memberships_data_tabs as $key => $tab) {
            $class = isset($tab['class']) ? $tab['class'] : array();
            ?>
<li class="<?php 
            echo sanitize_html_class($key);
            ?>
_options <?php 
            echo sanitize_html_class($key);
            ?>
_tab <?php 
            echo implode(' ', array_map('sanitize_html_class', $class));
            ?>
">
							<a href="#<?php 
            echo esc_attr($tab['target']);
            ?>
"><?php 
            echo esc_html($tab['label']);
            ?>
</a>
						</li><?php 
        }
        /**
         * Fires after the product memberships data write panel tabs are displayed
         *
         * @since 1.0.0
         */
        do_action('wc_memberships_data_product_write_panel_tabs');
        ?>
			</ul>


			<div id="memberships-data-restrict-product" class="panel woocommerce_options_panel">

				<p class="variable-notice <?php 
        if (!$product->is_type('variable')) {
            ?>
hide<?php 
        }
        ?>
">
					<?php 
        esc_html_e('These rules affect all variations. For variation-level control use the membership plan screen.', WC_Memberships::TEXT_DOMAIN);
        ?>
				</p>

				<?php 
        woocommerce_wp_checkbox(array('id' => '_wc_memberships_force_public', 'class' => 'js-toggle-rules', 'label' => __('Disable restrictions', WC_Memberships::TEXT_DOMAIN), 'description' => __('Check this box if you want to force this product to be public regardless of any restriction rules that may apply now or in the future.', WC_Memberships::TEXT_DOMAIN)));
        ?>

				<div class="js-restrictions <?php 
        if (get_post_meta($post->ID, '_wc_memberships_force_public', true) == 'yes') {
            ?>
hide<?php 
        }
        ?>
">

					<div class="options_group">
						<div class="table-wrap">
							<?php 
        require wc_memberships()->get_plugin_path() . '/includes/admin/meta-boxes/views/html-product-restriction-rules.php';
        ?>
						</div>
					</div>

					<?php 
        if (!empty($membership_plans)) {
            ?>
						<p>
							<em><?php 
            esc_html_e('Need to add or edit a plan?', WC_Memberships::TEXT_DOMAIN);
            ?>
</em> <a target="_blank" href="<?php 
            echo admin_url('edit.php?post_type=wc_membership_plan');
            ?>
"><?php 
            esc_html_e('Manage Membership Plans', WC_Memberships::TEXT_DOMAIN);
            ?>
</a>
						</p>
					<?php 
        }
        ?>

					<div class="options_group">

						<?php 
        woocommerce_wp_checkbox(array('id' => '_wc_memberships_use_custom_product_viewing_restricted_message', 'class' => 'js-toggle-custom-message', 'label' => __('Use custom message', WC_Memberships::TEXT_DOMAIN), 'description' => __('Check this box if you want to customize the <strong>viewing restricted message</strong> for this product.', WC_Memberships::TEXT_DOMAIN)));
        ?>

						<div class="js-custom-message-editor-container <?php 
        if (get_post_meta($post->ID, '_wc_memberships_use_custom_product_viewing_restricted_message', true) !== 'yes') {
            ?>
hide<?php 
        }
        ?>
">
						<?php 
        $message = get_post_meta($post->ID, '_wc_memberships_product_viewing_restricted_message', true);
        echo '<p>' . sprintf(__('<code>%s</code> automatically inserts the product(s) needed to gain access. <code>%s</code> inserts the URL to my account page. HTML is allowed.', WC_Memberships::TEXT_DOMAIN), '{products}', '{login_url}') . '</p>';
        wp_editor($message, '_wc_memberships_product_viewing_restricted_message', array('textarea_rows' => 5, 'teeny' => true));
        ?>
						</div>

					</div>

					<div class="options_group">

						<?php 
        woocommerce_wp_checkbox(array('id' => '_wc_memberships_use_custom_product_purchasing_restricted_message', 'class' => 'js-toggle-custom-message', 'label' => __('Use custom message', WC_Memberships::TEXT_DOMAIN), 'description' => __('Check this box if you want to customize the <strong>purchasing restricted message</strong> for this product.', WC_Memberships::TEXT_DOMAIN)));
        ?>

						<div class="js-custom-message-editor-container <?php 
        if (get_post_meta($post->ID, '_wc_memberships_use_custom_product_purchasing_restricted_message', true) !== 'yes') {
            ?>
hide<?php 
        }
        ?>
">
						<?php 
        $message = get_post_meta($post->ID, '_wc_memberships_product_purchasing_restricted_message', true);
        echo '<p>' . sprintf(__('<code>%s</code> automatically inserts the product(s) needed to gain access. <code>%s</code> inserts the URL to my account page. HTML is allowed.', WC_Memberships::TEXT_DOMAIN), '{products}', '{login_url}') . '</p>';
        wp_editor($message, '_wc_memberships_product_purchasing_restricted_message', array('textarea_rows' => 5, 'teeny' => true));
        ?>
						</div>

					</div>
				</div>

				<?php 
        /**
         * Fires after the product memberships data product restriction panel is displayed
         *
         * @since 1.0.0
         */
        do_action('wc_memberships_data_options_restrict_product');
        ?>
			</div><!-- //#memberships-data-restrict-products -->


			<div id="memberships-data-grant-access" class="panel woocommerce_options_panel">

				<p class="variable-notice <?php 
        if (!$product->is_type('variable')) {
            ?>
hide<?php 
        }
        ?>
">
					<?php 
        _e("These settings affect all variations. For variation-level control use the membership plan screen.", WC_Memberships::TEXT_DOMAIN);
        ?>
				</p>

				<!-- Plans that this product grants access to -->
				<div class="options_group">

				<?php 
        if (empty($membership_plans)) {
            ?>
					<p>
						<?php 
            esc_html_e('To grant membership access, please', WC_Memberships::TEXT_DOMAIN);
            ?>
 <a target="_blank" href="<?php 
            echo admin_url('post-new.php?post_type=wc_membership_plan');
            ?>
"><?php 
            esc_html_e('Add a Membership Plan', WC_Memberships::TEXT_DOMAIN);
            ?>
</a>.
					</p>
				<?php 
        } else {
            ?>

					<p class="form-field"><label for="_wc_memberships_membership_plan_ids"><?php 
            esc_html_e('Purchasing grants access to', WC_Memberships::TEXT_DOMAIN);
            ?>
</label>

					<?php 
            if (SV_WC_Plugin_Compatibility::is_wc_version_gte_2_3()) {
                ?>
						<input type="hidden" class="js-membership-plan-ids" style="width: 50%;" id="_wc_memberships_membership_plan_ids" name="_wc_memberships_membership_plan_ids" data-placeholder="<?php 
                esc_attr_e('Search for a membership plan&hellip;', WC_Memberships::TEXT_DOMAIN);
                ?>
" data-action="wc_memberships_search_membership_plans" data-multiple="true" data-selected="<?php 
                $json_ids = array();
                if (!empty($grant_access_to_plans)) {
                    foreach ($grant_access_to_plans as $plan) {
                        if (is_object($plan)) {
                            $json_ids[$plan->get_id()] = wp_kses_post(html_entity_decode($plan->get_name()));
                        }
                    }
                }
                echo esc_attr(wc_memberships()->wp_json_encode($json_ids));
                ?>
" value="<?php 
                echo esc_attr(implode(',', array_keys($json_ids)));
                ?>
" />

					<?php 
            } else {
                ?>
						<select name="_wc_memberships_membership_plan_ids[]" class="js-membership-plan-ids" id="_wc_memberships_membership_plan_ids" multiple="multiple" data-placeholder="<?php 
                esc_attr_e('Search for a membership plan&hellip;', WC_Memberships::TEXT_DOMAIN);
                ?>
">
							<?php 
                if (!empty($grant_access_to_plans)) {
                    foreach ($grant_access_to_plans as $plan) {
                        echo '<option value="' . esc_attr($plan->get_id()) . '" selected="selected">' . esc_html($plan->get_name()) . '</option>';
                    }
                }
                ?>
						</select>
					<?php 
            }
            ?>

					<img class="help_tip" data-tip="<?php 
            esc_attr_e('Select which membership plans does purchasing this product grant access tp.', WC_Memberships::TEXT_DOMAIN);
            ?>
" src="<?php 
            echo esc_url(WC()->plugin_url());
            ?>
/assets/images/help.png" height="16" width="16" /></p>

					<p>
						<em><?php 
            esc_html_e('Need to add or edit a plan?', WC_Memberships::TEXT_DOMAIN);
            ?>
</em> <a target="_blank" href="<?php 
            echo admin_url('edit.php?post_type=wc_membership_plan');
            ?>
"><?php 
            esc_html_e('Manage Membership Plans', WC_Memberships::TEXT_DOMAIN);
            ?>
</a>
					</p>

				<?php 
        }
        ?>

				</div>

				<?php 
        /**
         * Fires after the product memberships data grant access panel is displayed
         *
         * @since 1.0.0
         */
        do_action('wc_memberships_data_options_grant_access');
        ?>
			</div><!-- //#memberships-data-grant-access -->


			<div id="memberships-data-purchasing-discounts" class="panel woocommerce_options_panel">

				<p class="variable-notice <?php 
        if (!$product->is_type('variable')) {
            ?>
hide<?php 
        }
        ?>
">
					<?php 
        esc_html_e('These rules affect all variations. For variation-level control use the membership plan screen', WC_Memberships::TEXT_DOMAIN);
        ?>
				</p>

				<div class="table-wrap">
					<?php 
        require wc_memberships()->get_plugin_path() . '/includes/admin/meta-boxes/views/html-purchasing-discount-rules.php';
        ?>
				</div>

				<?php 
        /**
         * Fires after the membership plan purchasing discounts panel is displayed
         *
         * @since 1.0.0
         */
        do_action('wc_memberships_data_options_purchasing_discounts');
        ?>
			</div><!-- //#memberships-data-purchase-discounts -->

			<?php 
        /**
         * Fires after the product memberships data panels are displayed
         *
         * @since 1.0.0
         */
        do_action('wc_memberships_data_product_panels');
        ?>

			<div class="clear"></div>

		</div><!-- //.panel-wrap -->
		<?php 
    }
コード例 #14
0
 /**
  * Set up the DoExpressCheckoutPayment request
  *
  * @link https://developer.paypal.com/docs/classic/express-checkout/integration-guide/ECGettingStarted/#id084RN060BPF
  * @link https://developer.paypal.com/webapps/developer/docs/classic/api/merchant/DoExpressCheckoutPayment_API_Operation_NVP/
  *
  * @since 3.0.0
  * @param \WC_Order $order order object
  * @param string $type
  */
 private function do_payment(WC_Order $order, $type)
 {
     $this->set_method('DoExpressCheckoutPayment');
     // set base params
     $this->add_parameters(array('TOKEN' => $order->paypal_express_token, 'PAYERID' => !empty($order->paypal_express_payer_id) ? $order->paypal_express_payer_id : null, 'BUTTONSOURCE' => 'WooThemes_Cart', 'RETURNFMFDETAILS' => 1));
     $order_subtotal = $i = 0;
     $order_items = array();
     // add line items
     foreach ($order->get_items() as $item) {
         $product = new WC_Product($item['product_id']);
         $order_items[] = array('NAME' => SV_WC_Helper::str_truncate(html_entity_decode($product->get_title(), ENT_QUOTES, 'UTF-8'), 127), 'DESC' => $this->get_item_description($item, $product), 'AMT' => $order->get_item_subtotal($item), 'QTY' => !empty($item['qty']) ? absint($item['qty']) : 1, 'ITEMURL' => $product->get_permalink());
         $order_subtotal += $item['line_total'];
     }
     // add fees
     foreach ($order->get_fees() as $fee) {
         $order_items[] = array('NAME' => SV_WC_Helper::str_truncate($fee['name'], 127), 'AMT' => $fee['line_total'], 'QTY' => 1);
         $order_subtotal += $fee['line_total'];
     }
     if (SV_WC_Plugin_Compatibility::is_wc_version_gte_2_3()) {
         // WC 2.3+, no after-tax discounts
         if ($order->get_total_discount() > 0) {
             $order_items[] = array('NAME' => __('Total Discount', WC_Paypal_Express::TEXT_DOMAIN), 'QTY' => 1, 'AMT' => -$order->get_total_discount());
         }
     } else {
         // WC 2.2 or lesser
         // add cart discounts as line item
         if ($order->get_cart_discount() > 0) {
             $order_items[] = array('NAME' => __('Cart Discount', WC_Paypal_Express::TEXT_DOMAIN), 'QTY' => 1, 'AMT' => -$order->get_cart_discount());
         }
         // add order discounts as line item
         if ($order->get_order_discount() > 0) {
             $order_items[] = array('NAME' => __('Order Discount', WC_Paypal_Express::TEXT_DOMAIN), 'QTY' => 1, 'AMT' => -$order->get_order_discount());
         }
     }
     $total_discount = SV_WC_Plugin_Compatibility::is_wc_version_gte_2_3() ? 0 : $order->get_order_discount();
     // order subtotal includes pre-tax discounts in 2.3
     if ($this->skip_line_items($order)) {
         $item_names = array();
         foreach ($order_items as $item) {
             $item_names[] = sprintf('%s x %s', $item['NAME'], $item['QTY']);
         }
         // add a single item for the entire order
         $this->add_line_item_parameters(array('NAME' => sprintf(__('%s - Order', WC_PayPal_Express::TEXT_DOMAIN), get_option('blogname')), 'DESC' => SV_WC_Helper::str_truncate(html_entity_decode(implode(', ', $item_names), ENT_QUOTES, 'UTF-8'), 127), 'AMT' => $order_subtotal - $total_discount + $order->get_cart_tax(), 'QTY' => 1), 0);
         // add order-level parameters
         //  - Do not sent the TAXAMT due to rounding errors
         $this->add_payment_parameters(array('AMT' => $order->get_total(), 'CURRENCYCODE' => $order->get_order_currency(), 'ITEMAMT' => $order_subtotal - $total_discount + $order->get_cart_tax(), 'SHIPPINGAMT' => $order->get_total_shipping() + $order->get_shipping_tax(), 'INVNUM' => $order->paypal_express_invoice_prefix . SV_WC_Helper::str_to_ascii(ltrim($order->get_order_number(), _x('#', 'hash before the order number', WC_PayPal_Express::TEXT_DOMAIN))), 'PAYMENTACTION' => $type, 'PAYMENTREQUESTID' => $order->id));
     } else {
         // add individual order items
         foreach ($order_items as $item) {
             $this->add_line_item_parameters($item, $i++);
         }
         // add order-level parameters
         $this->add_payment_parameters(array('AMT' => $order->get_total(), 'CURRENCYCODE' => $order->get_order_currency(), 'ITEMAMT' => $order_subtotal - $total_discount, 'SHIPPINGAMT' => $order->get_total_shipping(), 'TAXAMT' => $order->get_total_tax(), 'INVNUM' => $order->paypal_express_invoice_prefix . SV_WC_Helper::str_to_ascii(ltrim($order->get_order_number(), _x('#', 'hash before the order number', WC_PayPal_Express::TEXT_DOMAIN))), 'PAYMENTACTION' => $type, 'PAYMENTREQUESTID' => $order->id));
     }
 }
コード例 #15
0
    /**
     * Add rating and media type dropdowns to reviews list screen filter
     */
    public function restrict_manage_reviews()
    {
        $rating_options = array('' => __('All ratings', 'wc-product-reviews-pro'), '5' => __('Perfect', 'wc-product-reviews-pro'), '4' => __('Good', 'wc-product-reviews-pro'), '3' => __('Average', 'wc-product-reviews-pro'), '2' => __('Mediocre', 'wc-product-reviews-pro'), '1' => __('Poor', 'wc-product-reviews-pro'));
        $current_rating = isset($_REQUEST['rating']) ? $_REQUEST['rating'] : '';
        ?>
		<select name="rating">
			<?php 
        foreach ($rating_options as $value => $label) {
            ?>
				<option value="<?php 
            echo $value;
            ?>
" <?php 
            selected($current_rating, $value);
            ?>
><?php 
            echo $label;
            ?>
</option>
			<?php 
        }
        ?>
		</select>

		<?php 
        $current_product = isset($_REQUEST['p']) ? $_REQUEST['p'] : '';
        $current_product_name = '';
        if ($current_product) {
            $product = SV_WC_Plugin_Compatibility::wc_get_product($current_product);
            $current_product_name = $product->get_formatted_name();
        }
        ?>

		<?php 
        if (SV_WC_Plugin_Compatibility::is_wc_version_gte_2_3()) {
            ?>

			<input type="hidden" class="wc-product-search" name="p" data-placeholder="<?php 
            _e('Search for a product&hellip;', 'wc-product-reviews-pro');
            ?>
" data-selected="<?php 
            echo esc_attr($current_product_name);
            ?>
" value="<?php 
            echo esc_attr($current_product);
            ?>
" data-action="woocommerce_json_search_products" data-allow_clear="true" >

		<?php 
        } else {
            ?>

			<select name="p" class="ajax_chosen_select_product">
				<option value=""><?php 
            _e('All Products', 'wc-product-reviews-pro');
            ?>
</option>
				<?php 
            if ($current_product) {
                echo '<option value="' . esc_attr($current_product) . '" ' . selected(1, 1, false) . '>' . esc_html($current_product_name) . '</option>';
            }
            ?>
			</select>

			<?php 
            // Ajax Chosen Customer Selectors JS
            wc_enqueue_js("\n\t\t\t\tjQuery('select.ajax_chosen_select_product').ajaxChosen({\n\t\t\t\t\tmethod:         'GET',\n\t\t\t\t\turl:            '" . admin_url('admin-ajax.php') . "',\n\t\t\t\t\tdataType:       'json',\n\t\t\t\t\tafterTypeDelay: 100,\n\t\t\t\t\tminTermLength:  1,\n\t\t\t\t\tdata: {\n\t\t\t\t\t\taction:   'woocommerce_json_search_products',\n\t\t\t\t\t\tsecurity: '" . wp_create_nonce('search-products') . "'\n\t\t\t\t\t}\n\t\t\t\t}, function (data) {\n\n\t\t\t\t\tvar terms = {};\n\n\t\t\t\t\t\$.each(data, function (i, val) {\n\t\t\t\t\t\t\tterms[i] = val;\n\t\t\t\t\t});\n\n\t\t\t\t\treturn terms;\n\t\t\t\t});\n\t\t\t");
        }
    }
 /**
  * Adds any gateways supported by this plugin to the list of available payment gateways
  *
  * @since 1.0.0
  * @param array $gateways
  * @return array $gateways
  */
 public function load_gateways($gateways)
 {
     if (SV_WC_Plugin_Compatibility::is_wc_version_gte_2_3()) {
         $gateways = array_merge($gateways, $this->get_gateways());
     } else {
         $gateways = array_merge($gateways, $this->get_gateway_class_names());
     }
     return $gateways;
 }
コード例 #17
0
    /**
     * Add 'FreshBooks Item' select box on 'Variations' tab of variable product write-panel
     *
     * @since 3.0
     * @param int $loop_count current variation count
     * @param array $variation_data individual variation data
     */
    public function add_variable_product_item_mapping($loop_count, $variation_data, $variation)
    {
        // WooCommerce 2.3 removed meta data from the $variation_data array, let's add it back
        if (SV_WC_Plugin_Compatibility::is_wc_version_gte_2_3()) {
            $variation_data = array_merge(get_post_meta($variation->ID), $variation_data);
        }
        $saved_item_id = isset($variation_data['_wc_freshbooks_item_name'][0]) ? $variation_data['_wc_freshbooks_item_name'][0] : '';
        if (SV_WC_Plugin_Compatibility::is_wc_version_gte_2_3()) {
            ?>
			<div class="clearfix">
				<p class="form-row form-row-first">
					<label for="<?php 
            echo esc_attr('wc_freshbooks_item_name_' . $loop_count);
            ?>
"><?php 
            esc_html_e('FreshBooks Item', WC_FreshBooks::TEXT_DOMAIN);
            ?>
						<a class="tips" data-tip="<?php 
            esc_attr_e('Choose which FreshBooks item to link to this product.', WC_FreshBooks::TEXT_DOMAIN);
            ?>
" href="#">[?]</a>
					</label>
					<select id="<?php 
            echo esc_attr('wc_freshbooks_item_name_' . $loop_count);
            ?>
" name="<?php 
            printf('%s[%s]', 'variable_wc_freshbooks_item_name', $loop_count);
            ?>
" class="js-wc-freshbooks-item-select" style="min-width: 250px;">
						<option value="none"><?php 
            esc_html_e('None', WC_FreshBooks::TEXT_DOMAIN);
            ?>
</option>
						<?php 
            foreach ($this->get_active_items() as $item_id => $item_name) {
                printf('<option value="%s" %s>%s</option>', esc_attr($item_id), selected($item_id, $saved_item_id, false), esc_html($item_name));
            }
            ?>
					</select>
				</p>
				<p class="form-row form-row-last" style="margin-top: 2.8em;"><a id="<?php 
            echo 'wc_freshbooks_item_name_' . $loop_count;
            ?>
" class="js-wc-freshbooks-bulk-set-items" href="#"><?php 
            esc_html_e('Set all other variations to this item', WC_FreshBooks::TEXT_DOMAIN);
            ?>
</a></p>
			</div>
		<?php 
        } else {
            ?>
			<tr>
				<td>
					<label for="<?php 
            echo esc_attr('wc_freshbooks_item_name_' . $loop_count);
            ?>
"><?php 
            esc_html_e('FreshBooks Item', WC_FreshBooks::TEXT_DOMAIN);
            ?>
						<a class="tips" data-tip="<?php 
            esc_attr_e('Choose which FreshBooks item to link to this product.', WC_FreshBooks::TEXT_DOMAIN);
            ?>
" href="#">[?]</a>
					</label>
					<select id="<?php 
            echo esc_attr('wc_freshbooks_item_name_' . $loop_count);
            ?>
" name="<?php 
            printf('%s[%s]', 'variable_wc_freshbooks_item_name', $loop_count);
            ?>
" class="js-wc-freshbooks-item-select" style="min-width: 250px;">
						<option value="none"><?php 
            esc_html_e('None', WC_FreshBooks::TEXT_DOMAIN);
            ?>
</option>
						<?php 
            foreach ($this->get_active_items() as $item_id => $item_name) {
                printf('<option value="%s" %s>%s</option>', esc_attr($item_id), selected($item_id, $saved_item_id, false), esc_html($item_name));
            }
            ?>
					</select>
				</td>
				<td style="vertical-align: bottom; padding-bottom: 1em;"><a id="<?php 
            echo 'wc_freshbooks_item_name_' . $loop_count;
            ?>
" class="js-wc-freshbooks-bulk-set-items" href="#"><?php 
            esc_html_e('Set all other variations to this item', WC_FreshBooks::TEXT_DOMAIN);
            ?>
</a></td>
			</tr>
		<?php 
        }
    }
    /**
     * Display the voucher select box in the product variation meta box for
     * downloadable variable products
     *
     * @since 1.2
     * @param int $loop loop counter
     * @param array $variation_data associative array of variation data
     */
    public function product_after_variable_attributes($loop, $variation_data, $variation)
    {
        // WooCommerce 2.3 removed meta data from the $variation_data array, let's add it back
        if (SV_WC_Plugin_Compatibility::is_wc_version_gte_2_3()) {
            $variation_data = array_merge(get_post_meta($variation->ID), $variation_data);
        }
        $options = array('' => '');
        // get all the published vouchers
        foreach (wc_pdf_product_vouchers()->get_voucher_handler()->get_vouchers() as $voucher) {
            $options[$voucher->ID] = $voucher->post_title;
        }
        if (SV_WC_Plugin_Compatibility::is_wc_version_gte_2_3()) {
            ?>
			<div class="show_if_variation_downloadable" style="display:none;">
				<p class="form-row form-row-first">
					<label><?php 
            _e('Voucher:', WC_PDF_Product_Vouchers::TEXT_DOMAIN);
            ?>
 <a class="tips" data-tip="<?php 
            _e('Select a voucher rather than providing a file path', WC_PDF_Product_Vouchers::TEXT_DOMAIN);
            ?>
" href="#">[?]</a></label><select class="variable_voucher" name="variable_voucher_id[<?php 
            echo $loop;
            ?>
]"><?php 
            foreach ($options as $voucher_id => $name) {
                echo '<option value="' . $voucher_id . '" ';
                if (isset($variation_data['_voucher_id'][0])) {
                    selected($voucher_id, $variation_data['_voucher_id'][0]);
                }
                echo '>' . $name . '</option>';
            }
            ?>
</select>
				</p>
			</div>
		<?php 
        } else {
            ?>
			<tr class="show_if_variation_downloadable" style="display:none;">
				<td>
					<label><?php 
            _e('Voucher:', WC_PDF_Product_Vouchers::TEXT_DOMAIN);
            ?>
 <a class="tips" data-tip="<?php 
            _e('Select a voucher rather than providing a file path', WC_PDF_Product_Vouchers::TEXT_DOMAIN);
            ?>
" href="#">[?]</a></label><select class="variable_voucher" name="variable_voucher_id[<?php 
            echo $loop;
            ?>
]"><?php 
            foreach ($options as $voucher_id => $name) {
                echo '<option value="' . $voucher_id . '" ';
                if (isset($variation_data['_voucher_id'][0])) {
                    selected($voucher_id, $variation_data['_voucher_id'][0]);
                }
                echo '>' . $name . '</option>';
            }
            ?>
</select>
				</td>
				<td>&nbsp;</td>
			</tr>
		<?php 
        }
    }
    /**
     * Display the membership data meta box
     *
     * @param WP_Post $post
     * @since 1.0.0
     */
    public function output(WP_Post $post)
    {
        global $post;
        $membership_plan = wc_memberships_get_membership_plan($post);
        // Place post types and taxonomies into separate option groups
        // so that they are easier to distinguish visually.
        $content_restriction_content_type_options = array('post_types' => array(), 'taxonomies' => array());
        // We need to prefix post_type/taxonomy names (values), so that
        // if a post type and taxonomy share a name, we can still distinguish
        // between them
        foreach (wc_memberships()->admin->get_valid_post_types_for_content_restriction() as $post_type_name => $post_type) {
            $content_restriction_content_type_options['post_types']['post_type|' . $post_type_name] = $post_type;
        }
        foreach (wc_memberships()->admin->get_valid_taxonomies_for_content_restriction() as $taxonomy_name => $taxonomy) {
            $content_restriction_content_type_options['taxonomies']['taxonomy|' . $taxonomy_name] = $taxonomy;
        }
        // Prepare access_length period toggler options
        $access_length_period_toggler_options = array('unlimited' => __('unlimited', WC_Memberships::TEXT_DOMAIN), 'specific' => __('specify a length', WC_Memberships::TEXT_DOMAIN));
        // Prepare access_schedule period toggler options
        $access_schedule_period_toggler_options = array('immediate' => __('immediately', WC_Memberships::TEXT_DOMAIN), 'specific' => __('specify a time', WC_Memberships::TEXT_DOMAIN));
        $period_options = array('days' => __('day(s)', WC_Memberships::TEXT_DOMAIN), 'weeks' => __('week(s)', WC_Memberships::TEXT_DOMAIN), 'months' => __('month(s)', WC_Memberships::TEXT_DOMAIN), 'years' => __('year(s)', WC_Memberships::TEXT_DOMAIN));
        // Get applied content restriction rules
        $content_restriction_rules = $membership_plan->get_content_restriction_rules();
        // Add empty option to create a HTML template for new rules
        $content_restriction_rules['__INDEX__'] = new WC_Memberships_Membership_Plan_Rule(array('rule_type' => 'content_restriction', 'membership_plan_id' => $post->ID, 'id' => '', 'content_type' => '', 'content_type_name' => '', 'object_ids' => array(), 'access_schedule' => 'immediate', 'access_schedule_exclude_trial' => 'no'));
        // Prepare product content type options
        $post_type_product = get_post_type_object('product');
        $product_restriction_content_type_options = $purchasing_discount_content_type_options = array('post_types' => array('post_type|product' => $post_type_product), 'taxonomies' => array());
        // prepare product restriction access_type options
        $product_restriction_access_type_options = array('view' => __('View', WC_Memberships::TEXT_DOMAIN), 'purchase' => __('Purchase', WC_Memberships::TEXT_DOMAIN));
        foreach (wc_memberships()->admin->get_valid_taxonomies_for_product_restriction() as $taxonomy_name => $taxonomy) {
            $product_restriction_content_type_options['taxonomies']['taxonomy|' . $taxonomy_name] = $taxonomy;
        }
        foreach (wc_memberships()->admin->get_valid_taxonomies_for_purchasing_discounts() as $taxonomy_name => $taxonomy) {
            $purchasing_discount_content_type_options['taxonomies']['taxonomy|' . $taxonomy_name] = $taxonomy;
        }
        // Get applied product restriction rules
        $product_restriction_rules = $membership_plan->get_product_restriction_rules();
        // Add empty option to create a HTML template for new rules
        $product_restriction_rules['__INDEX__'] = new WC_Memberships_Membership_Plan_Rule(array('rule_type' => 'product_restriction', 'membership_plan_id' => $post->ID, 'id' => '', 'content_type' => '', 'content_type_name' => '', 'object_ids' => array(), 'access_type' => '', 'access_schedule' => 'immediate', 'access_schedule_exclude_trial' => 'no'));
        // prepare product restriction access_type options
        $purchasing_discount_type_options = array('percentage' => '%', 'amount' => '$');
        // Get applied product restriction rules
        $purchasing_discount_rules = $membership_plan->get_purchasing_discount_rules();
        // Add empty option to create a HTML template for new rules
        $purchasing_discount_rules['__INDEX__'] = new WC_Memberships_Membership_Plan_Rule(array('rule_type' => 'purchasing_discount', 'membership_plan_id' => $post->ID, 'id' => '', 'content_type' => '', 'content_type_name' => '', 'object_ids' => array(), 'discount_type' => '', 'discount_amount' => '', 'active' => ''));
        ?>

		<div class="panel-wrap data">

			<?php 
        if (!SV_WC_Plugin_Compatibility::is_wc_version_gte_2_3()) {
            ?>
				<div class="wc-tabs-back"></div>
			<?php 
        }
        ?>

			<ul class="membership_plan_data_tabs wc-tabs">
				<?php 
        /**
         * Filter membership plan data tabs
         *
         * @since 1.0.0
         * @param array $tabs Associative array of membership plan tabs
         */
        $membership_plan_data_tabs = apply_filters('wc_membership_plan_data_tabs', array('general' => array('label' => __('General', WC_Memberships::TEXT_DOMAIN), 'target' => 'membership-plan-data-general', 'class' => array('active')), 'restrict_content' => array('label' => __('Restrict Content', WC_Memberships::TEXT_DOMAIN), 'target' => 'membership-plan-data-restrict-content'), 'restrict_products' => array('label' => __('Restrict Products', WC_Memberships::TEXT_DOMAIN), 'target' => 'membership-plan-data-restrict-products'), 'purchasing_discounts' => array('label' => __('Purchasing Discounts', WC_Memberships::TEXT_DOMAIN), 'target' => 'membership-plan-data-purchasing-discounts')));
        foreach ($membership_plan_data_tabs as $key => $tab) {
            $class = isset($tab['class']) ? $tab['class'] : array();
            ?>
<li class="<?php 
            echo sanitize_html_class($key);
            ?>
_options <?php 
            echo sanitize_html_class($key);
            ?>
_tab <?php 
            echo implode(' ', array_map('sanitize_html_class', $class));
            ?>
">
							<a href="#<?php 
            echo esc_attr($tab['target']);
            ?>
"><?php 
            echo esc_html($tab['label']);
            ?>
</a>
						</li><?php 
        }
        /**
         * Fires after the membership plan write panel tabs are displayed
         *
         * @since 1.0.0
         */
        do_action('wc_membership_plan_write_panel_tabs');
        ?>
			</ul>


			<div id="membership-plan-data-general" class="panel woocommerce_options_panel"><?php 
        echo '<div class="options_group">';
        // Slug
        woocommerce_wp_text_input(array('id' => 'post_name', 'label' => __('Slug', WC_Memberships::TEXT_DOMAIN), 'value' => $post->post_name));
        echo '</div>';
        echo '<div class="options_group">';
        ?>
				<p class="form-field"><label for="_product_ids"><?php 
        esc_html_e('Grant Access to people who purchase:', WC_Memberships::TEXT_DOMAIN);
        ?>
</label>

				<?php 
        if (SV_WC_Plugin_Compatibility::is_wc_version_gte_2_3()) {
            ?>
					<input type="hidden" id="_product_ids" name="_product_ids" class="js-ajax-select-products" style="width: 50%;" data-placeholder="<?php 
            esc_attr_e('Search for a product&hellip;', WC_Memberships::TEXT_DOMAIN);
            ?>
" data-multiple="true" data-selected="<?php 
            $product_ids = array_filter(array_map('absint', (array) get_post_meta($post->ID, '_product_ids', true)));
            $json_ids = array();
            foreach ($product_ids as $product_id) {
                $product = wc_get_product($product_id);
                if (is_object($product)) {
                    $json_ids[$product_id] = wp_kses_post(html_entity_decode($product->get_formatted_name()));
                }
            }
            echo esc_attr(wc_memberships()->wp_json_encode($json_ids));
            ?>
" value="<?php 
            echo esc_attr(implode(',', array_keys($json_ids)));
            ?>
" />
				<?php 
        } else {
            ?>
					<select id="_product_ids" id="_product_ids" name="_product_ids[]" class="ajax_chosen_select_products js-ajax-select-products" multiple="multiple" data-placeholder="<?php 
            esc_attr_e('Search for a product&hellip;', WC_Memberships::TEXT_DOMAIN);
            ?>
">
						<?php 
            if ($membership_plan->get_product_ids()) {
                foreach ($membership_plan->get_product_ids() as $product_id) {
                    $product = wc_get_product($product_id);
                    if ($product) {
                        echo '<option value="' . esc_attr($product_id) . '" selected="selected">' . strip_tags($product->get_formatted_name()) . '</option>';
                    }
                }
            }
            ?>
					</select>
				<?php 
        }
        ?>

				<img class="help_tip" data-tip="<?php 
        esc_attr_e('Leave empty to only allow members you manually assign.', WC_Memberships::TEXT_DOMAIN);
        ?>
" src="<?php 
        echo esc_url(WC()->plugin_url());
        ?>
/assets/images/help.png" height="16" width="16" />

				</p>

				<p class="form-field plan-access-length-field">
					<label for="_access_length"><?php 
        esc_html_e('Membership Length', WC_Memberships::TEXT_DOMAIN);
        ?>
</label>

					<span class="plan-access-length-selectors">
						<?php 
        $current_access_length = $membership_plan->get_access_length() ? 'specific' : 'unlimited';
        ?>
						<?php 
        foreach ($access_length_period_toggler_options as $value => $label) {
            ?>
							<label class="label-radio">
								<input type="radio" name="_access_length" class="js-access-length-period-selector js-access-length-type" value="<?php 
            echo esc_attr($value);
            ?>
" <?php 
            checked($value, $current_access_length);
            ?>
 />
								<?php 
            echo esc_html($label);
            ?>
							</label>
						<?php 
        }
        ?>
						<img class="help_tip" data-tip="<?php 
        esc_attr_e('When does the membership expire?', WC_Memberships::TEXT_DOMAIN);
        ?>
" src="<?php 
        echo esc_url(WC()->plugin_url());
        ?>
/assets/images/help.png" height="16" width="16" />
					</span>

					<span class="plan-access-length-specific js-hide-if-access-length-unlimited <?php 
        if (!$membership_plan->get_access_length()) {
            ?>
hide<?php 
        }
        ?>
">

						<input type="number" min="0" name="_access_length_amount" id="_access_length_amount" value="<?php 
        echo esc_attr($membership_plan->get_access_length_amount());
        ?>
" class="access_length-amount" />

						<select name="_access_length_period" id="_access_length_period" class="short access_length-period js-access-length-period-selector">
							<?php 
        foreach ($period_options as $key => $label) {
            ?>
								<option value="<?php 
            echo esc_attr($key);
            ?>
" <?php 
            selected($key, $membership_plan->get_access_length_period());
            ?>
><?php 
            echo esc_html($label);
            ?>
</option>
							<?php 
        }
        ?>
						</select>

					</span>

				</p>

				<?php 
        echo '</div>';
        /**
         * Fires after the membership plan general data panel is displayed
         *
         * @since 1.0.0
         */
        do_action('wc_membership_plan_options_membership_plan_data_general');
        ?>
			</div><!-- //#membership-plan-data-general -->


			<div id="membership-plan-data-restrict-content" class="panel woocommerce_options_panel">

				<div class="table-wrap">
					<?php 
        require wc_memberships()->get_plugin_path() . '/includes/admin/meta-boxes/views/html-content-restriction-rules.php';
        ?>
				</div>

				<?php 
        if ($public_posts = wc_memberships()->rules->get_public_posts()) {
            ?>
					<p><?php 
            printf(__('These posts are public, and will be excluded from all restriction rules: %s', WC_Memberships::TEXT_DOMAIN), wc_memberships()->admin_list_post_links($public_posts));
            ?>
</p>
				<?php 
        }
        ?>

				<?php 
        /**
         * Fires after the membership plan content restriction panel is displayed
         *
         * @since 1.0.0
         */
        do_action('wc_membership_plan_options_membership_plan_data_restrict_content');
        ?>
			</div><!-- //#membership-plan-data-restrict-content -->


			<div id="membership-plan-data-restrict-products" class="panel woocommerce_options_panel">

				<div class="table-wrap">
					<?php 
        require wc_memberships()->get_plugin_path() . '/includes/admin/meta-boxes/views/html-product-restriction-rules.php';
        ?>
				</div>

				<?php 
        if ($public_products = wc_memberships()->rules->get_public_products()) {
            ?>
					<p><?php 
            printf(__('These products are public, and will be excluded from all restriction rules: %s', WC_Memberships::TEXT_DOMAIN), wc_memberships()->admin_list_post_links($public_products));
            ?>
</p>
				<?php 
        }
        ?>

				<?php 
        /**
         * Fires after the membership plan product restriction panel is displayed
         *
         * @since 1.0.0
         */
        do_action('wc_membership_plan_options_membership_plan_data_restrict_products');
        ?>
			</div><!-- //#membership-plan-data-restrict-products -->


			<div id="membership-plan-data-purchasing-discounts" class="panel woocommerce_options_panel">

				<div class="table-wrap">
					<?php 
        require wc_memberships()->get_plugin_path() . '/includes/admin/meta-boxes/views/html-purchasing-discount-rules.php';
        ?>
				</div>

				<?php 
        /**
         * Fires after the membership plan purchasing discounts panel is displayed
         *
         * @since 1.0.0
         */
        do_action('wc_membership_plan_options_membership_plan_data_purchasing_discounts');
        ?>
			</div><!-- //#membership-plan-data-purchase-discounts -->

			<?php 
        /**
         * Fires after the membership plan data panels are displayed
         *
         * @since 1.0.0
         */
        do_action('wc_membership_plan_data_panels');
        ?>

			<div class="clear"></div>

		</div><!-- //.panel-wrap -->

		<?php 
    }
    /**
     * Render dropdowns for any filterable checkout add-ons
     *
     * @since 1.0
     */
    public function restrict_orders()
    {
        global $typenow;
        if ('shop_order' != $typenow) {
            return;
        }
        $javascript = '';
        foreach (wc_checkout_add_ons()->get_add_ons() as $add_on) {
            // if the add-on is filterable
            if ($add_on->is_filterable()) {
                if ($add_on->has_options()) {
                    // filterable multi item add-on field (select, multiselect, radio, checkbox), provide a dropdown
                    ?>
					<select name="<?php 
                    echo esc_attr($add_on->get_key());
                    ?>
" id="<?php 
                    echo esc_attr($add_on->get_key());
                    ?>
" class="wc-enhanced-select" data-placeholder="<?php 
                    echo __("Show all ", WC_Checkout_Add_Ons::TEXT_DOMAIN) . $add_on->name;
                    ?>
" data-allow_clear="true" style="min-width:200px;">
						<option value=""></option>
						<?php 
                    foreach ($add_on->get_options() as $option) {
                        if ('' === $option['value'] && '' === $option['label']) {
                            continue;
                        }
                        echo '<option value="' . $option['value'] . '" ' . (isset($_GET[$add_on->get_key()]) ? selected($option['value'], $_GET[$add_on->get_key()]) : '') . '>' . __($option['label'], WC_Checkout_Add_Ons::TEXT_DOMAIN) . '</option>';
                    }
                    ?>
					</select>
					<?php 
                    $javascript .= SV_WC_Plugin_Compatibility::is_wc_version_lt_2_3() ? "if ( \$().chosen ) { \$('select#" . $add_on->get_key() . "').chosen( {  allow_single_deselect: true  } ); }" : "";
                } elseif ($add_on->type == 'text') {
                    if (SV_WC_Plugin_Compatibility::is_wc_version_gte_2_3()) {
                        ?>
						<input type="hidden" class="sv-wc-enhanced-search" name="<?php 
                        echo esc_attr($add_on->get_key());
                        ?>
" style="min-width:200px;"
							data-placeholder="<?php 
                        echo __("Show all ", WC_Checkout_Add_Ons::TEXT_DOMAIN) . $add_on->label;
                        ?>
"
							data-selected="<?php 
                        echo empty($_GET[$add_on->get_key()]) ? '' : $_GET[$add_on->get_key()];
                        ?>
"
							value="<?php 
                        echo empty($_GET[$add_on->get_key()]) ? '' : esc_attr($_GET[$add_on->get_key()]);
                        ?>
"
							data-allow_clear="true"
							data-action="wc_checkout_add_ons_json_search_field"
							data-nonce="<?php 
                        echo wp_create_nonce('search-field');
                        ?>
"
							data-request_data = "<?php 
                        echo esc_attr(json_encode(array('add_on_id' => $add_on->id, 'default' => addslashes(__('Show all ', WC_Checkout_Add_Ons::TEXT_DOMAIN) . $add_on->name))));
                        ?>
"
							/>
						<?php 
                        SV_WC_Helper::render_select2_ajax();
                    } else {
                        // search box dropdown
                        ?>
						<select id="<?php 
                        echo esc_attr($add_on->get_key());
                        ?>
" name="<?php 
                        echo esc_attr($add_on->get_key());
                        ?>
" data-placeholder="<?php 
                        echo __("Show all ", WC_Checkout_Add_Ons::TEXT_DOMAIN) . $add_on->name;
                        ?>
" data-allow_clear="true" style="min-width:200px;">
							<option value=""></option>
							<?php 
                        if (!empty($_GET[$add_on->get_key()])) {
                            echo '<option value="' . esc_attr($_GET[$add_on->get_key()]) . '" ';
                            selected(1, 1);
                            echo '>' . $_GET[$add_on->get_key()] . '</option>';
                        }
                        ?>
						</select>
						<?php 
                        $javascript .= "\n\t\t\t\t\t\t\t\$( 'select#" . $add_on->get_key() . "' ).ajaxChosen( {\n\t\t\t\t\t\t\t\tmethod:         'GET',\n\t\t\t\t\t\t\t\turl:            '" . admin_url('admin-ajax.php') . "',\n\t\t\t\t\t\t\t\tdataType:       'json',\n\t\t\t\t\t\t\t\tafterTypeDelay: '100',\n\t\t\t\t\t\t\t\tminTermLength:  1,\n\t\t\t\t\t\t\t\tdata: {\n\t\t\t\t\t\t\t\t\taction:     'wc_checkout_add_ons_json_search_field',\n\t\t\t\t\t\t\t\t\tsecurity:   '" . wp_create_nonce("search-field") . "',\n\t\t\t\t\t\t\t\t\trequest_data: { 'add_on_id' : '" . $add_on->id . "', 'default' : '" . addslashes(__('Show all ', WC_Checkout_Add_Ons::TEXT_DOMAIN) . $add_on->name) . "' },\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}, function ( data ) {\n\n\t\t\t\t\t\t\t\tvar terms = {};\n\n\t\t\t\t\t\t\t\t\$.each( data, function ( i, val ) {\n\t\t\t\t\t\t\t\t\tterms[ i ] = val;\n\t\t\t\t\t\t\t\t} );\n\n\t\t\t\t\t\t\t\treturn terms;\n\t\t\t\t\t\t\t}, {  allow_single_deselect: true } );";
                    }
                } elseif ($add_on->type == 'checkbox' || $add_on->type == 'file') {
                    $checked = isset($_GET[$add_on->get_key()]) && $_GET[$add_on->get_key()];
                    ?>
					<label class="wc-checkout-add-on-checkbox-filter">
						<input type="checkbox" id="<?php 
                    echo esc_attr($add_on->get_key());
                    ?>
" name="<?php 
                    echo esc_attr($add_on->get_key());
                    ?>
" value="1" <?php 
                    checked($checked);
                    ?>
>
						<?php 
                    echo $add_on->name;
                    ?>
					</label>
					<?php 
                }
            }
        }
        // filterable dropdown javascript
        wc_enqueue_js($javascript);
    }
    /**
     * Render dropdowns for any filterable custom order fields
     *
     * @since 1.0
     */
    public function restrict_orders()
    {
        global $typenow;
        if ('shop_order' != $typenow) {
            return;
        }
        $javascript = '';
        foreach (wc_admin_custom_order_fields()->get_order_fields() as $order_field) {
            // if the field is filterable
            if ($order_field->is_filterable()) {
                if ($order_field->type == 'date') {
                    // filterable date field: provide a monthly dropdown
                    $this->render_months_dropdown($order_field->label, $order_field->get_meta_key());
                    $javascript .= "if ( ! \$().select2 && \$().chosen ) { \$( 'select#" . $order_field->get_meta_key() . "' ).chosen( { allow_single_deselect: true } ); }";
                } elseif ($order_field->has_options()) {
                    // filterable multi item field (select, multiselect, radio, checkbox), provide a dropdown
                    ?>
					<select name="<?php 
                    echo esc_attr($order_field->get_meta_key());
                    ?>
" id="<?php 
                    echo esc_attr($order_field->get_meta_key());
                    ?>
" class="wc-enhanced-select" data-placeholder="<?php 
                    echo __("Show all ", 'wc_admin_custom_order_fields') . $order_field->label;
                    ?>
" data-allow_clear="true" style="min-width:200px;">
						<option value=""></option>
						<?php 
                    foreach ($order_field->get_options() as $option) {
                        if ('' === $option['value'] && '' === $option['label']) {
                            continue;
                        }
                        echo '<option value="' . $option['value'] . '" ' . (isset($_GET[$order_field->get_meta_key()]) ? selected($option['value'], $_GET[$order_field->get_meta_key()]) : '') . '>' . __($option['label'], 'wc_admin_custom_order_fields') . '</option>';
                    }
                    ?>
					</select>
					<?php 
                    $javascript .= SV_WC_Plugin_Compatibility::is_wc_version_lt_2_3() ? "if ( ! \$().select2 && \$().chosen ) { \$('select#" . $order_field->get_meta_key() . "').chosen( { allow_single_deselect: true } ); }" : "";
                } elseif ($order_field->type == 'text') {
                    if (SV_WC_Plugin_Compatibility::is_wc_version_gte_2_3()) {
                        ?>
						<input type="hidden" class="sv-wc-enhanced-search" name="<?php 
                        echo esc_attr($order_field->get_meta_key());
                        ?>
" style="min-width:200px;"
							data-placeholder="<?php 
                        echo __('Show all ', 'wc_admin_custom_order_fields') . $order_field->label;
                        ?>
"
							data-selected="<?php 
                        echo empty($_GET[$order_field->get_meta_key()]) ? '' : $_GET[$order_field->get_meta_key()];
                        ?>
"
							value="<?php 
                        echo empty($_GET[$order_field->get_meta_key()]) ? '' : esc_attr($_GET[$order_field->get_meta_key()]);
                        ?>
"
							data-allow_clear="true"
							data-action="wc_admin_custom_order_fields_json_search_field"
							data-nonce="<?php 
                        echo wp_create_nonce('search-field');
                        ?>
"
							data-request_data = "<?php 
                        echo esc_attr(json_encode(array('field_name' => $order_field->get_meta_key(), 'default' => __('Show all ', 'wc_admin_custom_order_fields') . $order_field->label)));
                        ?>
"
							/>
						<?php 
                        SV_WC_Helper::render_select2_ajax();
                    } else {
                        // search box dropdown
                        ?>
						<select id="<?php 
                        echo esc_attr($order_field->get_meta_key());
                        ?>
" name="<?php 
                        echo esc_attr($order_field->get_meta_key());
                        ?>
" data-placeholder="<?php 
                        echo __('Show all ', 'wc_admin_custom_order_fields') . $order_field->label;
                        ?>
" data-allow_clear="true" style="min-width:200px;">
							<option value=""></option>
							<?php 
                        if (!empty($_GET[$order_field->get_meta_key()])) {
                            echo '<option value="' . esc_attr($_GET[$order_field->get_meta_key()]) . '" ';
                            selected(1, 1);
                            echo '>' . $_GET[$order_field->get_meta_key()] . '</option>';
                        }
                        ?>
						</select>
						<?php 
                        $javascript .= "\n\t\t\t\t\t\tif ( \$().ajaxChosen ) {\n\t\t\t\t\t\t\t\$( 'select#" . $order_field->get_meta_key() . "' ).ajaxChosen( {\n\t\t\t\t\t\t\t\tmethod:         'GET',\n\t\t\t\t\t\t\t\turl:            '" . admin_url('admin-ajax.php') . "',\n\t\t\t\t\t\t\t\tdataType:       'json',\n\t\t\t\t\t\t\t\tafterTypeDelay: '100',\n\t\t\t\t\t\t\t\tminTermLength:  1,\n\t\t\t\t\t\t\t\tdata: {\n\t\t\t\t\t\t\t\t\trequest_data: { 'field_name' : '" . $order_field->get_meta_key() . "', 'default' : '" . __('Show all ' . $order_field->label, 'wc_admin_custom_order_fields') . "' },\n\t\t\t\t\t\t\t\t\taction:       'wc_admin_custom_order_fields_json_search_field',\n\t\t\t\t\t\t\t\t\tsecurity:     '" . wp_create_nonce("search-field") . "',\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}, function ( data ) {\n\n\t\t\t\t\t\t\t\tvar terms = {};\n\n\t\t\t\t\t\t\t\t\$.each( data, function ( i, val ) {\n\t\t\t\t\t\t\t\t\tterms[ i ] = val;\n\t\t\t\t\t\t\t\t} );\n\n\t\t\t\t\t\t\t\treturn terms;\n\t\t\t\t\t\t\t}, {\n\t\t\t\t\t\t\t\tallow_single_deselect: true\n\t\t\t\t\t\t\t} );\n\t\t\t\t\t\t}\n\t\t\t\t\t\t";
                    }
                }
            }
        }
        // filterable dropdown javascript
        wc_enqueue_js($javascript);
    }