/** * Creates the Referfriend Meta Box in the admin control panel when in the Giftcard Post Type. Allows you to create a giftcard manually. * @param [type] $post * @return [type] */ function rf_meta_box($post) { global $woocommerce; wp_nonce_field('woocommerce_save_data', 'woocommerce_meta_nonce'); ?> <style type="text/css"> #edit-slug-box, #minor-publishing-actions { display:none } .form-field input, .form-field textarea { width:100%;} input[type="checkbox"], input[type="radio"] { float: left; width:16px;} </style> <div class="panel woocommerce_options_panel"> <?php woocommerce_wp_select(array('id' => 'rf_coupon_type', 'label' => __('Coupon Type', 'mg_referfriend'), 'placeholder' => '', 'description' => __('Coupon Type', 'mg_referfriend'), 'options' => wc_get_coupon_types())); woocommerce_wp_text_input(array('id' => 'rf_coupon_amount', 'label' => __('Coupon Amount', 'mg_referfriend'), 'placeholder' => '', 'description' => __('Coupon Amount', 'mg_referfriend'), 'type' => 'number', 'custom_attributes' => array('step' => 'any', 'min' => '0'))); woocommerce_wp_select(array('id' => 'rf_type', 'label' => __('Type', 'mg_referfriend'), 'placeholder' => '', 'options' => array('' => '', '1' => 'Refered by Email', '2' => 'Refered by share link'))); // Description woocommerce_wp_textarea_input(array('id' => 'rf_description', 'label' => __('Description', 'rpgiftcards'), 'placeholder' => '', 'description' => __('Description', 'rpgiftcards'))); woocommerce_wp_text_input(array('id' => 'rf_product_id', 'label' => __('Product IDs', 'mg_referfriend'), 'placeholder' => '', 'description' => __('Product IDs', 'mg_referfriend'), 'type' => 'number')); woocommerce_wp_text_input(array('id' => 'rf_usage', 'label' => __('Usage', 'mg_referfriend'), 'placeholder' => '', 'description' => __('Usage', 'mg_referfriend'))); woocommerce_wp_text_input(array('id' => 'rf_limit', 'label' => __('Limit', 'mg_referfriend'), 'placeholder' => '', 'description' => __('Limit', 'mg_referfriend'))); woocommerce_wp_text_input(array('id' => 'rf_expiry_date', 'label' => __('Expiry Date', 'mg_referfriend'), 'placeholder' => '', 'description' => __('Expiry Date', 'mg_referfriend'))); echo '</div>'; }
/** * Get a coupon type's name. * * @param string $type (default: '') * @return string */ function wc_get_coupon_type($type = '') { $types = wc_get_coupon_types(); if (isset($types[$type])) { return $types[$type]; } return ''; }
/** * @since 1.1.0 of SA_WC_Compatibility */ public static function wc_get_coupon_types() { if (self::is_wc_21()) { return wc_get_coupon_types(); } else { global $woocommerce; return $woocommerce->get_coupon_discount_types(); } }
/** * Get settings array * * @return array */ public function rf_genaral_setting($current_section = '') { $options = ''; $options = apply_filters('woocommerce_rf_genaral_setting', array(array('title' => __('Refer a Friend', 'mg_referfriend'), 'type' => 'title'), array('title' => __('Allow invite a friend', 'mg_referfriend'), 'id' => 'rf_enable_invitation', 'default' => 1, 'type' => 'checkbox'), array('title' => __('Allow share link', 'mg_referfriend'), 'id' => 'rf_enable_sharelink', 'default' => 1, 'type' => 'checkbox'), array('title' => __('Cookie of referral will expire after x days', 'mg_referfriend'), 'id' => 'rf_cookie_duration', 'default' => '30', 'type' => 'text'), array('title' => __('Reward affiliate and send notification email when status of order', 'mg_referfriend'), 'id' => 'magenest_rf_reward_when', 'type' => 'select', 'options' => array('completed' => __('Completed', 'mg_referfriend'), 'processing' => __('Processing', 'mg_referfriend'), 'on-hold' => __('On hold', 'mg_referfriend'), 'pending' => __('Pending', 'mg_referfriend')), 'autoload' => false), array('title' => __('Give bonus to referfal for friend registration', 'mg_referfriend'), 'id' => 'rf_bonus_signup', 'default' => 1, 'type' => 'checkbox'), array('name' => __('Coupon Amount for friend sign up', 'mg_referfriend'), 'desc' => __('This is the amount for the coupon sent after a friend received invitation and sign up', 'mg_referfriend'), 'id' => 'rf_coupon_sign_up_amount', 'type' => 'text'), array('type' => 'sectionend', 'id' => 'account_registration_options'), array('title' => __('Invitation Coupon Settings', 'mg_referfriend'), 'type' => 'title', 'desc' => __('Coupon is automatically insert in invitation email')), array('title' => __('Coupon Type', 'mg_referfriend'), 'id' => 'rf_invite_coupon_type', 'default' => 1, 'type' => 'select', 'options' => wc_get_coupon_types()), array('name' => __('Coupon Amount (in local currency)', 'mg_referfriend'), 'desc' => __('This is the amount for the coupon sent as a reward', 'mg_referfriend'), 'id' => 'rf_invite_coupon_amount', 'type' => 'text'), array('name' => __('Coupon Minimum Amount', 'mg_referfriend'), 'desc' => __('You can set minimum amount for the order', 'mg_referfriend'), 'id' => 'rf_invite_coupon_minimum_amount', 'type' => 'text'), array('name' => __('Coupon Duration', 'mg_referfriend'), 'desc' => __('Coupon duration is mandatory. Value is the number of days beginning on the coupong creation.', 'mg_referfriend'), 'id' => 'rf_invite_coupon_duration', 'type' => 'text'), array('title' => __('Individual Use', 'mg_referfriend'), 'desc' => __('individual use', 'mg_referfriend'), 'id' => 'rf_invite_individual_use', 'default' => 'no', 'type' => 'checkbox', 'autoload' => true), array('title' => __('Apply before tax', 'mg_referfriend'), 'desc' => __('Apply before tax', 'mg_referfriend'), 'id' => 'rf_invite_apply_before_tax', 'default' => 'no', 'type' => 'checkbox', 'autoload' => true), array('type' => 'sectionend', 'id' => 'product_referfriend_options'), array('title' => __('Reward Coupon Settings', 'mg_referfriend'), 'type' => 'title', 'desc' => __('Coupon is rewarded to referral after a friend received invitation email or follow the referral link and place order')), array('title' => __('Coupon Type', 'mg_referfriend'), 'id' => 'rf_reward_coupon_type', 'default' => 1, 'type' => 'select', 'options' => wc_get_coupon_types()), array('name' => __('Coupon Amount', 'mg_referfriend'), 'desc' => __('This is the amount for the coupon sent as a reward', 'mg_referfriend'), 'id' => 'rf_reward_coupon_amount', 'type' => 'text'), array('name' => __('Coupon Minimum Amount', 'mg_referfriend'), 'desc' => __('You can set minimum amount for the order', 'mg_referfriend'), 'id' => 'rf_reward_coupon_minimum_amount', 'type' => 'text'), array('name' => __('Coupon Duration', 'mg_referfriend'), 'desc' => __('Coupon duration is mandatory. Value is the number of days beginning on the coupong creation.', 'mg_referfriend'), 'id' => 'rf_reward_coupon_duration', 'type' => 'text'), array('title' => __('Individual Use', 'mg_referfriend'), 'desc' => __('individual use', 'mg_referfriend'), 'id' => 'rf_reward_individual_use', 'default' => 'no', 'type' => 'checkbox', 'autoload' => true), array('title' => __('Apply before tax', 'mg_referfriend'), 'desc' => __('Apply before tax', 'mg_referfriend'), 'id' => 'rf_reward_apply_before_tax', 'default' => 'no', 'type' => 'checkbox', 'autoload' => true), array('type' => 'sectionend', 'id' => 'product_referfriend_options'))); return apply_filters('rf_general_setting', $options); }
/** * @see CACIE_Editable_Model::get_editables_data() * @since 1.0 */ public function get_editables_data() { $data = array('author' => array('type' => 'select2_dropdown', 'property' => 'post_author', 'ajax_populate' => true), 'categories' => array('type' => 'select2_tags'), 'date' => array('type' => 'date', 'property' => 'post_date'), 'tags' => array('type' => 'select2_tags'), 'title' => array('type' => 'text', 'property' => 'post_title', 'js' => array('selector' => 'a.row-title'), 'display_ajax' => false), 'column-author_name' => array('type' => 'select2_dropdown', 'property' => 'post_author', 'ajax_populate' => true), 'column-attachment' => array('type' => 'media', 'attachment' => array('disable_select_current' => true), 'multiple' => true), 'column-comment_status' => array('type' => 'togglable', 'property' => 'comment_status', 'options' => array('closed', 'open')), 'column-excerpt' => array('type' => 'textarea', 'property' => 'post_excerpt', 'placeholder' => __('Excerpt automatically generated from content.', 'cpac')), 'column-featured_image' => array('type' => 'media', 'attachment' => array('library' => array('type' => 'image')), 'clear_button' => true), 'column-post_formats' => array('type' => 'select'), 'column-page_template' => array('type' => 'select'), 'column-parent' => array('type' => 'select2_dropdown', 'property' => 'post_parent', 'ajax_populate' => true, 'multiple' => false), 'column-ping_status' => array('type' => 'togglable', 'property' => 'ping_status', 'options' => array('closed', 'open')), 'column-content' => array('type' => 'textarea', 'property' => 'post_content'), 'column-order' => array('type' => 'text', 'property' => 'menu_order'), 'column-slug' => array('type' => 'text', 'property' => 'post_name'), 'column-sticky' => array('type' => 'togglable', 'options' => array('no', 'yes')), 'column-status' => array('type' => 'select', 'property' => 'post_status'), 'column-taxonomy' => array('type' => 'select2_tags'), 'column-meta' => array()); /** * WooCommerce columns * */ if (function_exists('WC')) { $wc_data = array('name' => array('type' => 'text', 'property' => 'post_title', 'js' => array('selector' => 'a.row-title'), 'display_ajax' => false), 'amount' => array('type' => 'text'), 'column-wc-minimum_amount' => array('type' => 'text'), 'order_status' => array('type' => 'select'), 'coupon_code' => array('type' => 'text', 'js' => array('selector' => '.row-actions'), 'property' => 'post_title'), 'column-wc-free_shipping' => array('type' => 'togglable', 'options' => array('no', 'yes')), 'column-wc-apply_before_tax' => array('type' => 'togglable', 'options' => array('no', 'yes')), 'price' => array('type' => 'wc_price'), 'column-wc-weight' => array('type' => 'float', 'js' => array('inputclass' => 'small-text')), 'column-wc-dimensions' => array('type' => 'dimensions'), 'sku' => array('type' => 'text'), 'is_in_stock' => array('type' => 'wc_stock'), 'column-wc-stock-status' => array('type' => 'togglable', 'options' => array('outofstock', 'instock')), 'type' => array('type' => 'select', 'options' => wc_get_coupon_types()), 'thumb' => array('type' => 'media', 'attachment' => array('library' => array('type' => 'image')), 'clear_button' => true), 'column-wc-upsells' => array('type' => 'select2_dropdown', 'ajax_populate' => true, 'advanced_dropdown' => true, 'multiple' => true), 'column-wc-crosssells' => array('type' => 'select2_dropdown', 'ajax_populate' => true, 'advanced_dropdown' => true, 'multiple' => true), 'column-wc-exclude_products' => array('type' => 'select2_dropdown', 'ajax_populate' => true, 'advanced_dropdown' => true, 'multiple' => true), 'column-wc-include_products' => array('type' => 'select2_dropdown', 'ajax_populate' => true, 'advanced_dropdown' => true, 'multiple' => true), 'column-wc-shipping_class' => array('type' => 'select'), 'usage' => array('type' => 'wc_usage'), 'description' => array('type' => 'textarea', 'property' => 'post_excerpt'), 'column-wc-reviews_enabled' => array('type' => 'togglable', 'property' => 'comment_status', 'options' => array('closed', 'open')), 'column-wc-backorders_allowed' => array('type' => 'select', 'options' => array('no' => __('Do not allow', 'woocommerce'), 'notify' => __('Allow, but notify customer', 'woocommerce'), 'yes' => __('Allow', 'woocommerce'))), 'product_cat' => array('type' => 'select2_tags'), 'product_tag' => array('type' => 'select2_tags'), 'column-wc-featured' => array('type' => 'togglable', 'options' => array('no', 'yes')), 'column-wc-visibility' => array('type' => 'select')); $data = array_merge($wc_data, $data); } // Handle capabilities for editing post status $post_type_object = get_post_type_object($this->storage_model->get_post_type()); if (!current_user_can($post_type_object->cap->publish_posts)) { unset($data['column-status']); } /** * Filter the editability settings for a column * * @since 3.4 * * @param array $data { * Editability settings. * * @type string $type Editability type. Accepts 'text', 'select', 'textarea', etc. * @type array $options Optional. Options for dropdown ([value] => [label]), only used when $type is "select" * } * @param CACIE_Editable_Model $model Editability storage model */ $data = apply_filters('cac/editable/editables_data', $data, $this); $data = apply_filters('cac/editable/editables_data/type=' . $this->storage_model->get_type(), $data, $this); $data = apply_filters('cac/editable/editables_data/post_type=' . $this->storage_model->get_post_type(), $data, $this); return $data; }
/** * Get a coupon type's name. * * @param string $type (default: '') * @return string */ function wc_get_coupon_type($type = '') { $types = wc_get_coupon_types(); return isset($types[$type]) ? $types[$type] : ''; }
/** * Output the metabox */ public static function output($post) { wp_nonce_field('woocommerce_save_data', 'woocommerce_meta_nonce'); ?> <style type="text/css"> #edit-slug-box, #minor-publishing-actions { display:none } </style> <div id="coupon_options" class="panel-wrap coupon_data"> <div class="wc-tabs-back"></div> <ul class="coupon_data_tabs wc-tabs" style="display:none;"> <?php $coupon_data_tabs = apply_filters('woocommerce_coupon_data_tabs', array('general' => array('label' => __('General', 'woocommerce'), 'target' => 'general_coupon_data', 'class' => 'general_coupon_data'), 'usage_restriction' => array('label' => __('Usage Restriction', 'woocommerce'), 'target' => 'usage_restriction_coupon_data', 'class' => ''), 'usage_limit' => array('label' => __('Usage Limits', 'woocommerce'), 'target' => 'usage_limit_coupon_data', 'class' => ''))); foreach ($coupon_data_tabs as $key => $tab) { ?> <li class="<?php echo $key; ?> _options <?php echo $key; ?> _tab <?php echo implode(' ', (array) $tab['class']); ?> "> <a href="#<?php echo $tab['target']; ?> "><?php echo esc_html($tab['label']); ?> </a> </li><?php } ?> </ul> <div id="general_coupon_data" class="panel woocommerce_options_panel"><?php // Type woocommerce_wp_select(array('id' => 'discount_type', 'label' => __('Discount type', 'woocommerce'), 'options' => wc_get_coupon_types())); // Amount woocommerce_wp_text_input(array('id' => 'coupon_amount', 'label' => __('Coupon amount', 'woocommerce'), 'placeholder' => wc_format_localized_price(0), 'description' => __('Value of the coupon.', 'woocommerce'), 'data_type' => 'price', 'desc_tip' => true)); // Free Shipping woocommerce_wp_checkbox(array('id' => 'free_shipping', 'label' => __('Allow free shipping', 'woocommerce'), 'description' => sprintf(__('Check this box if the coupon grants free shipping. The <a href="%s">free shipping method</a> must be enabled with the "must use coupon" setting.', 'woocommerce'), admin_url('admin.php?page=wc-settings&tab=shipping§ion=WC_Shipping_Free_Shipping')))); // Apply before tax woocommerce_wp_checkbox(array('id' => 'apply_before_tax', 'label' => __('Apply before tax', 'woocommerce'), 'description' => __('Check this box if the coupon should be applied before calculating cart tax.', 'woocommerce'))); // Expiry date woocommerce_wp_text_input(array('id' => 'expiry_date', 'label' => __('Coupon expiry date', 'woocommerce'), 'placeholder' => _x('YYYY-MM-DD', 'placeholder', 'woocommerce'), 'description' => '', 'class' => 'date-picker', 'custom_attributes' => array('pattern' => "[0-9]{4}-(0[1-9]|1[012])-(0[1-9]|1[0-9]|2[0-9]|3[01])"))); do_action('woocommerce_coupon_options'); ?> </div> <div id="usage_restriction_coupon_data" class="panel woocommerce_options_panel"><?php echo '<div class="options_group">'; // minimum spend woocommerce_wp_text_input(array('id' => 'minimum_amount', 'label' => __('Minimum spend', 'woocommerce'), 'placeholder' => __('No minimum', 'woocommerce'), 'description' => __('This field allows you to set the minimum subtotal needed to use the coupon.', 'woocommerce'), 'data_type' => 'price', 'desc_tip' => true)); // maximum spend woocommerce_wp_text_input(array('id' => 'maximum_amount', 'label' => __('Maximum spend', 'woocommerce'), 'placeholder' => __('No maximum', 'woocommerce'), 'description' => __('This field allows you to set the maximum subtotal allowed when using the coupon.', 'woocommerce'), 'data_type' => 'price', 'desc_tip' => true)); // Individual use woocommerce_wp_checkbox(array('id' => 'individual_use', 'label' => __('Individual use only', 'woocommerce'), 'description' => __('Check this box if the coupon cannot be used in conjunction with other coupons.', 'woocommerce'))); // Exclude Sale Products woocommerce_wp_checkbox(array('id' => 'exclude_sale_items', 'label' => __('Exclude sale items', 'woocommerce'), 'description' => __('Check this box if the coupon should not apply to items on sale. Per-item coupons will only work if the item is not on sale. Per-cart coupons will only work if there are no sale items in the cart.', 'woocommerce'))); echo '</div><div class="options_group">'; // Product ids ?> <p class="form-field"><label for="product_ids"><?php _e('Products', 'woocommerce'); ?> </label> <select id="product_ids" name="product_ids[]" class="ajax_chosen_select_products_and_variations" multiple="multiple" data-placeholder="<?php _e('Search for a product…', 'woocommerce'); ?> "> <?php $product_ids = get_post_meta($post->ID, 'product_ids', true); if ($product_ids) { $product_ids = array_map('absint', explode(',', $product_ids)); foreach ($product_ids as $product_id) { $product = wc_get_product($product_id); echo '<option value="' . esc_attr($product_id) . '" selected="selected">' . wp_kses_post($product->get_formatted_name()) . '</option>'; } } ?> </select> <img class="help_tip" data-tip='<?php _e('Products which need to be in the cart to use this coupon or, for "Product Discounts", which products are discounted.', 'woocommerce'); ?> ' src="<?php echo WC()->plugin_url(); ?> /assets/images/help.png" height="16" width="16" /></p> <?php // Exclude Product ids ?> <p class="form-field"><label for="exclude_product_ids"><?php _e('Exclude products', 'woocommerce'); ?> </label> <select id="exclude_product_ids" name="exclude_product_ids[]" class="ajax_chosen_select_products_and_variations" multiple="multiple" data-placeholder="<?php _e('Search for a product…', 'woocommerce'); ?> "> <?php $product_ids = get_post_meta($post->ID, 'exclude_product_ids', true); if ($product_ids) { $product_ids = array_map('absint', explode(',', $product_ids)); foreach ($product_ids as $product_id) { $product = wc_get_product($product_id); echo '<option value="' . esc_attr($product_id) . '" selected="selected">' . wp_kses_post($product->get_formatted_name()) . '</option>'; } } ?> </select> <img class="help_tip" data-tip='<?php _e('Products which must not be in the cart to use this coupon or, for "Product Discounts", which products are not discounted.', 'woocommerce'); ?> ' src="<?php echo WC()->plugin_url(); ?> /assets/images/help.png" height="16" width="16" /></p> <?php echo '</div><div class="options_group">'; // Categories ?> <p class="form-field"><label for="product_ids"><?php _e('Product categories', 'woocommerce'); ?> </label> <select id="product_categories" name="product_categories[]" class="chosen_select" multiple="multiple" data-placeholder="<?php _e('Any category', 'woocommerce'); ?> "> <?php $category_ids = (array) get_post_meta($post->ID, 'product_categories', true); $categories = get_terms('product_cat', 'orderby=name&hide_empty=0'); if ($categories) { foreach ($categories as $cat) { echo '<option value="' . esc_attr($cat->term_id) . '"' . selected(in_array($cat->term_id, $category_ids), true, false) . '>' . esc_html($cat->name) . '</option>'; } } ?> </select> <img class="help_tip" data-tip='<?php _e('A product must be in this category for the coupon to remain valid or, for "Product Discounts", products in these categories will be discounted.', 'woocommerce'); ?> ' src="<?php echo WC()->plugin_url(); ?> /assets/images/help.png" height="16" width="16" /></p> <?php // Exclude Categories ?> <p class="form-field"><label for="exclude_product_categories"><?php _e('Exclude categories', 'woocommerce'); ?> </label> <select id="exclude_product_categories" name="exclude_product_categories[]" class="chosen_select" multiple="multiple" data-placeholder="<?php _e('No categories', 'woocommerce'); ?> "> <?php $category_ids = (array) get_post_meta($post->ID, 'exclude_product_categories', true); $categories = get_terms('product_cat', 'orderby=name&hide_empty=0'); if ($categories) { foreach ($categories as $cat) { echo '<option value="' . esc_attr($cat->term_id) . '"' . selected(in_array($cat->term_id, $category_ids), true, false) . '>' . esc_html($cat->name) . '</option>'; } } ?> </select> <img class="help_tip" data-tip='<?php _e('Product must not be in this category for the coupon to remain valid or, for "Product Discounts", products in these categories will not be discounted.', 'woocommerce'); ?> ' src="<?php echo WC()->plugin_url(); ?> /assets/images/help.png" height="16" width="16" /></p> <?php echo '</div><div class="options_group">'; // Customers woocommerce_wp_text_input(array('id' => 'customer_email', 'label' => __('Email restrictions', 'woocommerce'), 'placeholder' => __('No restrictions', 'woocommerce'), 'description' => __('List of emails to check against the customer\'s billing email when an order is placed. Separate email addresses with commas.', 'woocommerce'), 'value' => implode(', ', (array) get_post_meta($post->ID, 'customer_email', true)), 'desc_tip' => true, 'type' => 'email', 'class' => '', 'custom_attributes' => array('multiple' => 'multiple'))); echo '</div>'; do_action('woocommerce_coupon_options_usage_restriction'); ?> </div> <div id="usage_limit_coupon_data" class="panel woocommerce_options_panel"><?php echo '<div class="options_group">'; // Usage limit per coupons woocommerce_wp_text_input(array('id' => 'usage_limit', 'label' => __('Usage limit per coupon', 'woocommerce'), 'placeholder' => _x('Unlimited usage', 'placeholder', 'woocommerce'), 'description' => __('How many times this coupon can be used before it is void.', 'woocommerce'), 'type' => 'number', 'desc_tip' => true, 'class' => 'short', 'custom_attributes' => array('step' => '1', 'min' => '0'))); // Usage limit per product woocommerce_wp_text_input(array('id' => 'limit_usage_to_x_items', 'label' => __('Limit usage to X items', 'woocommerce'), 'placeholder' => _x('Apply to all qualifying items in cart', 'placeholder', 'woocommerce'), 'description' => __('The maximum number of individual items this coupon can apply to when using product discounts. Leave blank to apply to all qualifying items in cart.', 'woocommerce'), 'desc_tip' => true, 'class' => 'short', 'type' => 'number', 'custom_attributes' => array('step' => '1', 'min' => '0'))); // Usage limit per users woocommerce_wp_text_input(array('id' => 'usage_limit_per_user', 'label' => __('Usage limit per user', 'woocommerce'), 'placeholder' => _x('Unlimited usage', 'placeholder', 'woocommerce'), 'description' => __('How many times this coupon can be used by an invidual user. Uses billing email for guests, and user ID for logged in users.', 'woocommerce'), 'desc_tip' => true, 'class' => 'short', 'type' => 'number', 'custom_attributes' => array('step' => '1', 'min' => '0'))); echo '</div>'; do_action('woocommerce_coupon_options_usage_limit'); ?> </div> <?php do_action('woocommerce_coupon_data_panels'); ?> <div class="clear"></div> </div> <?php }
/** * Show custom filters to filter coupons by type. */ public function shop_coupon_filters() { ?> <select name="coupon_type" id="dropdown_shop_coupon_type"> <option value=""><?php _e('Show all types', 'woocommerce'); ?> </option> <?php $types = wc_get_coupon_types(); foreach ($types as $name => $type) { echo '<option value="' . esc_attr($name) . '"'; if (isset($_GET['coupon_type'])) { selected($name, $_GET['coupon_type']); } echo '>' . esc_html__($type, 'woocommerce') . '</option>'; } ?> </select> <?php }
/** * Update one or more coupons. * * ## OPTIONS * * <coupon> * : The ID or code of the coupon to update. * * --<field>=<value> * : One or more fields to update. * * ## AVAILABLE FIELDS * * These fields are available for update command: * * * code * * type * * amount * * description * * expiry_date * * individual_use * * product_ids * * exclude_product_ids * * usage_limit * * usage_limit_per_user * * limit_usage_to_x_items * * usage_count * * enable_free_shipping * * product_category_ids * * exclude_product_categories * * exclude_product_category_ids * * minimum_amount * * maximum_amount * * customer_emails * * ## EXAMPLES * * wp wc coupon update 123 --amount=5 * * wp wc coupon update coupon-code --code=new-coupon-code * * @since 2.5.0 */ public function update($args, $assoc_args) { try { $coupon = $this->get_coupon_from_id_or_code($args[0]); if (!$coupon) { throw new WC_CLI_Exception('woocommerce_cli_invalid_coupon', sprintf(__('Invalid coupon ID or code: %s', 'woocommerce'), $args[0])); } $id = $coupon->id; $coupon_code = $coupon->code; $data = apply_filters('woocommerce_cli_update_coupon_data', $assoc_args, $id); if (isset($data['code'])) { global $wpdb; $coupon_code = apply_filters('woocommerce_coupon_code', $data['code']); // Check for duplicate coupon codes $coupon_found = $wpdb->get_var($wpdb->prepare("\n\t\t\t\t\tSELECT {$wpdb->posts}.ID\n\t\t\t\t\tFROM {$wpdb->posts}\n\t\t\t\t\tWHERE {$wpdb->posts}.post_type = 'shop_coupon'\n\t\t\t\t\tAND {$wpdb->posts}.post_status = 'publish'\n\t\t\t\t\tAND {$wpdb->posts}.post_title = '%s'\n\t\t\t\t\tAND {$wpdb->posts}.ID != %s\n\t\t\t\t ", $coupon_code, $id)); if ($coupon_found) { throw new WC_CLI_Exception('woocommerce_cli_coupon_code_already_exists', __('The coupon code already exists', 'woocommerce')); } } $id = wp_update_post(array('ID' => intval($id), 'post_title' => $coupon_code, 'post_excerpt' => isset($data['description']) ? $data['description'] : '')); if (0 === $id) { throw new WC_CLI_Exception('woocommerce_cli_cannot_update_coupon', __('Failed to update coupon', 'woocommerce')); } if (isset($data['type'])) { // Validate coupon types. if (!in_array(wc_clean($data['type']), array_keys(wc_get_coupon_types()))) { throw new WC_CLI_Exception('woocommerce_cli_invalid_coupon_type', sprintf(__('Invalid coupon type - the coupon type must be any of these: %s', 'woocommerce'), implode(', ', array_keys(wc_get_coupon_types())))); } update_post_meta($id, 'discount_type', $data['type']); } if (isset($data['amount'])) { update_post_meta($id, 'coupon_amount', wc_format_decimal($data['amount'])); } if (isset($data['individual_use'])) { update_post_meta($id, 'individual_use', true === $data['individual_use'] ? 'yes' : 'no'); } if (isset($data['product_ids'])) { update_post_meta($id, 'product_ids', implode(',', array_filter(array_map('intval', $data['product_ids'])))); } if (isset($data['exclude_product_ids'])) { update_post_meta($id, 'exclude_product_ids', implode(',', array_filter(array_map('intval', $data['exclude_product_ids'])))); } if (isset($data['usage_limit'])) { update_post_meta($id, 'usage_limit', absint($data['usage_limit'])); } if (isset($data['usage_limit_per_user'])) { update_post_meta($id, 'usage_limit_per_user', absint($data['usage_limit_per_user'])); } if (isset($data['limit_usage_to_x_items'])) { update_post_meta($id, 'limit_usage_to_x_items', absint($data['limit_usage_to_x_items'])); } if (isset($data['usage_count'])) { update_post_meta($id, 'usage_count', absint($data['usage_count'])); } if (isset($data['expiry_date'])) { update_post_meta($id, 'expiry_date', $this->get_coupon_expiry_date(wc_clean($data['expiry_date']))); } if (isset($data['enable_free_shipping'])) { update_post_meta($id, 'free_shipping', true === $data['enable_free_shipping'] ? 'yes' : 'no'); } if (isset($data['product_category_ids'])) { update_post_meta($id, 'product_categories', array_filter(array_map('intval', $data['product_category_ids']))); } if (isset($data['exclude_product_category_ids'])) { update_post_meta($id, 'exclude_product_categories', array_filter(array_map('intval', $data['exclude_product_category_ids']))); } if (isset($data['exclude_sale_items'])) { update_post_meta($id, 'exclude_sale_items', true === $data['exclude_sale_items'] ? 'yes' : 'no'); } if (isset($data['minimum_amount'])) { update_post_meta($id, 'minimum_amount', wc_format_decimal($data['minimum_amount'])); } if (isset($data['maximum_amount'])) { update_post_meta($id, 'maximum_amount', wc_format_decimal($data['maximum_amount'])); } if (isset($data['customer_emails'])) { update_post_meta($id, 'customer_email', array_filter(array_map('sanitize_email', $data['customer_emails']))); } do_action('woocommerce_cli_update_coupon', $id, $data); WP_CLI::success("Updated coupon {$id}."); } catch (WC_CLI_Exception $e) { WP_CLI::error($e->getMessage()); } }
//Array for advanced search $wpec_products_cols_advanced_search = $products_cols; } else { if (WOO_RUNNING === true) { $products_search_cols = array(); //array for advanced search autocomplete // ============================================================== // Coupons Code // ============================================================== $couponfieldsResults = array(); $couponfieldsquery = "SELECT DISTINCT meta_key FROM {$wpdb->prefix}postmeta WHERE meta_key IN\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t('discount_type','coupon_amount','individual_use','coupon_title_suffix',\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t'apply_before_tax','free_shipping','coupon_title_prefix','exclude_sale_items',\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t'usage_limit','expiry_date','minimum_amount','usage_count')"; $couponfieldsResults = $wpdb->get_results($couponfieldsquery, ARRAY_A); if (empty($couponfieldsResults)) { $couponfieldsResults = array(array('meta_key' => 'apply_before_tax'), array('meta_key' => 'coupon_amount'), array('meta_key' => 'discount_type'), array('meta_key' => 'exclude_sale_items'), array('meta_key' => 'expiry_date'), array('meta_key' => 'free_shipping'), array('meta_key' => 'individual_use'), array('meta_key' => 'minimum_amount'), array('meta_key' => 'usage_count'), array('meta_key' => 'usage_limit')); } $select_box = SM_IS_WOO21 == "true" || SM_IS_WOO22 == "true" ? wc_get_coupon_types() : $woocommerce->get_coupon_discount_types(); $select_box_keys = array_keys($select_box); $couponfield_names_select = array(); $i = 0; foreach ($select_box as $select_box1) { $couponfield_names_select[$i][0] = $select_box_keys[$i]; $couponfield_names_select[$i][1] = $select_box1; $i++; } $cnt = 0; $couponfield_names['items'][$cnt]['id'] = $cnt; $couponfield_names['items'][$cnt]['name'] = 'Coupon Name'; $couponfield_names['items'][$cnt]['type'] = 'string'; $couponfield_names['items'][$cnt]['table'] = "posts"; $couponfield_names['items'][$cnt]['value'] = 'post_title'; $cnt++;
/** * Test wc_get_coupon_types(). * * @since 2.2 */ public function test_wc_get_coupon_types() { $coupon_types = array('fixed_cart' => 'Cart discount', 'percent' => 'Cart % discount', 'fixed_product' => 'Product discount', 'percent_product' => 'Product % discount'); $this->assertEquals($coupon_types, wc_get_coupon_types()); }
public static function get_discount_types() { global $woocommerce; return function_exists('wc_get_coupon_types') ? wc_get_coupon_types() : $woocommerce->get_coupon_discount_types(); }
/** * Update a coupon * * @since 3.0.0 * @param int $id the coupon ID * @param array $data * @param array $options * @return array|WP_Error */ public function update_coupon($id, $data, $options = array()) { try { $id = absint($id); // validate the coupon ID. if (empty($id)) { throw new WC_CSV_Import_Suite_Import_Exception('wc_csv_import_suite_invalid_coupon_id', __('Invalid coupon ID', 'woocommerce-csv-import-suite')); } $post = get_post($id); if (null === $post) { throw new WC_CSV_Import_Suite_Import_Exception('wc_csv_import_suite_no_coupon_found', sprintf(__('No coupon found with the ID equal to %s', 'woocommerce-csv-import-suite'), $id)); } // validate post type if ('shop_coupon' !== $post->post_type) { throw new WC_CSV_Import_Suite_Import_Exception('wc_csv_import_suite_invalid_coupon', __('Invalid coupon', 'woocommerce-csv-import-suite')); } /** * Filter data that is going to be updated for a coupon via CSV * * @since 3.0.0 * @param array $data * @param array $options * @param object $this */ $data = apply_filters('wc_csv_import_suite_update_coupon_data', $data, $options, $this); $coupon_data = array(); if (isset($data['code'])) { global $wpdb; $coupon_code = apply_filters('woocommerce_coupon_code', $data['code']); // check for duplicate coupon codes $coupon_found = $wpdb->get_var($wpdb->prepare("\n\t\t\t\t\tSELECT {$wpdb->posts}.ID\n\t\t\t\t\tFROM {$wpdb->posts}\n\t\t\t\t\tWHERE {$wpdb->posts}.post_type = 'shop_coupon'\n\t\t\t\t\tAND {$wpdb->posts}.post_status = 'publish'\n\t\t\t\t\tAND {$wpdb->posts}.post_title = '%s'\n\t\t\t\t\tAND {$wpdb->posts}.ID != %s\n\t\t\t\t ", $coupon_code, $id)); if ($coupon_found) { throw new WC_CSV_Import_Suite_Import_Exception('wc_csv_import_suite_coupon_code_already_exists', __('The coupon code already exists', 'woocommerce-csv-import-suite')); } $coupon_data['post_title'] = $coupon_code; } if (isset($data['description'])) { $coupon_data['post_excerpt'] = $data['description']; } if (!empty($coupon_data)) { $coupon_data['ID'] = intval($id); $updated = wp_update_post(array('ID' => intval($id), 'post_title' => $coupon_code), $wp_error = true); if (is_wp_error($updated)) { throw new WC_CSV_Import_Suite_Import_Exception($id->get_error_code(), $id->get_error_message()); } } // validate coupon types if (isset($data['type'])) { if (!in_array(wc_clean($data['type']), array_keys(wc_get_coupon_types()))) { throw new WC_CSV_Import_Suite_Import_Exception('wc_csv_import_suite_invalid_coupon_type', sprintf(__('Invalid coupon type - the coupon type must be any of these: %s', 'woocommerce-csv-import-suite'), implode(', ', array_keys(wc_get_coupon_types())))); } } // update coupon data $this->update_coupon_data($id, $data, $options); /** * Triggered after a coupon has been updated via CSV import * * @since 3.0.0 * @param int $id Coupon ID * @param array $data Data from CSV * @param array $options Import options */ do_action('wc_csv_import_suite_update_coupon', $id, $data); return $id; } catch (WC_CSV_Import_Suite_Import_Exception $e) { return new WP_Error($e->getErrorCode(), $e->getMessage()); } }
protected function getCouponData($i05355412b857f5174e9a2f71b1e936a86ad60cd287395dcafb6eb7221410dbcd87e9e8ce0007214a) { $iced8cbcfca3c880f0f157e119d1cc6f8691e7e89 = (array) get_post($i05355412b857f5174e9a2f71b1e936a86ad60cd287395dcafb6eb7221410dbcd87e9e8ce0007214a); $i05355412b857f5174e9a2f71b1e936a86ad60cd218327082d2290372922428ae0ac10d179dcc0334 = get_post_meta($i05355412b857f5174e9a2f71b1e936a86ad60cd287395dcafb6eb7221410dbcd87e9e8ce0007214a); $i05355412b857f5174e9a2f71b1e936a86ad60cd2c2328e91b7d7f67ee535f97a7c0a148b48f30b57 = wc_get_coupon_types(); foreach ($i05355412b857f5174e9a2f71b1e936a86ad60cd218327082d2290372922428ae0ac10d179dcc0334 as $i05355412b857f5174e9a2f71b1e936a86ad60cd27baa31be52215025da340cfec29600d8d2b327c4 => $i05355412b857f5174e9a2f71b1e936a86ad60cd2e10f888510a016f5ea5f46b736afa9e60fb62395) { if ($i05355412b857f5174e9a2f71b1e936a86ad60cd27baa31be52215025da340cfec29600d8d2b327c4 == "discount_type") { $iced8cbcfca3c880f0f157e119d1cc6f8691e7e89["type"] = $i05355412b857f5174e9a2f71b1e936a86ad60cd2c2328e91b7d7f67ee535f97a7c0a148b48f30b57[$i05355412b857f5174e9a2f71b1e936a86ad60cd2e10f888510a016f5ea5f46b736afa9e60fb62395[0]]; } $iced8cbcfca3c880f0f157e119d1cc6f8691e7e89[$i05355412b857f5174e9a2f71b1e936a86ad60cd27baa31be52215025da340cfec29600d8d2b327c4] = $i05355412b857f5174e9a2f71b1e936a86ad60cd2e10f888510a016f5ea5f46b736afa9e60fb62395[0]; } return $iced8cbcfca3c880f0f157e119d1cc6f8691e7e89; }
/** * @deprecated 2.1.0 * @return array */ public function get_coupon_discount_types() { _deprecated_function('Woocommerce->get_coupon_discount_types', '2.1', 'wc_get_coupon_types'); return wc_get_coupon_types(); }
/** * Test wc_get_coupon_types(). * * @since 2.2 */ public function test_wc_get_coupon_types() { $coupon_types = array('fixed_cart' => __('Cart Discount', 'woocommerce'), 'percent' => __('Cart % Discount', 'woocommerce'), 'fixed_product' => __('Product Discount', 'woocommerce'), 'percent_product' => __('Product % Discount', 'woocommerce')); $this->assertEquals($coupon_types, wc_get_coupon_types()); }
/** * Edit a coupon * * @since 2.2 * @param int $id the coupon ID * @param array $data * @return array */ public function edit_coupon($id, $data) { $data = isset($data['coupon']) ? $data['coupon'] : array(); $id = $this->validate_request($id, 'shop_coupon', 'edit'); if (is_wp_error($id)) { return $id; } $data = apply_filters('woocommerce_api_edit_coupon_data', $data, $id, $this); if (isset($data['code'])) { global $wpdb; $coupon_code = apply_filters('woocommerce_coupon_code', $data['code']); // Check for duplicate coupon codes $coupon_found = $wpdb->get_var($wpdb->prepare("\r\n\t\t\t\tSELECT {$wpdb->posts}.ID\r\n\t\t\t\tFROM {$wpdb->posts}\r\n\t\t\t\tWHERE {$wpdb->posts}.post_type = 'shop_coupon'\r\n\t\t\t\tAND {$wpdb->posts}.post_status = 'publish'\r\n\t\t\t\tAND {$wpdb->posts}.post_title = '%s'\r\n\t\t\t\tAND {$wpdb->posts}.ID != %s\r\n\t\t\t ", $coupon_code, $id)); if ($coupon_found) { return new WP_Error('woocommerce_api_coupon_code_already_exists', __('The coupon code already exists', 'woocommerce'), array('status' => 400)); } $id = wp_update_post(array('ID' => intval($id), 'post_title' => $coupon_code, 'post_excerpt' => isset($data['description']) ? $data['description'] : '')); if (0 === $id) { return new WP_Error('woocommerce_api_cannot_update_coupon', __('Failed to update coupon', 'woocommerce'), array('status' => 400)); } } if (isset($data['type'])) { // Validate coupon types if (!in_array(wc_clean($data['type']), array_keys(wc_get_coupon_types()))) { return new WP_Error('woocommerce_api_invalid_coupon_type', sprintf(__('Invalid coupon type - the coupon type must be any of these: %s', 'woocommerce'), implode(', ', array_keys(wc_get_coupon_types()))), array('status' => 400)); } update_post_meta($id, 'discount_type', $data['type']); } if (isset($data['amount'])) { update_post_meta($id, 'coupon_amount', wc_format_decimal($data['amount'])); } if (isset($data['individual_use'])) { update_post_meta($id, 'individual_use', $data['individual_use']); } if (isset($data['product_ids'])) { update_post_meta($id, 'product_ids', implode(',', array_filter(array_map('intval', $data['product_ids'])))); } if (isset($data['exclude_product_ids'])) { update_post_meta($id, 'exclude_product_ids', implode(',', array_filter(array_map('intval', $data['exclude_product_ids'])))); } if (isset($data['usage_limit'])) { update_post_meta($id, 'usage_limit', absint($data['usage_limit'])); } if (isset($data['usage_limit_per_user'])) { update_post_meta($id, 'usage_limit_per_user', absint($data['usage_limit_per_user'])); } if (isset($data['limit_usage_to_x_items'])) { update_post_meta($id, 'limit_usage_to_x_items', absint($data['limit_usage_to_x_items'])); } if (isset($data['usage_count'])) { update_post_meta($id, 'usage_count', absint($data['usage_count'])); } if (isset($data['expiry_date'])) { update_post_meta($id, 'expiry_date', wc_clean($data['expiry_date'])); } if (isset($data['apply_before_tax'])) { update_post_meta($id, 'apply_before_tax', wc_clean($data['apply_before_tax'])); } if (isset($data['enable_free_shipping'])) { update_post_meta($id, 'free_shipping', true === $data['enable_free_shipping'] ? 'yes' : 'no'); } if (isset($data['product_category_ids'])) { update_post_meta($id, 'product_categories', array_filter(array_map('intval', $data['product_category_ids']))); } if (isset($data['exclude_product_category_ids'])) { update_post_meta($id, 'exclude_product_categories', array_filter(array_map('intval', $data['exclude_product_category_ids']))); } if (isset($data['exclude_sale_items'])) { update_post_meta($id, 'exclude_sale_items', wc_clean($data['exclude_sale_items'])); } if (isset($data['minimum_amount'])) { update_post_meta($id, 'minimum_amount', wc_format_decimal($data['minimum_amount'])); } if (isset($data['maximum_amount'])) { update_post_meta($id, 'maximum_amount', wc_format_decimal($data['maximum_amount'])); } if (isset($data['customer_emails'])) { update_post_meta($id, 'customer_email', array_filter(array_map('sanitize_email', $data['customer_emails']))); } do_action('woocommerce_api_edit_coupon', $id, $data); return $this->get_coupon($id); }
/** * Edit a coupon * * @since 2.2 * @param int $id the coupon ID * @param array $data * @return array */ public function edit_coupon($id, $data) { try { if (!isset($data['coupon'])) { throw new WC_API_Exception('woocommerce_api_missing_coupon_data', sprintf(__('No %1$s data specified to edit %1$s', 'woocommerce'), 'coupon'), 400); } $data = $data['coupon']; $id = $this->validate_request($id, 'shop_coupon', 'edit'); if (is_wp_error($id)) { return $id; } $data = apply_filters('woocommerce_api_edit_coupon_data', $data, $id, $this); if (isset($data['code'])) { global $wpdb; $coupon_code = apply_filters('woocommerce_coupon_code', $data['code']); $id_from_code = wc_get_coupon_id_by_code($coupon_code, $id); if ($id_from_code) { throw new WC_API_Exception('woocommerce_api_coupon_code_already_exists', __('The coupon code already exists', 'woocommerce'), 400); } $updated = wp_update_post(array('ID' => intval($id), 'post_title' => $coupon_code)); if (0 === $updated) { throw new WC_API_Exception('woocommerce_api_cannot_update_coupon', __('Failed to update coupon', 'woocommerce'), 400); } } if (isset($data['description'])) { $updated = wp_update_post(array('ID' => intval($id), 'post_excerpt' => $data['description'])); if (0 === $updated) { throw new WC_API_Exception('woocommerce_api_cannot_update_coupon', __('Failed to update coupon', 'woocommerce'), 400); } } if (isset($data['type'])) { // Validate coupon types if (!in_array(wc_clean($data['type']), array_keys(wc_get_coupon_types()))) { throw new WC_API_Exception('woocommerce_api_invalid_coupon_type', sprintf(__('Invalid coupon type - the coupon type must be any of these: %s', 'woocommerce'), implode(', ', array_keys(wc_get_coupon_types()))), 400); } update_post_meta($id, 'discount_type', $data['type']); } if (isset($data['amount'])) { update_post_meta($id, 'coupon_amount', wc_format_decimal($data['amount'])); } if (isset($data['individual_use'])) { update_post_meta($id, 'individual_use', true === $data['individual_use'] ? 'yes' : 'no'); } if (isset($data['product_ids'])) { update_post_meta($id, 'product_ids', implode(',', array_filter(array_map('intval', $data['product_ids'])))); } if (isset($data['exclude_product_ids'])) { update_post_meta($id, 'exclude_product_ids', implode(',', array_filter(array_map('intval', $data['exclude_product_ids'])))); } if (isset($data['usage_limit'])) { update_post_meta($id, 'usage_limit', absint($data['usage_limit'])); } if (isset($data['usage_limit_per_user'])) { update_post_meta($id, 'usage_limit_per_user', absint($data['usage_limit_per_user'])); } if (isset($data['limit_usage_to_x_items'])) { update_post_meta($id, 'limit_usage_to_x_items', absint($data['limit_usage_to_x_items'])); } if (isset($data['usage_count'])) { update_post_meta($id, 'usage_count', absint($data['usage_count'])); } if (isset($data['expiry_date'])) { update_post_meta($id, 'expiry_date', $this->get_coupon_expiry_date(wc_clean($data['expiry_date']))); } if (isset($data['enable_free_shipping'])) { update_post_meta($id, 'free_shipping', true === $data['enable_free_shipping'] ? 'yes' : 'no'); } if (isset($data['product_category_ids'])) { update_post_meta($id, 'product_categories', array_filter(array_map('intval', $data['product_category_ids']))); } if (isset($data['exclude_product_category_ids'])) { update_post_meta($id, 'exclude_product_categories', array_filter(array_map('intval', $data['exclude_product_category_ids']))); } if (isset($data['exclude_sale_items'])) { update_post_meta($id, 'exclude_sale_items', true === $data['exclude_sale_items'] ? 'yes' : 'no'); } if (isset($data['minimum_amount'])) { update_post_meta($id, 'minimum_amount', wc_format_decimal($data['minimum_amount'])); } if (isset($data['maximum_amount'])) { update_post_meta($id, 'maximum_amount', wc_format_decimal($data['maximum_amount'])); } if (isset($data['customer_emails'])) { update_post_meta($id, 'customer_email', array_filter(array_map('sanitize_email', $data['customer_emails']))); } do_action('woocommerce_api_edit_coupon', $id, $data); return $this->get_coupon($id); } catch (WC_API_Exception $e) { return new WP_Error($e->getErrorCode(), $e->getMessage(), array('status' => $e->getCode())); } }
/** * Get the Coupon's schema, conforming to JSON Schema. * * @return array */ public function get_item_schema() { $schema = array('$schema' => 'http://json-schema.org/draft-04/schema#', 'title' => $this->post_type, 'type' => 'object', 'properties' => array('id' => array('description' => __('Unique identifier for the object.', 'woocommerce'), 'type' => 'integer', 'context' => array('view', 'edit'), 'readonly' => true), 'code' => array('description' => __('Coupon code.', 'woocommerce'), 'type' => 'string', 'context' => array('view', 'edit')), 'date_created' => array('description' => __("The date the coupon was created, in the site's timezone.", 'woocommerce'), 'type' => 'date-time', 'context' => array('view', 'edit'), 'readonly' => true), 'date_modified' => array('description' => __("The date the coupon was last modified, in the site's timezone.", 'woocommerce'), 'type' => 'date-time', 'context' => array('view', 'edit'), 'readonly' => true), 'description' => array('description' => __('Coupon description.', 'woocommerce'), 'type' => 'string', 'context' => array('view', 'edit')), 'discount_type' => array('description' => __('Determines the type of discount that will be applied.', 'woocommerce'), 'type' => 'string', 'default' => 'fixed_cart', 'enum' => array_keys(wc_get_coupon_types()), 'context' => array('view', 'edit')), 'amount' => array('description' => __('The amount of discount.', 'woocommerce'), 'type' => 'string', 'context' => array('view', 'edit')), 'date_expires' => array('description' => __('UTC DateTime when the coupon expires.', 'woocommerce'), 'type' => 'string', 'context' => array('view', 'edit')), 'usage_count' => array('description' => __('Number of times the coupon has been used already.', 'woocommerce'), 'type' => 'integer', 'context' => array('view', 'edit'), 'readonly' => true), 'individual_use' => array('description' => __('Whether coupon can only be used individually.', 'woocommerce'), 'type' => 'boolean', 'default' => false, 'context' => array('view', 'edit')), 'product_ids' => array('description' => __("List of product ID's the coupon can be used on.", 'woocommerce'), 'type' => 'array', 'context' => array('view', 'edit')), 'excluded_product_ids' => array('description' => __("List of product ID's the coupon cannot be used on.", 'woocommerce'), 'type' => 'array', 'context' => array('view', 'edit')), 'usage_limit' => array('description' => __('How many times the coupon can be used.', 'woocommerce'), 'type' => 'integer', 'context' => array('view', 'edit')), 'usage_limit_per_user' => array('description' => __('How many times the coupon can be used per customer.', 'woocommerce'), 'type' => 'integer', 'context' => array('view', 'edit')), 'limit_usage_to_x_items' => array('description' => __('Max number of items in the cart the coupon can be applied to.', 'woocommerce'), 'type' => 'integer', 'context' => array('view', 'edit')), 'free_shipping' => array('description' => __('Define if can be applied for free shipping.', 'woocommerce'), 'type' => 'boolean', 'default' => false, 'context' => array('view', 'edit')), 'product_categories' => array('description' => __("List of category ID's the coupon applies to.", 'woocommerce'), 'type' => 'array', 'context' => array('view', 'edit')), 'excluded_product_categories' => array('description' => __("List of category ID's the coupon does not apply to.", 'woocommerce'), 'type' => 'array', 'context' => array('view', 'edit')), 'exclude_sale_items' => array('description' => __('Define if should not apply when have sale items.', 'woocommerce'), 'type' => 'boolean', 'default' => false, 'context' => array('view', 'edit')), 'minimum_amount' => array('description' => __('Minimum order amount that needs to be in the cart before coupon applies.', 'woocommerce'), 'type' => 'string', 'context' => array('view', 'edit')), 'maximum_amount' => array('description' => __('Maximum order amount allowed when using the coupon.', 'woocommerce'), 'type' => 'string', 'context' => array('view', 'edit')), 'email_restrictions' => array('description' => __('List of email addresses that can use this coupon.', 'woocommerce'), 'type' => 'array', 'context' => array('view', 'edit')), 'used_by' => array('description' => __('List of user IDs who have used the coupon.', 'woocommerce'), 'type' => 'array', 'context' => array('view', 'edit'), 'readonly' => true), 'meta_data' => array('description' => __('Order meta data.', 'woocommerce'), 'type' => 'array', 'context' => array('view', 'edit'), 'properties' => array('id' => array('description' => __('Meta ID.', 'woocommerce'), 'type' => 'int', 'context' => array('view', 'edit'), 'readonly' => true), 'key' => array('description' => __('Meta key.', 'woocommerce'), 'type' => 'string', 'context' => array('view', 'edit')), 'value' => array('description' => __('Meta value.', 'woocommerce'), 'type' => 'string', 'context' => array('view', 'edit')))))); return $this->add_additional_fields_schema($schema); }
/** * Output the metabox. * * @param WP_Post $post */ public static function output($post) { wp_nonce_field('woocommerce_save_data', 'woocommerce_meta_nonce'); $coupon = new WC_Coupon($post->ID); ?> <style type="text/css"> #edit-slug-box, #minor-publishing-actions { display:none } </style> <div id="coupon_options" class="panel-wrap coupon_data"> <div class="wc-tabs-back"></div> <ul class="coupon_data_tabs wc-tabs" style="display:none;"> <?php $coupon_data_tabs = apply_filters('woocommerce_coupon_data_tabs', array('general' => array('label' => __('General', 'woocommerce'), 'target' => 'general_coupon_data', 'class' => 'general_coupon_data'), 'usage_restriction' => array('label' => __('Usage restriction', 'woocommerce'), 'target' => 'usage_restriction_coupon_data', 'class' => ''), 'usage_limit' => array('label' => __('Usage limits', 'woocommerce'), 'target' => 'usage_limit_coupon_data', 'class' => ''))); foreach ($coupon_data_tabs as $key => $tab) { ?> <li class="<?php echo $key; ?> _options <?php echo $key; ?> _tab <?php echo implode(' ', (array) $tab['class']); ?> "> <a href="#<?php echo $tab['target']; ?> "><?php echo esc_html($tab['label']); ?> </a> </li><?php } ?> </ul> <div id="general_coupon_data" class="panel woocommerce_options_panel"><?php // Type woocommerce_wp_select(array('id' => 'discount_type', 'label' => __('Discount type', 'woocommerce'), 'options' => wc_get_coupon_types())); // Amount woocommerce_wp_text_input(array('id' => 'coupon_amount', 'label' => __('Coupon amount', 'woocommerce'), 'placeholder' => wc_format_localized_price(0), 'description' => __('Value of the coupon.', 'woocommerce'), 'data_type' => 'price', 'desc_tip' => true)); // Free Shipping woocommerce_wp_checkbox(array('id' => 'free_shipping', 'label' => __('Allow free shipping', 'woocommerce'), 'description' => sprintf(__('Check this box if the coupon grants free shipping. A <a href="%s" target="_blank">free shipping method</a> must be enabled in your shipping zone and be set to require "a valid free shipping coupon" (see the "Free Shipping Requires" setting).', 'woocommerce'), 'https://docs.woocommerce.com/document/free-shipping/'))); // Expiry date $expiry_date = $coupon->get_date_expires() ? date('Y-m-d', $coupon->get_date_expires()) : ''; woocommerce_wp_text_input(array('id' => 'expiry_date', 'value' => esc_attr($expiry_date), 'label' => __('Coupon expiry date', 'woocommerce'), 'placeholder' => esc_attr__('YYYY-MM-DD', 'woocommerce'), 'description' => '', 'class' => 'date-picker', 'custom_attributes' => array('pattern' => "[0-9]{4}-(0[1-9]|1[012])-(0[1-9]|1[0-9]|2[0-9]|3[01])"))); do_action('woocommerce_coupon_options'); ?> </div> <div id="usage_restriction_coupon_data" class="panel woocommerce_options_panel"><?php echo '<div class="options_group">'; // minimum spend woocommerce_wp_text_input(array('id' => 'minimum_amount', 'label' => __('Minimum spend', 'woocommerce'), 'placeholder' => __('No minimum', 'woocommerce'), 'description' => __('This field allows you to set the minimum spend (subtotal, including taxes) allowed to use the coupon.', 'woocommerce'), 'data_type' => 'price', 'desc_tip' => true)); // maximum spend woocommerce_wp_text_input(array('id' => 'maximum_amount', 'label' => __('Maximum spend', 'woocommerce'), 'placeholder' => __('No maximum', 'woocommerce'), 'description' => __('This field allows you to set the maximum spend (subtotal, including taxes) allowed when using the coupon.', 'woocommerce'), 'data_type' => 'price', 'desc_tip' => true)); // Individual use woocommerce_wp_checkbox(array('id' => 'individual_use', 'label' => __('Individual use only', 'woocommerce'), 'description' => __('Check this box if the coupon cannot be used in conjunction with other coupons.', 'woocommerce'))); // Exclude Sale Products woocommerce_wp_checkbox(array('id' => 'exclude_sale_items', 'label' => __('Exclude sale items', 'woocommerce'), 'description' => __('Check this box if the coupon should not apply to items on sale. Per-item coupons will only work if the item is not on sale. Per-cart coupons will only work if there are no sale items in the cart.', 'woocommerce'))); echo '</div><div class="options_group">'; // Product ids ?> <p class="form-field"><label><?php _e('Products', 'woocommerce'); ?> </label> <input type="hidden" class="wc-product-search" data-multiple="true" style="width: 50%;" name="product_ids" data-placeholder="<?php esc_attr_e('Search for a product…', 'woocommerce'); ?> " data-action="woocommerce_json_search_products_and_variations" data-selected="<?php $product_ids = $coupon->get_product_ids(); $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($product->get_formatted_name()); } } echo esc_attr(json_encode($json_ids)); ?> " value="<?php echo implode(',', array_keys($json_ids)); ?> " /> <?php echo wc_help_tip(__('Products which need to be in the cart to use this coupon or, for "Product Discounts", which products are discounted.', 'woocommerce')); ?> </p> <?php // Exclude Product ids ?> <p class="form-field"><label><?php _e('Exclude products', 'woocommerce'); ?> </label> <input type="hidden" class="wc-product-search" data-multiple="true" style="width: 50%;" name="exclude_product_ids" data-placeholder="<?php esc_attr_e('Search for a product…', 'woocommerce'); ?> " data-action="woocommerce_json_search_products_and_variations" data-selected="<?php $product_ids = $coupon->get_excluded_product_ids(); $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($product->get_formatted_name()); } } echo esc_attr(json_encode($json_ids)); ?> " value="<?php echo implode(',', array_keys($json_ids)); ?> " /> <?php echo wc_help_tip(__('Products which must not be in the cart to use this coupon or, for "Product Discounts", which products are not discounted.', 'woocommerce')); ?> </p> <?php echo '</div><div class="options_group">'; // Categories ?> <p class="form-field"><label for="product_categories"><?php _e('Product categories', 'woocommerce'); ?> </label> <select id="product_categories" name="product_categories[]" style="width: 50%;" class="wc-enhanced-select" multiple="multiple" data-placeholder="<?php esc_attr_e('Any category', 'woocommerce'); ?> "> <?php $category_ids = $coupon->get_product_categories(); $categories = get_terms('product_cat', 'orderby=name&hide_empty=0'); if ($categories) { foreach ($categories as $cat) { echo '<option value="' . esc_attr($cat->term_id) . '"' . selected(in_array($cat->term_id, $category_ids), true, false) . '>' . esc_html($cat->name) . '</option>'; } } ?> </select> <?php echo wc_help_tip(__('A product must be in this category for the coupon to remain valid or, for "Product Discounts", products in these categories will be discounted.', 'woocommerce')); ?> </p> <?php // Exclude Categories ?> <p class="form-field"><label for="exclude_product_categories"><?php _e('Exclude categories', 'woocommerce'); ?> </label> <select id="exclude_product_categories" name="exclude_product_categories[]" style="width: 50%;" class="wc-enhanced-select" multiple="multiple" data-placeholder="<?php esc_attr_e('No categories', 'woocommerce'); ?> "> <?php $category_ids = $coupon->get_excluded_product_categories(); $categories = get_terms('product_cat', 'orderby=name&hide_empty=0'); if ($categories) { foreach ($categories as $cat) { echo '<option value="' . esc_attr($cat->term_id) . '"' . selected(in_array($cat->term_id, $category_ids), true, false) . '>' . esc_html($cat->name) . '</option>'; } } ?> </select> <?php echo wc_help_tip(__('Product must not be in this category for the coupon to remain valid or, for "Product Discounts", products in these categories will not be discounted.', 'woocommerce')); ?> </p> <?php echo '</div><div class="options_group">'; // Customers woocommerce_wp_text_input(array('id' => 'customer_email', 'label' => __('Email restrictions', 'woocommerce'), 'placeholder' => __('No restrictions', 'woocommerce'), 'description' => __('List of allowed emails to check against the customer\'s billing email when an order is placed. Separate email addresses with commas.', 'woocommerce'), 'value' => implode(', ', (array) get_post_meta($post->ID, 'customer_email', true)), 'desc_tip' => true, 'type' => 'email', 'class' => '', 'custom_attributes' => array('multiple' => 'multiple'))); echo '</div>'; do_action('woocommerce_coupon_options_usage_restriction'); ?> </div> <div id="usage_limit_coupon_data" class="panel woocommerce_options_panel"><?php echo '<div class="options_group">'; // Usage limit per coupons woocommerce_wp_text_input(array('id' => 'usage_limit', 'label' => __('Usage limit per coupon', 'woocommerce'), 'placeholder' => esc_attr__('Unlimited usage', 'woocommerce'), 'description' => __('How many times this coupon can be used before it is void.', 'woocommerce'), 'type' => 'number', 'desc_tip' => true, 'class' => 'short', 'custom_attributes' => array('step' => 1, 'min' => 0), 'value' => $coupon->get_usage_limit() ? $coupon->get_usage_limit() : '')); // Usage limit per product woocommerce_wp_text_input(array('id' => 'limit_usage_to_x_items', 'label' => __('Limit usage to X items', 'woocommerce'), 'placeholder' => esc_attr__('Apply to all qualifying items in cart', 'woocommerce'), 'description' => __('The maximum number of individual items this coupon can apply to when using product discounts. Leave blank to apply to all qualifying items in cart.', 'woocommerce'), 'desc_tip' => true, 'class' => 'short', 'type' => 'number', 'custom_attributes' => array('step' => 1, 'min' => 0), 'value' => $coupon->get_limit_usage_to_x_items() ? $coupon->get_limit_usage_to_x_items() : '')); // Usage limit per users woocommerce_wp_text_input(array('id' => 'usage_limit_per_user', 'label' => __('Usage limit per user', 'woocommerce'), 'placeholder' => esc_attr__('Unlimited usage', 'woocommerce'), 'description' => __('How many times this coupon can be used by an invidual user. Uses billing email for guests, and user ID for logged in users.', 'woocommerce'), 'desc_tip' => true, 'class' => 'short', 'type' => 'number', 'custom_attributes' => array('step' => 1, 'min' => 0), 'value' => $coupon->get_usage_limit_per_user() ? $coupon->get_usage_limit_per_user() : '')); echo '</div>'; do_action('woocommerce_coupon_options_usage_limit'); ?> </div> <?php do_action('woocommerce_coupon_data_panels'); ?> <div class="clear"></div> </div> <?php }
/** * Show custom filters to filter coupons by type. */ public function shop_coupon_filters() { ?> <select name='coupon_type' id='dropdown_shop_coupon_type'> <option value=""><?php _e('Show all types', 'woocommerce'); ?> </option> <?php $types = wc_get_coupon_types(); foreach ($types as $name => $type) { echo '<option value="' . esc_attr($name) . '"'; if (isset($_GET['coupon_type'])) { selected($name, $_GET['coupon_type']); } echo '>' . esc_html__($type, 'woocommerce') . '</option>'; } ?> </select> <?php wc_enqueue_js("\n\t\t\tjQuery('select#dropdown_shop_coupon_type, select[name=m]').css('width', '150px').chosen();\n\t\t"); }
/** * Set discount type. * @since 2.7.0 * @param string $discount_type * @throws WC_Data_Exception */ public function set_discount_type($discount_type) { if (!in_array($discount_type, array_keys(wc_get_coupon_types()))) { $this->error('coupon_invalid_discount_type', __('Invalid discount type', 'woocommerce')); } $this->data['discount_type'] = $discount_type; }
/** * Backwards compatible method of getting all discount types * * @return array */ public static function get_discount_types() { return function_exists('wc_get_coupon_types') ? wc_get_coupon_types() : WC()->get_coupon_discount_types(); }
/** * Function to provide area for entering coupon code */ public function woocommerce_product_options_coupons() { global $post, $woocommerce; $all_discount_types = $this->is_wc_gte_21() ? wc_get_coupon_types() : $woocommerce->get_coupon_discount_types(); ?> <p class="form-field" id="sc-field"><label for="_coupon_title"><?php _e('Coupons', self::$text_domain); ?> </label> <?php if ($this->is_wc_gte_23()) { ?> <input type="hidden" class="wc-coupon-search" style="width: 50%;" id="_coupon_title" name="_coupon_title" data-placeholder="<?php _e('Search for a coupon…', self::$text_domain); ?> " data-action="sc_json_search_coupons" data-multiple="true" data-selected="<?php $coupon_titles = array_filter(array_map('trim', (array) get_post_meta($post->ID, '_coupon_title', true))); $json_coupons = array(); if (!empty($coupon_titles)) { foreach ($coupon_titles as $coupon_title) { $coupon = new WC_Coupon($coupon_title); $discount_type = $coupon->discount_type; if (!empty($discount_type)) { $discount_type = sprintf(__(' ( %s: %s )', self::$text_domain), __('Type', self::$text_domain), $all_discount_types[$discount_type]); } $json_coupons[$coupon_title] = $coupon_title . $discount_type; } } echo esc_attr(json_encode($json_coupons)); ?> " value="<?php echo implode(',', array_keys($json_coupons)); ?> " /> <?php } else { ?> <select id="_coupon_title" name="_coupon_title[]" class="ajax_chosen_select_coupons" multiple="multiple" data-placeholder="<?php _e('Search for a coupon...', self::$text_domain); ?> "> <?php $coupon_titles = get_post_meta($post->ID, '_coupon_title', true); if (!empty($coupon_titles)) { foreach ($coupon_titles as $coupon_title) { $coupon = new WC_Coupon($coupon_title); $discount_type = $coupon->discount_type; if (!empty($discount_type)) { $discount_type = sprintf(__(' ( %s: %s )', self::$text_domain), __('Type', self::$text_domain), $all_discount_types[$discount_type]); } echo '<option value="' . $coupon_title . '" selected="selected">' . $coupon_title . $discount_type . '</option>'; } } ?> </select> <?php } ?> <img class="help_tip" data-tip='<?php _e('These coupon/s will be given to customers who buy this product. The coupon code will be automatically sent to their email address on purchase.', self::$text_domain); ?> ' src="<?php echo $this->global_wc()->plugin_url(); ?> /assets/images/help.png" width="16" height="16"/> </p> <script type="text/javascript"> jQuery(function(){ var updateSendCouponOnRenewals = function() { var prodType = jQuery('select#product-type').find('option:selected').val(); <?php if ($this->is_wc_gte_23()) { ?> var associatedCouponCount = jQuery('div[id^="s2id__coupon_title"] ul.select2-choices li.select2-search-choice').length; <?php } elseif ($this->is_wc_gte_21()) { ?> var associatedCouponCount = jQuery('div[id^="_coupon_title_chosen"] ul.chosen-choices li.search-choice').length; <?php } else { ?> var associatedCouponCount = jQuery('div[id^="_coupon_title_chzn"] ul.chzn-choices li.search-choice').length; <?php } ?> if ( ( prodType == 'subscription' || prodType == 'variable-subscription' ) && associatedCouponCount > 0 ) { jQuery('p.send_coupons_on_renewals_field').show(); } else { jQuery('p.send_coupons_on_renewals_field').hide(); } }; setTimeout(function(){updateSendCouponOnRenewals();}, 100); <?php if ($this->is_wc_gte_23()) { ?> if ( typeof getEnhancedSelectFormatString == "undefined" ) { function getEnhancedSelectFormatString() { var formatString = { formatMatches: function( matches ) { if ( 1 === matches ) { return smart_coupons_select_params.i18n_matches_1; } return smart_coupons_select_params.i18n_matches_n.replace( '%qty%', matches ); }, formatNoMatches: function() { return smart_coupons_select_params.i18n_no_matches; }, formatAjaxError: function( jqXHR, textStatus, errorThrown ) { return smart_coupons_select_params.i18n_ajax_error; }, formatInputTooShort: function( input, min ) { var number = min - input.length; if ( 1 === number ) { return smart_coupons_select_params.i18n_input_too_short_1 } return smart_coupons_select_params.i18n_input_too_short_n.replace( '%qty%', number ); }, formatInputTooLong: function( input, max ) { var number = input.length - max; if ( 1 === number ) { return smart_coupons_select_params.i18n_input_too_long_1 } return smart_coupons_select_params.i18n_input_too_long_n.replace( '%qty%', number ); }, formatSelectionTooBig: function( limit ) { if ( 1 === limit ) { return smart_coupons_select_params.i18n_selection_too_long_1; } return smart_coupons_select_params.i18n_selection_too_long_n.replace( '%qty%', number ); }, formatLoadMore: function( pageNumber ) { return smart_coupons_select_params.i18n_load_more; }, formatSearching: function() { return smart_coupons_select_params.i18n_searching; } }; return formatString; } } // Ajax product search box jQuery( ':input.wc-coupon-search' ).filter( ':not(.enhanced)' ).each( function() { var select2_args = { allowClear: jQuery( this ).data( 'allow_clear' ) ? true : false, placeholder: jQuery( this ).data( 'placeholder' ), minimumInputLength: jQuery( this ).data( 'minimum_input_length' ) ? jQuery( this ).data( 'minimum_input_length' ) : '3', escapeMarkup: function( m ) { return m; }, ajax: { url: '<?php echo admin_url("admin-ajax.php"); ?> ', dataType: 'json', quietMillis: 250, data: function( term, page ) { return { term: term, action: jQuery( this ).data( 'action' ) || 'sc_json_search_coupons', security: '<?php echo wp_create_nonce("search-coupons"); ?> ' }; }, results: function( data, page ) { var terms = []; if ( data ) { jQuery.each( data, function( id, text ) { terms.push( { id: id, text: text } ); }); } return { results: terms }; }, cache: true } }; if ( jQuery( this ).data( 'multiple' ) === true ) { select2_args.multiple = true; select2_args.initSelection = function( element, callback ) { var data = jQuery.parseJSON( element.attr( 'data-selected' ) ); var selected = []; jQuery( element.val().split( "," ) ).each( function( i, val ) { selected.push( { id: val, text: data[ val ] } ); }); return callback( selected ); }; select2_args.formatSelection = function( data ) { return '<div class="selected-option" data-id="' + data.id + '">' + data.text + '</div>'; }; } else { select2_args.multiple = false; select2_args.initSelection = function( element, callback ) { var data = {id: element.val(), text: element.attr( 'data-selected' )}; return callback( data ); }; } select2_args = jQuery.extend( select2_args, getEnhancedSelectFormatString() ); jQuery( this ).select2( select2_args ).addClass( 'enhanced' ); }); <?php } else { ?> // Ajax Chosen Coupon Selectors jQuery("select.ajax_chosen_select_coupons").ajaxChosen({ method: 'GET', url: '<?php echo admin_url('admin-ajax.php'); ?> ', dataType: 'json', afterTypeDelay: 100, data: { action: 'sc_json_search_coupons', security: '<?php echo wp_create_nonce("search-coupons"); ?> ' } }, function (data) { var terms = {}; jQuery.each(data, function (i, val) { terms[i] = val; }); return terms; }); <?php } ?> jQuery('select#product-type').on('change', function() { var productType = jQuery(this).find('option:selected').val(); if ( productType == 'simple' || productType == 'variable' || productType == 'subscription' || productType == 'variable-subscription' ) { jQuery('p#sc-field').show(); } else { jQuery('p#sc-field').hide(); } updateSendCouponOnRenewals(); }); jQuery('#_coupon_title').on('change', function(){ setTimeout( function() { updateSendCouponOnRenewals(); }, 10 ); }); }); </script> <?php woocommerce_wp_checkbox(array('id' => 'send_coupons_on_renewals', 'label' => __('Send coupons on renewals?', self::$text_domain), 'description' => __('Check this box to send above coupons on each renewal order.', self::$text_domain))); }
/** * Output the metabox */ public static function output($post) { wp_nonce_field('woocommerce_save_data', 'woocommerce_meta_nonce'); ?> <style type="text/css"> #edit-slug-box, #minor-publishing-actions { display:none } </style> <div id="coupon_options" class="panel-wrap coupon_data"> <div class="wc-tabs-back"></div> <ul class="coupon_data_tabs wc-tabs" style="display:none;"> <?php $coupon_data_tabs = apply_filters('woocommerce_coupon_data_tabs', array('general' => array('label' => __('General', 'yith_wc_product_vendors'), 'target' => 'general_coupon_data', 'class' => 'general_coupon_data'), 'usage_restriction' => array('label' => __('Usage Restriction', 'yith_wc_product_vendors'), 'target' => 'usage_restriction_coupon_data', 'class' => ''), 'usage_limit' => array('label' => __('Usage Limits', 'yith_wc_product_vendors'), 'target' => 'usage_limit_coupon_data', 'class' => ''))); foreach ($coupon_data_tabs as $key => $tab) { ?> <li class="<?php echo $key; ?> _options <?php echo $key; ?> _tab <?php echo implode(' ', (array) $tab['class']); ?> "> <a href="#<?php echo $tab['target']; ?> "><?php echo esc_html($tab['label']); ?> </a> </li><?php } ?> </ul> <div id="general_coupon_data" class="panel woocommerce_options_panel"><?php // Type woocommerce_wp_select(array('id' => 'discount_type', 'label' => __('Discount type', 'yith_wc_product_vendors'), 'options' => wc_get_coupon_types())); // Amount woocommerce_wp_text_input(array('id' => 'coupon_amount', 'label' => __('Coupon amount', 'yith_wc_product_vendors'), 'placeholder' => wc_format_localized_price(0), 'description' => __('Value of the coupon.', 'yith_wc_product_vendors'), 'data_type' => 'price', 'desc_tip' => true)); // Expiry date woocommerce_wp_text_input(array('id' => 'expiry_date', 'label' => __('Coupon expiry date', 'yith_wc_product_vendors'), 'placeholder' => _x('YYYY-MM-DD', 'placeholder', 'yith_wc_product_vendors'), 'description' => '', 'class' => 'date-picker', 'custom_attributes' => array('pattern' => "[0-9]{4}-(0[1-9]|1[012])-(0[1-9]|1[0-9]|2[0-9]|3[01])"))); do_action('woocommerce_coupon_options'); ?> </div> <div id="usage_restriction_coupon_data" class="panel woocommerce_options_panel"><?php echo '<div class="options_group">'; // minimum spend woocommerce_wp_text_input(array('id' => 'minimum_amount', 'label' => __('Minimum spend', 'yith_wc_product_vendors'), 'placeholder' => __('No minimum', 'yith_wc_product_vendors'), 'description' => __('This field allows you to set the minimum subtotal needed to use the coupon.', 'yith_wc_product_vendors'), 'data_type' => 'price', 'desc_tip' => true)); // maximum spend woocommerce_wp_text_input(array('id' => 'maximum_amount', 'label' => __('Maximum spend', 'yith_wc_product_vendors'), 'placeholder' => __('No maximum', 'yith_wc_product_vendors'), 'description' => __('This field allows you to set the maximum subtotal allowed when using the coupon.', 'yith_wc_product_vendors'), 'data_type' => 'price', 'desc_tip' => true)); // Individual use woocommerce_wp_checkbox(array('id' => 'individual_use', 'label' => __('Individual use only', 'yith_wc_product_vendors'), 'description' => __('Check this box if the coupon cannot be used in conjunction with other coupons.', 'yith_wc_product_vendors'))); // Exclude Sale Products woocommerce_wp_checkbox(array('id' => 'exclude_sale_items', 'label' => __('Exclude sale items', 'yith_wc_product_vendors'), 'description' => __('Check this box if the coupon should not apply to items on sale. Per-item coupons will only work if the item is not on sale. Per-cart coupons will only work if there are no sale items in the cart.', 'yith_wc_product_vendors'))); echo '</div><div class="options_group">'; // Product ids ?> <p class="form-field"><label><?php _e('Products', 'yith_wc_product_vendors'); ?> </label> <input type="hidden" class="wc-product-search" data-multiple="true" style="width: 50%;" name="product_ids" data-placeholder="<?php _e('Search for a product…', 'yith_wc_product_vendors'); ?> " data-action="woocommerce_json_search_products_and_variations" data-selected="<?php $product_ids = array_filter(array_map('absint', explode(',', 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($product->get_formatted_name()); } } echo esc_attr(json_encode($json_ids)); ?> " value="<?php echo implode(',', array_keys($json_ids)); ?> " /> <img class="help_tip" data-tip='<?php _e('Select products that must have been added to cart to use this coupon.', 'yith_wc_product_vendors'); ?> ' src="<?php echo WC()->plugin_url(); ?> /assets/images/help.png" height="16" width="16" /></p> <?php // Exclude Product ids ?> <p class="form-field"><label><?php _e('Exclude products', 'yith_wc_product_vendors'); ?> </label> <input type="hidden" class="wc-product-search" data-multiple="true" style="width: 50%;" name="exclude_product_ids" data-placeholder="<?php _e('Search for a product…', 'yith_wc_product_vendors'); ?> " data-action="woocommerce_json_search_products_and_variations" data-selected="<?php $product_ids = array_filter(array_map('absint', explode(',', get_post_meta($post->ID, 'exclude_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($product->get_formatted_name()); } } echo esc_attr(json_encode($json_ids)); ?> " value="<?php echo implode(',', array_keys($json_ids)); ?> " /> <img class="help_tip" data-tip='<?php _e('Select products that must have been added to cart to use this coupon.', 'yith_wc_product_vendors'); ?> ' src="<?php echo WC()->plugin_url(); ?> /assets/images/help.png" height="16" width="16" /></p> <?php echo '</div><div class="options_group">'; // Customers woocommerce_wp_text_input(array('id' => 'customer_email', 'label' => __('Email restrictions', 'yith_wc_product_vendors'), 'placeholder' => __('No restrictions', 'yith_wc_product_vendors'), 'description' => __('List of allowed emails to check against the customer\'s billing email when an order is placed. Separate email addresses with commas.', 'yith_wc_product_vendors'), 'value' => implode(', ', (array) get_post_meta($post->ID, 'customer_email', true)), 'desc_tip' => true, 'type' => 'email', 'class' => '', 'custom_attributes' => array('multiple' => 'multiple'))); echo '</div>'; do_action('woocommerce_coupon_options_usage_restriction'); ?> </div> <div id="usage_limit_coupon_data" class="panel woocommerce_options_panel"><?php echo '<div class="options_group">'; // Usage limit per coupons woocommerce_wp_text_input(array('id' => 'usage_limit', 'label' => __('Usage limit per coupon', 'yith_wc_product_vendors'), 'placeholder' => _x('Unlimited usage', 'placeholder', 'yith_wc_product_vendors'), 'description' => __('How many times this coupon can be used before it is void.', 'yith_wc_product_vendors'), 'type' => 'number', 'desc_tip' => true, 'class' => 'short', 'custom_attributes' => array('step' => '1', 'min' => '0'))); // Usage limit per product woocommerce_wp_text_input(array('id' => 'limit_usage_to_x_items', 'label' => __('Limit usage to X items', 'yith_wc_product_vendors'), 'placeholder' => _x('Apply to all qualifying items in cart', 'placeholder', 'yith_wc_product_vendors'), 'description' => __('The maximum number of individual items this coupon can apply to when using product discounts. Leave blank to apply to all qualifying items in cart.', 'yith_wc_product_vendors'), 'desc_tip' => true, 'class' => 'short', 'type' => 'number', 'custom_attributes' => array('step' => '1', 'min' => '0'))); // Usage limit per users woocommerce_wp_text_input(array('id' => 'usage_limit_per_user', 'label' => __('Usage limit per user', 'yith_wc_product_vendors'), 'placeholder' => _x('Unlimited usage', 'placeholder', 'yith_wc_product_vendors'), 'description' => __('How many times this coupon can be used by an invidual user. Uses billing email for guests, and user ID for logged in users.', 'yith_wc_product_vendors'), 'desc_tip' => true, 'class' => 'short', 'type' => 'number', 'custom_attributes' => array('step' => '1', 'min' => '0'))); echo '</div>'; do_action('woocommerce_coupon_options_usage_limit'); ?> </div> <?php do_action('woocommerce_coupon_data_panels'); ?> <div class="clear"></div> </div> <?php }