/** * @since 1.1.0 of SA_WC_Compatibility */ public static function wc_get_formatted_name($product = false) { if (self::is_wc_21()) { return $product->get_formatted_name(); } else { return woocommerce_get_formatted_product_name($product); } }
/** * Search for products and return json * * @access public * @param string $x (default: '') * @param string $post_types (default: array('product')) * @return void */ function woocommerce_json_search_products($x = '', $post_types = array('product')) { check_ajax_referer('search-products', 'security'); header('Content-Type: application/json; charset=utf-8'); $term = (string) urldecode(stripslashes(strip_tags($_GET['term']))); if (empty($term)) { die; } if (is_numeric($term)) { $args = array('post_type' => $post_types, 'post_status' => 'publish', 'posts_per_page' => -1, 'post__in' => array(0, $term), 'fields' => 'ids'); $args2 = array('post_type' => $post_types, 'post_status' => 'publish', 'posts_per_page' => -1, 'post_parent' => $term, 'fields' => 'ids'); $args3 = array('post_type' => $post_types, 'post_status' => 'publish', 'posts_per_page' => -1, 'meta_query' => array(array('key' => '_sku', 'value' => $term, 'compare' => 'LIKE')), 'fields' => 'ids'); $posts = array_unique(array_merge(get_posts($args), get_posts($args2), get_posts($args3))); } else { $args = array('post_type' => $post_types, 'post_status' => 'publish', 'posts_per_page' => -1, 's' => $term, 'fields' => 'ids'); $args2 = array('post_type' => $post_types, 'post_status' => 'publish', 'posts_per_page' => -1, 'meta_query' => array(array('key' => '_sku', 'value' => $term, 'compare' => 'LIKE')), 'fields' => 'ids'); $posts = array_unique(array_merge(get_posts($args), get_posts($args2))); } $found_products = array(); if ($posts) { foreach ($posts as $post) { $product = get_product($post); $found_products[$post] = woocommerce_get_formatted_product_name($product); } } $found_products = apply_filters('woocommerce_json_search_found_products', $found_products); echo json_encode($found_products); die; }
<div class="toolbar row dokan-clearfix"> <div class="dokan-w8"> <select name="grant_access_id" class="grant_access_id dokan-form-control" data-placeholder="<?php _e('Choose a downloadable product…', 'dokan'); ?> " multiple="multiple"> <?php echo '<option value=""></option>'; $args = array('post_type' => array('product', 'product_variation'), 'posts_per_page' => -1, 'post_status' => 'publish', 'author' => get_current_user_id(), 'order' => 'ASC', 'orderby' => 'parent title', 'meta_query' => array(array('key' => '_downloadable', 'value' => 'yes'))); $products = get_posts($args); if ($products) { foreach ($products as $product) { $product_object = get_product($product->ID); $product_name = woocommerce_get_formatted_product_name($product_object); echo '<option value="' . esc_attr($product->ID) . '">' . esc_html($product_name) . '</option>'; } } ?> </select> </div> <div class="dokan-w4"> <button type="button" class="dokan-btn dokan-btn-success grant_access" data-order-id="<?php echo $order->id; ?> " data-nonce="<?php echo wp_create_nonce('grant-access'); ?> "><?php
/** * Get the fields to display for the selected action, in the format required by woocommerce_admin_fields() * * @since 1.0 * @param string $section the current section to get fields for * @return array */ private function get_action_fields($section) { $products = array(' ' => ''); foreach (WC_Pre_Orders_Manager::get_all_pre_order_enabled_products() as $product) { $products[$product->id] = woocommerce_get_formatted_product_name($product); } $fields = array('email' => array(array('name' => __('Email Pre-Order Customers', WC_Pre_Orders::TEXT_DOMAIN), 'desc' => sprintf(__('You may send an email message to all customers who have pre-ordered a specific product. This will use the default template specified for the %sCustomer Note%s Email.', WC_Pre_Orders::TEXT_DOMAIN), '<a href="' . admin_url('admin.php?page=woocommerce_settings&tab=email§ion=WC_Email_Customer_Note') . '">', '</a>'), 'type' => 'title'), array('id' => 'wc_pre_orders_action_product', 'name' => __('Product', WC_Pre_Orders::TEXT_DOMAIN), 'desc_tip' => __('Select which product to email all pre-ordered customers.'), 'default' => ' ', 'options' => $products, 'type' => 'select'), array('id' => 'wc_pre_orders_action_email_message', 'name' => __('Message', WC_Pre_Orders::TEXT_DOMAIN), 'desc_tip' => __('Enter a message to include in the email notification to customer. Limited HTML allowed.', WC_Pre_Orders::TEXT_DOMAIN), 'css' => 'min-width: 300px;', 'default' => '', 'type' => 'textarea'), array('type' => 'sectionend'), array('name' => __('Send Emails', WC_Pre_Orders::TEXT_DOMAIN), 'type' => 'submit_button')), 'change-date' => array(array('name' => __('Change the Pre-Order Release Date', WC_Pre_Orders::TEXT_DOMAIN), 'desc' => __('You may change the release date for all pre-orders of a specific product. This will send an email notification to each customer informing them that the pre-order release date was changed, along with the new release date.', WC_Pre_Orders::TEXT_DOMAIN), 'type' => 'title'), array('id' => 'wc_pre_orders_action_product', 'name' => __('Product', WC_Pre_Orders::TEXT_DOMAIN), 'desc_tip' => __('Select which product to change the release date for.'), 'default' => ' ', 'options' => $products, 'type' => 'select'), array('id' => 'wc_pre_orders_action_new_availability_date', 'name' => __('New Availability Date', WC_Pre_Orders::TEXT_DOMAIN), 'desc_tip' => __('The new availability date for the product. This must be later than the current availability date.', WC_Pre_Orders::TEXT_DOMAIN), 'default' => '', 'type' => 'text'), array('id' => 'wc_pre_orders_action_enable_email_notification', 'name' => __('Send Email Notification', WC_Pre_Orders::TEXT_DOMAIN), 'desc' => __('Uncheck this to prevent email notifications from being sent to customers.', WC_Pre_Orders::TEXT_DOMAIN), 'default' => 'yes', 'type' => 'checkbox'), array('id' => 'wc_pre_orders_action_email_message', 'name' => __('Message', WC_Pre_Orders::TEXT_DOMAIN), 'desc_tip' => __('Enter a message to include in the email notification to customer.', WC_Pre_Orders::TEXT_DOMAIN), 'default' => '', 'css' => 'min-width: 300px;', 'type' => 'textarea'), array('type' => 'sectionend'), array('name' => __('Change Release Date', WC_Pre_Orders::TEXT_DOMAIN), 'type' => 'submit_button')), 'complete' => array(array('name' => __('Complete Pre-Orders', WC_Pre_Orders::TEXT_DOMAIN), 'desc' => __('You may complete all pre-orders for a specific product. This will charge the customer\'s card the pre-ordered amount, change their order status to completed, and send them an email notification.', WC_Pre_Orders::TEXT_DOMAIN), 'type' => 'title'), array('id' => 'wc_pre_orders_action_product', 'name' => __('Product', WC_Pre_Orders::TEXT_DOMAIN), 'desc_tip' => __('Select which product to complete all pre-orders for.'), 'default' => ' ', 'options' => $products, 'type' => 'select'), array('id' => 'wc_pre_orders_action_enable_email_notification', 'name' => __('Send Email Notification', WC_Pre_Orders::TEXT_DOMAIN), 'desc' => __('Uncheck this to prevent email notifications from being sent to customers.', WC_Pre_Orders::TEXT_DOMAIN), 'default' => 'yes', 'type' => 'checkbox'), array('id' => 'wc_pre_orders_action_email_message', 'name' => __('Message', WC_Pre_Orders::TEXT_DOMAIN), 'desc_tip' => __('Enter a message to include in the email notification to customer.', WC_Pre_Orders::TEXT_DOMAIN), 'default' => '', 'css' => 'min-width: 300px;', 'type' => 'textarea'), array('type' => 'sectionend'), array('name' => __('Complete Pre-Orders', WC_Pre_Orders::TEXT_DOMAIN), 'type' => 'submit_button')), 'cancel' => array(array('name' => __('Cancel Pre-Orders', WC_Pre_Orders::TEXT_DOMAIN), 'desc' => __('You may cancel all pre-orders for a specific product. This will mark the order as cancelled and send the customer an email notification. If pre-orders were charged upfront, you must manually refund the orders.', WC_Pre_Orders::TEXT_DOMAIN), 'type' => 'title'), array('id' => 'wc_pre_orders_action_product', 'name' => __('Product', WC_Pre_Orders::TEXT_DOMAIN), 'desc_tip' => __('Select which product to cancel all pre-orders for.'), 'default' => ' ', 'options' => $products, 'type' => 'select'), array('id' => 'wc_pre_orders_action_enable_email_notification', 'name' => __('Send Email Notification', WC_Pre_Orders::TEXT_DOMAIN), 'desc' => __('Uncheck this to prevent email notifications from being sent to customers.', WC_Pre_Orders::TEXT_DOMAIN), 'default' => 'yes', 'type' => 'checkbox'), array('id' => 'wc_pre_orders_action_email_message', 'name' => __('Message', WC_Pre_Orders::TEXT_DOMAIN), 'desc_tip' => __('Enter a message to include in the email notification to customer.', WC_Pre_Orders::TEXT_DOMAIN), 'default' => '', 'css' => 'min-width: 300px;', 'type' => 'textarea'), array('type' => 'sectionend'), array('name' => __('Cancel Pre-Orders', WC_Pre_Orders::TEXT_DOMAIN), 'type' => 'submit_button'))); return isset($fields[$section]) ? $fields[$section] : array(); }
/** * Display the product data meta box. * * Displays the product data box, tabbed, with several panels covering price, stock etc. * * @access public * @return void */ function woocommerce_product_data_box() { global $post, $wpdb, $thepostid, $woocommerce; wp_nonce_field('woocommerce_save_data', 'woocommerce_meta_nonce'); $thepostid = $post->ID; if ($terms = wp_get_object_terms($post->ID, 'product_type')) { $product_type = sanitize_title(current($terms)->name); } else { $product_type = 'simple'; } $product_type_selector = apply_filters('product_type_selector', array('simple' => __('Simple product', 'woocommerce'), 'grouped' => __('Grouped product', 'woocommerce'), 'external' => __('External/Affiliate product', 'woocommerce')), $product_type); $type_box = '<label for="product-type"><select id="product-type" name="product-type"><optgroup label="' . __('Product Type', 'woocommerce') . '">'; foreach ($product_type_selector as $value => $label) { $type_box .= '<option value="' . esc_attr($value) . '" ' . selected($product_type, $value, false) . '>' . esc_html($label) . '</option>'; } $type_box .= '</optgroup></select></label>'; $product_type_options = apply_filters('product_type_options', array('virtual' => array('id' => '_virtual', 'wrapper_class' => 'show_if_simple', 'label' => __('Virtual', 'woocommerce'), 'description' => __('Virtual products are intangible and aren\'t shipped.', 'woocommerce')), 'downloadable' => array('id' => '_downloadable', 'wrapper_class' => 'show_if_simple', 'label' => __('Downloadable', 'woocommerce'), 'description' => __('Downloadable products give access to a file upon purchase.', 'woocommerce')))); foreach ($product_type_options as $key => $option) { $selected_value = get_post_meta($post->ID, '_' . $key, true); $type_box .= '<label for="' . esc_attr($option['id']) . '" class="' . esc_attr($option['wrapper_class']) . ' tips" data-tip="' . esc_attr($option['description']) . '">' . esc_html($option['label']) . ': <input type="checkbox" name="' . esc_attr($option['id']) . '" id="' . esc_attr($option['id']) . '" ' . checked($selected_value, 'yes', false) . ' /></label>'; } ?> <div class="panel-wrap product_data"> <span class="type_box"> — <?php echo $type_box; ?> </span> <div class="wc-tabs-back"></div> <ul class="product_data_tabs wc-tabs" style="display:none;"> <li class="active general_options hide_if_grouped"><a href="#general_product_data"><?php _e('General', 'woocommerce'); ?> </a></li> <li class="inventory_tab show_if_simple show_if_variable show_if_grouped inventory_options"><a href="#inventory_product_data"><?php _e('Inventory', 'woocommerce'); ?> </a></li> <li class="shipping_tab hide_if_virtual shipping_options hide_if_grouped hide_if_external"><a href="#shipping_product_data"><?php _e('Shipping', 'woocommerce'); ?> </a></li> <li class="linked_product_tab linked_product_options"><a href="#linked_product_data"><?php _e('Linked Products', 'woocommerce'); ?> </a></li> <li class="attributes_tab attribute_options"><a href="#woocommerce_attributes"><?php _e('Attributes', 'woocommerce'); ?> </a></li> <li class="advanced_tab advanced_options"><a href="#advanced_product_data"><?php _e('Advanced', 'woocommerce'); ?> </a></li> <?php do_action('woocommerce_product_write_panel_tabs'); ?> </ul> <div id="general_product_data" class="panel woocommerce_options_panel"><?php echo '<div class="options_group hide_if_grouped">'; // SKU if (get_option('woocommerce_enable_sku', true) !== 'no') { woocommerce_wp_text_input(array('id' => '_sku', 'label' => '<abbr title="' . __('Stock Keeping Unit', 'woocommerce') . '">' . __('SKU', 'woocommerce') . '</abbr>', 'desc_tip' => 'true', 'description' => __('SKU refers to a Stock-keeping unit, a unique identifier for each distinct product and service that can be purchased.', 'woocommerce'))); } else { echo '<input type="hidden" name="_sku" value="' . esc_attr(get_post_meta($thepostid, '_sku', true)) . '" />'; } do_action('woocommerce_product_options_sku'); echo '</div>'; echo '<div class="options_group show_if_external">'; // External URL woocommerce_wp_text_input(array('id' => '_product_url', 'label' => __('Product URL', 'woocommerce'), 'placeholder' => 'http://', 'description' => __('Enter the external URL to the product.', 'woocommerce'))); // Button text woocommerce_wp_text_input(array('id' => '_button_text', 'label' => __('Button text', 'woocommerce'), 'placeholder' => _x('Buy product', 'placeholder', 'woocommerce'), 'description' => __('This text will be shown on the button linking to the external product.', 'woocommerce'))); echo '</div>'; echo '<div class="options_group pricing show_if_simple show_if_external">'; // Price woocommerce_wp_text_input(array('id' => '_regular_price', 'class' => 'wc_input_price short', 'label' => __('Regular Price', 'woocommerce') . ' (' . get_woocommerce_currency_symbol() . ')', 'type' => 'number', 'custom_attributes' => array('step' => 'any', 'min' => '0'))); // Special Price woocommerce_wp_text_input(array('id' => '_sale_price', 'class' => 'wc_input_price short', 'label' => __('Sale Price', 'woocommerce') . ' (' . get_woocommerce_currency_symbol() . ')', 'description' => '<a href="#" class="sale_schedule">' . __('Schedule', 'woocommerce') . '</a>', 'type' => 'number', 'custom_attributes' => array('step' => 'any', 'min' => '0'))); // Special Price date range $sale_price_dates_from = ($date = get_post_meta($thepostid, '_sale_price_dates_from', true)) ? date_i18n('Y-m-d', $date) : ''; $sale_price_dates_to = ($date = get_post_meta($thepostid, '_sale_price_dates_to', true)) ? date_i18n('Y-m-d', $date) : ''; echo ' <p class="form-field sale_price_dates_fields"> <label for="_sale_price_dates_from">' . __('Sale Price Dates', 'woocommerce') . '</label> <input type="text" class="short" name="_sale_price_dates_from" id="_sale_price_dates_from" value="' . $sale_price_dates_from . '" placeholder="' . _x('From…', 'placeholder', 'woocommerce') . ' YYYY-MM-DD" maxlength="10" pattern="[0-9]{4}-(0[1-9]|1[012])-(0[1-9]|1[0-9]|2[0-9]|3[01])" /> <input type="text" class="short" name="_sale_price_dates_to" id="_sale_price_dates_to" value="' . $sale_price_dates_to . '" placeholder="' . _x('To…', 'placeholder', 'woocommerce') . ' YYYY-MM-DD" maxlength="10" pattern="[0-9]{4}-(0[1-9]|1[012])-(0[1-9]|1[0-9]|2[0-9]|3[01])" /> <a href="#" class="cancel_sale_schedule">' . __('Cancel', 'woocommerce') . '</a> </p>'; do_action('woocommerce_product_options_pricing'); echo '</div>'; echo '<div class="options_group show_if_downloadable">'; // File URL $file_paths = get_post_meta($post->ID, '_file_paths', true); if (is_array($file_paths)) { $file_paths = implode("\n", $file_paths); } echo '<p class="form-field"><label for="_file_paths">' . __('File paths (one per line)', 'woocommerce') . ':</label> <textarea style="float:left;height:5em;" id="_file_paths" class="short file_paths" cols="20" rows="3" placeholder="' . __('File paths/URLs, one per line', 'woocommerce') . '" name="_file_paths" wrap="off">' . esc_textarea($file_paths) . '</textarea> <input type="button" class="upload_file_button button" data-choose="' . __('Choose a file', 'woocommerce') . '" data-update="' . __('Insert file URL', 'woocommerce') . '" value="' . __('Choose a file', 'woocommerce') . '" /> </p>'; // Download Limit woocommerce_wp_text_input(array('id' => '_download_limit', 'label' => __('Download Limit', 'woocommerce'), 'placeholder' => __('Unlimited', 'woocommerce'), 'description' => __('Leave blank for unlimited re-downloads.', 'woocommerce'), 'type' => 'number', 'custom_attributes' => array('step' => '1', 'min' => '0'))); // Expirey woocommerce_wp_text_input(array('id' => '_download_expiry', 'label' => __('Download Expiry', 'woocommerce'), 'placeholder' => __('Never', 'woocommerce'), 'description' => __('Enter the number of days before a download link expires, or leave blank.', 'woocommerce'), 'type' => 'number', 'custom_attributes' => array('step' => '1', 'min' => '0'))); do_action('woocommerce_product_options_downloads'); echo '</div>'; if (get_option('woocommerce_calc_taxes') == 'yes') { echo '<div class="options_group show_if_simple show_if_external show_if_variable">'; // Tax woocommerce_wp_select(array('id' => '_tax_status', 'label' => __('Tax Status', 'woocommerce'), 'options' => array('taxable' => __('Taxable', 'woocommerce'), 'shipping' => __('Shipping only', 'woocommerce'), 'none' => __('None', 'woocommerce')))); $tax_classes = array_filter(array_map('trim', explode("\n", get_option('woocommerce_tax_classes')))); $classes_options = array(); $classes_options[''] = __('Standard', 'woocommerce'); if ($tax_classes) { foreach ($tax_classes as $class) { $classes_options[sanitize_title($class)] = esc_html($class); } } woocommerce_wp_select(array('id' => '_tax_class', 'label' => __('Tax Class', 'woocommerce'), 'options' => $classes_options)); do_action('woocommerce_product_options_tax'); echo '</div>'; } do_action('woocommerce_product_options_general_product_data'); ?> </div> <div id="inventory_product_data" class="panel woocommerce_options_panel"> <?php echo '<div class="options_group">'; if (get_option('woocommerce_manage_stock') == 'yes') { // manage stock woocommerce_wp_checkbox(array('id' => '_manage_stock', 'wrapper_class' => 'show_if_simple show_if_variable', 'label' => __('Manage stock?', 'woocommerce'), 'description' => __('Enable stock management at product level', 'woocommerce'))); do_action('woocommerce_product_options_stock'); echo '<div class="stock_fields show_if_simple show_if_variable">'; // Stock woocommerce_wp_text_input(array('id' => '_stock', 'label' => __('Stock Qty', 'woocommerce'), 'desc_tip' => true, 'description' => __('Stock quantity. If this is a variable product this value will be used to control stock for all variations, unless you define stock at variation level.', 'woocommerce'), 'type' => 'number', 'custom_attributes' => array('step' => 'any'))); do_action('woocommerce_product_options_stock_fields'); echo '</div>'; } // Stock status woocommerce_wp_select(array('id' => '_stock_status', 'label' => __('Stock status', 'woocommerce'), 'options' => array('instock' => __('In stock', 'woocommerce'), 'outofstock' => __('Out of stock', 'woocommerce')), 'desc_tip' => true, 'description' => __('Controls whether or not the product is listed as "in stock" or "out of stock" on the frontend.', 'woocommerce'))); if (get_option('woocommerce_manage_stock') == 'yes') { echo '<div class="show_if_simple show_if_variable">'; // Backorders? woocommerce_wp_select(array('id' => '_backorders', 'label' => __('Allow Backorders?', 'woocommerce'), 'options' => array('no' => __('Do not allow', 'woocommerce'), 'notify' => __('Allow, but notify customer', 'woocommerce'), 'yes' => __('Allow', 'woocommerce')), 'desc_tip' => true, 'description' => __('If managing stock, this controls whether or not backorders are allowed for this product and variations. If enabled, stock quantity can go below 0.', 'woocommerce'))); echo '</div>'; } echo '</div>'; echo '<div class="options_group show_if_simple show_if_variable">'; // Individual product woocommerce_wp_checkbox(array('id' => '_sold_individually', 'wrapper_class' => 'show_if_simple show_if_variable', 'label' => __('Sold Individually', 'woocommerce'), 'description' => __('Enable this to only allow one of this item to be bought in a single order', 'woocommerce'))); do_action('woocommerce_product_options_sold_individually'); echo '</div>'; ?> </div> <div id="shipping_product_data" class="panel woocommerce_options_panel"> <?php echo '<div class="options_group">'; // Weight if (get_option('woocommerce_enable_weight', true) !== 'no') { woocommerce_wp_text_input(array('id' => '_weight', 'label' => __('Weight', 'woocommerce') . ' (' . get_option('woocommerce_weight_unit') . ')', 'placeholder' => '0.00', 'description' => __('Weight in decimal form', 'woocommerce'), 'type' => 'number', 'custom_attributes' => array('step' => 'any', 'min' => '0'))); } else { echo '<input type="hidden" name="_weight" value="' . esc_attr(get_post_meta($thepostid, '_weight', true)) . '" />'; } // Size fields if (get_option('woocommerce_enable_dimensions', true) !== 'no') { ?> <p class="form-field dimensions_field"> <label for="product_length"><?php echo __('Dimensions', 'woocommerce') . ' (' . get_option('woocommerce_dimension_unit') . ')'; ?> </label> <span class="wrap"> <input id="product_length" placeholder="<?php _e('Length', 'woocommerce'); ?> " class="input-text" size="6" type="number" name="_length" value="<?php echo esc_attr(get_post_meta($thepostid, '_length', true)); ?> " step="any" min="0" /> <input placeholder="<?php _e('Width', 'woocommerce'); ?> " class="input-text" size="6" type="number" name="_width" value="<?php echo esc_attr(get_post_meta($thepostid, '_width', true)); ?> " step="any" min="0" /> <input placeholder="<?php _e('Height', 'woocommerce'); ?> " class="input-text last" size="6" type="number" name="_height" value="<?php echo esc_attr(get_post_meta($thepostid, '_height', true)); ?> " step="any" min="0" /> </span> <span class="description"><?php _e('LxWxH in decimal form', 'woocommerce'); ?> </span> </p><?php } else { echo '<input type="hidden" name="_length" value="' . esc_attr(get_post_meta($thepostid, '_length', true)) . '" />'; echo '<input type="hidden" name="_width" value="' . esc_attr(get_post_meta($thepostid, '_width', true)) . '" />'; echo '<input type="hidden" name="_height" value="' . esc_attr(get_post_meta($thepostid, '_height', true)) . '" />'; } do_action('woocommerce_product_options_dimensions'); echo '</div>'; echo '<div class="options_group">'; // Shipping Class $classes = get_the_terms($thepostid, 'product_shipping_class'); if ($classes && !is_wp_error($classes)) { $current_shipping_class = current($classes)->term_id; } else { $current_shipping_class = ''; } $args = array('taxonomy' => 'product_shipping_class', 'hide_empty' => 0, 'show_option_none' => __('No shipping class', 'woocommerce'), 'name' => 'product_shipping_class', 'id' => 'product_shipping_class', 'selected' => $current_shipping_class, 'class' => 'select short'); ?> <p class="form-field dimensions_field"><label for="product_shipping_class"><?php _e('Shipping class', 'woocommerce'); ?> </label> <?php wp_dropdown_categories($args); ?> <span class="description"><?php _e('Shipping classes are used by certain shipping methods to group similar products.', 'woocommerce'); ?> </span></p><?php do_action('woocommerce_product_options_shipping'); echo '</div>'; ?> </div> <div id="woocommerce_attributes" class="panel wc-metaboxes-wrapper"> <p class="toolbar"> <a href="#" class="close_all"><?php _e('Close all', 'woocommerce'); ?> </a><a href="#" class="expand_all"><?php _e('Expand all', 'woocommerce'); ?> </a> </p> <div class="woocommerce_attributes wc-metaboxes"> <?php // Array of defined attribute taxonomies $attribute_taxonomies = $woocommerce->get_attribute_taxonomies(); // Product attributes - taxonomies and custom, ordered, with visibility and variation attributes set $attributes = maybe_unserialize(get_post_meta($thepostid, '_product_attributes', true)); $i = -1; // Taxonomies if ($attribute_taxonomies) { foreach ($attribute_taxonomies as $tax) { // Get name of taxonomy we're now outputting (pa_xxx) $attribute_taxonomy_name = $woocommerce->attribute_taxonomy_name($tax->attribute_name); // Ensure it exists if (!taxonomy_exists($attribute_taxonomy_name)) { continue; } $i++; // Get product data values for current taxonomy - this contains ordering and visibility data if (isset($attributes[sanitize_title($attribute_taxonomy_name)])) { $attribute = $attributes[sanitize_title($attribute_taxonomy_name)]; } $position = empty($attribute['position']) ? 0 : absint($attribute['position']); // Get terms of this taxonomy associated with current product $post_terms = wp_get_post_terms($thepostid, $attribute_taxonomy_name); // Any set? $has_terms = is_wp_error($post_terms) || !$post_terms || sizeof($post_terms) == 0 ? 0 : 1; ?> <div class="woocommerce_attribute wc-metabox closed taxonomy <?php echo $attribute_taxonomy_name; ?> " rel="<?php echo $position; ?> " <?php if (!$has_terms) { echo 'style="display:none"'; } ?> > <h3> <button type="button" class="remove_row button"><?php _e('Remove', 'woocommerce'); ?> </button> <div class="handlediv" title="<?php _e('Click to toggle', 'woocommerce'); ?> "></div> <strong class="attribute_name"><?php echo apply_filters('woocommerce_attribute_label', $tax->attribute_label ? $tax->attribute_label : $tax->attribute_name, $tax->attribute_name); ?> </strong> </h3> <table cellpadding="0" cellspacing="0" class="woocommerce_attribute_data wc-metabox-content"> <tbody> <tr> <td class="attribute_name"> <label><?php _e('Name', 'woocommerce'); ?> :</label> <strong><?php echo $tax->attribute_label ? $tax->attribute_label : $tax->attribute_name; ?> </strong> <input type="hidden" name="attribute_names[<?php echo $i; ?> ]" value="<?php echo esc_attr($attribute_taxonomy_name); ?> " /> <input type="hidden" name="attribute_position[<?php echo $i; ?> ]" class="attribute_position" value="<?php echo esc_attr($position); ?> " /> <input type="hidden" name="attribute_is_taxonomy[<?php echo $i; ?> ]" value="1" /> </td> <td rowspan="3"> <label><?php _e('Value(s)', 'woocommerce'); ?> :</label> <?php if ($tax->attribute_type == "select") { ?> <select multiple="multiple" data-placeholder="<?php _e('Select terms', 'woocommerce'); ?> " class="multiselect attribute_values" name="attribute_values[<?php echo $i; ?> ][]"> <?php $all_terms = get_terms($attribute_taxonomy_name, 'orderby=name&hide_empty=0'); if ($all_terms) { foreach ($all_terms as $term) { $has_term = has_term((int) $term->term_id, $attribute_taxonomy_name, $thepostid) ? 1 : 0; echo '<option value="' . esc_attr($term->slug) . '" ' . selected($has_term, 1, false) . '>' . $term->name . '</option>'; } } ?> </select> <button class="button plus select_all_attributes"><?php _e('Select all', 'woocommerce'); ?> </button> <button class="button minus select_no_attributes"><?php _e('Select none', 'woocommerce'); ?> </button> <button class="button fr plus add_new_attribute" data-attribute="<?php echo $attribute_taxonomy_name; ?> "><?php _e('Add new', 'woocommerce'); ?> </button> <?php } elseif ($tax->attribute_type == "text") { ?> <input type="text" name="attribute_values[<?php echo $i; ?> ]" value="<?php // Text attributes should list terms pipe separated if ($post_terms) { $values = array(); foreach ($post_terms as $term) { $values[] = $term->name; } echo implode(' | ', $values); } ?> " placeholder="<?php _e('Pipe (|) separate terms', 'woocommerce'); ?> " /> <?php } ?> <?php do_action('woocommerce_product_option_terms', $tax, $i); ?> </td> </tr> <tr> <td> <label><input type="checkbox" class="checkbox" <?php if (isset($attribute['is_visible'])) { checked($attribute['is_visible'], 1); } else { checked(apply_filters('default_attribute_visibility', false, $tax), true); } ?> name="attribute_visibility[<?php echo $i; ?> ]" value="1" /> <?php _e('Visible on the product page', 'woocommerce'); ?> </label> </td> </tr> <tr> <td> <div class="enable_variation show_if_variable"> <label><input type="checkbox" class="checkbox" <?php if (isset($attribute['is_variation'])) { checked($attribute['is_variation'], 1); } else { checked(apply_filters('default_attribute_variation', false, $tax), true); } ?> name="attribute_variation[<?php echo $i; ?> ]" value="1" /> <?php _e('Used for variations', 'woocommerce'); ?> </label> </div> </td> </tr> </tbody> </table> </div> <?php } } // Custom Attributes if (!empty($attributes)) { foreach ($attributes as $attribute) { if ($attribute['is_taxonomy']) { continue; } $i++; $position = empty($attribute['position']) ? 0 : absint($attribute['position']); ?> <div class="woocommerce_attribute wc-metabox closed" rel="<?php echo $position; ?> "> <h3> <button type="button" class="remove_row button"><?php _e('Remove', 'woocommerce'); ?> </button> <div class="handlediv" title="<?php _e('Click to toggle', 'woocommerce'); ?> "></div> <strong class="attribute_name"><?php echo apply_filters('woocommerce_attribute_label', esc_html($attribute['name']), esc_html($attribute['name'])); ?> </strong> </h3> <table cellpadding="0" cellspacing="0" class="woocommerce_attribute_data wc-metabox-content"> <tbody> <tr> <td class="attribute_name"> <label><?php _e('Name', 'woocommerce'); ?> :</label> <input type="text" class="attribute_name" name="attribute_names[<?php echo $i; ?> ]" value="<?php echo esc_attr($attribute['name']); ?> " /> <input type="hidden" name="attribute_position[<?php echo $i; ?> ]" class="attribute_position" value="<?php echo esc_attr($position); ?> " /> <input type="hidden" name="attribute_is_taxonomy[<?php echo $i; ?> ]" value="0" /> </td> <td rowspan="3"> <label><?php _e('Value(s)', 'woocommerce'); ?> :</label> <textarea name="attribute_values[<?php echo $i; ?> ]" cols="5" rows="5" placeholder="<?php _e('Enter some text, or some attributes by pipe (|) separating values.', 'woocommerce'); ?> "><?php echo esc_textarea($attribute['value']); ?> </textarea> </td> </tr> <tr> <td> <label><input type="checkbox" class="checkbox" <?php checked($attribute['is_visible'], 1); ?> name="attribute_visibility[<?php echo $i; ?> ]" value="1" /> <?php _e('Visible on the product page', 'woocommerce'); ?> </label> </td> </tr> <tr> <td> <div class="enable_variation show_if_variable"> <label><input type="checkbox" class="checkbox" <?php checked($attribute['is_variation'], 1); ?> name="attribute_variation[<?php echo $i; ?> ]" value="1" /> <?php _e('Used for variations', 'woocommerce'); ?> </label> </div> </td> </tr> </tbody> </table> </div> <?php } } ?> </div> <p class="toolbar"> <button type="button" class="button button-primary add_attribute"><?php _e('Add', 'woocommerce'); ?> </button> <select name="attribute_taxonomy" class="attribute_taxonomy"> <option value=""><?php _e('Custom product attribute', 'woocommerce'); ?> </option> <?php if ($attribute_taxonomies) { foreach ($attribute_taxonomies as $tax) { $attribute_taxonomy_name = $woocommerce->attribute_taxonomy_name($tax->attribute_name); $label = $tax->attribute_label ? $tax->attribute_label : $tax->attribute_name; echo '<option value="' . esc_attr($attribute_taxonomy_name) . '">' . esc_html($label) . '</option>'; } } ?> </select> <button type="button" class="button save_attributes"><?php _e('Save attributes', 'woocommerce'); ?> </button> </p> </div> <div id="linked_product_data" class="panel woocommerce_options_panel"> <div class="options_group"> <p class="form-field"><label for="upsell_ids"><?php _e('Up-Sells', 'woocommerce'); ?> </label> <select id="upsell_ids" name="upsell_ids[]" class="ajax_chosen_select_products" multiple="multiple" data-placeholder="<?php _e('Search for a product…', 'woocommerce'); ?> "> <?php $upsell_ids = get_post_meta($post->ID, '_upsell_ids', true); $product_ids = !empty($upsell_ids) ? array_map('absint', $upsell_ids) : null; if ($product_ids) { foreach ($product_ids as $product_id) { $product = get_product($product_id); $product_name = woocommerce_get_formatted_product_name($product); echo '<option value="' . esc_attr($product_id) . '" selected="selected">' . esc_html($product_name) . '</option>'; } } ?> </select> <img class="help_tip" data-tip='<?php _e('Up-sells are products which you recommend instead of the currently viewed product, for example, products that are more profitable or better quality or more expensive.', 'woocommerce'); ?> ' src="<?php echo $woocommerce->plugin_url(); ?> /assets/images/help.png" height="16" width="16" /></p> <p class="form-field"><label for="crosssell_ids"><?php _e('Cross-Sells', 'woocommerce'); ?> </label> <select id="crosssell_ids" name="crosssell_ids[]" class="ajax_chosen_select_products" multiple="multiple" data-placeholder="<?php _e('Search for a product…', 'woocommerce'); ?> "> <?php $crosssell_ids = get_post_meta($post->ID, '_crosssell_ids', true); $product_ids = !empty($crosssell_ids) ? array_map('absint', $crosssell_ids) : null; if ($product_ids) { foreach ($product_ids as $product_id) { $product = get_product($product_id); $product_name = woocommerce_get_formatted_product_name($product); if ($product) { echo '<option value="' . esc_attr($product_id) . '" selected="selected">' . esc_html($product_name) . '</option>'; } } } ?> </select> <img class="help_tip" data-tip='<?php _e('Cross-sells are products which you promote in the cart, based on the current product.', 'woocommerce'); ?> ' src="<?php echo $woocommerce->plugin_url(); ?> /assets/images/help.png" height="16" width="16" /></p> </div> <?php echo '<div class="options_group grouping show_if_simple show_if_external">'; // List Grouped products $post_parents = array(); $post_parents[''] = __('Choose a grouped product…', 'woocommerce'); $posts_in = array_unique((array) get_objects_in_term(get_term_by('slug', 'grouped', 'product_type')->term_id, 'product_type')); if (sizeof($posts_in) > 0) { $args = array('post_type' => 'product', 'post_status' => 'any', 'numberposts' => -1, 'orderby' => 'title', 'order' => 'asc', 'post_parent' => 0, 'include' => $posts_in); $grouped_products = get_posts($args); if ($grouped_products) { foreach ($grouped_products as $product) { if ($product->ID == $post->ID) { continue; } $post_parents[$product->ID] = $product->post_title; } } } woocommerce_wp_select(array('id' => 'parent_id', 'label' => __('Grouping', 'woocommerce'), 'value' => absint($post->post_parent), 'options' => $post_parents, 'desc_tip' => true, 'description' => __('Set this option to make this product part of a grouped product.', 'woocommerce'))); woocommerce_wp_hidden_input(array('id' => 'previous_parent_id', 'value' => absint($post->post_parent))); do_action('woocommerce_product_options_grouping'); echo '</div>'; ?> <?php do_action('woocommerce_product_options_related'); ?> </div> <div id="advanced_product_data" class="panel woocommerce_options_panel"> <?php echo '<div class="options_group hide_if_external">'; // Purchase note woocommerce_wp_textarea_input(array('id' => '_purchase_note', 'label' => __('Purchase Note', 'woocommerce'), 'description' => __('Enter an optional note to send the customer after purchase.', 'woocommerce'))); echo '</div>'; echo '<div class="options_group">'; // menu_order woocommerce_wp_text_input(array('id' => 'menu_order', 'label' => __('Menu order', 'woocommerce'), 'description' => __('Custom ordering position.', 'woocommerce'), 'value' => intval($post->menu_order), 'type' => 'number', 'custom_attributes' => array('step' => '1'))); echo '</div>'; echo '<div class="options_group reviews">'; woocommerce_wp_checkbox(array('id' => 'comment_status', 'label' => __('Enable reviews', 'woocommerce'), 'cbvalue' => 'open', 'value' => esc_attr($post->comment_status))); do_action('woocommerce_product_options_reviews'); echo '</div>'; ?> </div> <?php do_action('woocommerce_product_write_panels'); ?> <div class="clear"></div> </div> <?php }
/** * Displays the order downloads meta box. * * @access public * @return void */ function woocommerce_order_downloads_meta_box() { global $woocommerce, $post, $wpdb; ?> <div class="order_download_permissions wc-metaboxes-wrapper"> <div class="wc-metaboxes"> <?php $download_permissions = $wpdb->get_results($wpdb->prepare("\n\t\t\t\t\tSELECT * FROM {$wpdb->prefix}woocommerce_downloadable_product_permissions\n\t\t\t\t\tWHERE order_id = %d ORDER BY product_id\n\t\t\t\t", $post->ID)); $product = null; $loop = 0; if ($download_permissions && sizeof($download_permissions) > 0) { foreach ($download_permissions as $download) { if (!$product || $product->id != $download->product_id) { $product = get_product(absint($download->product_id)); $file_count = 0; } // don't show permissions to files that have since been removed if (!$product || !$product->exists() || !$product->has_file($download->download_id)) { continue; } include 'order-download-permission-html.php'; $loop++; $file_count++; } } ?> </div> <div class="toolbar"> <p class="buttons"> <select name="grant_access_id" class="grant_access_id chosen_select_nostd" data-placeholder="<?php _e('Choose a downloadable product…', 'woocommerce'); ?> "> <?php echo '<option value=""></option>'; $args = array('post_type' => array('product', 'product_variation'), 'posts_per_page' => -1, 'post_status' => 'publish', 'order' => 'ASC', 'orderby' => 'parent title', 'meta_query' => array(array('key' => '_downloadable', 'value' => 'yes'))); $products = get_posts($args); if ($products) { foreach ($products as $product) { $product_object = get_product($product->ID); $product_name = woocommerce_get_formatted_product_name($product_object); echo '<option value="' . esc_attr($product->ID) . '">' . esc_html($product_name) . '</option>'; } } ?> </select> <button type="button" class="button grant_access"><?php _e('Grant Access', 'woocommerce'); ?> </button> </p> <div class="clear"></div> </div> </div> <?php /** * Javascript */ ob_start(); ?> jQuery(function(){ jQuery('.order_download_permissions').on('click', 'button.grant_access', function(){ var product = jQuery('select.grant_access_id').val(); if (!product) return; jQuery('.order_download_permissions').block({ message: null, overlayCSS: { background: '#fff url(<?php echo $woocommerce->plugin_url(); ?> /assets/images/ajax-loader.gif) no-repeat center', opacity: 0.6 } }); var data = { action: 'woocommerce_grant_access_to_download', product_id: product, loop: jQuery('.order_download_permissions .wc-metabox').size(), order_id: '<?php echo $post->ID; ?> ', security: '<?php echo wp_create_nonce("grant-access"); ?> ' }; jQuery.post('<?php echo admin_url('admin-ajax.php'); ?> ', data, function( response ) { if ( response ) { jQuery('.order_download_permissions .wc-metaboxes').append( response ); } else { alert('<?php echo esc_js(__('Could not grant access - the user may already have permission for this file or billing email is not set. Ensure the billing email is set, and the order has been saved.', 'woocommerce')); ?> '); } jQuery( ".date-picker" ).datepicker({ dateFormat: "yy-mm-dd", numberOfMonths: 1, showButtonPanel: true, showOn: "button", buttonImage: woocommerce_writepanel_params.calendar_image, buttonImageOnly: true }); jQuery('.order_download_permissions').unblock(); }); return false; }); jQuery('.order_download_permissions').on('click', 'button.revoke_access', function(e){ e.preventDefault(); var answer = confirm('<?php echo esc_js(__('Are you sure you want to revoke access to this download?', 'woocommerce')); ?> '); if (answer){ var el = jQuery(this).parent().parent(); var product = jQuery(this).attr('rel').split(",")[0]; var file = jQuery(this).attr('rel').split(",")[1]; if (product>0) { jQuery(el).block({ message: null, overlayCSS: { background: '#fff url(<?php echo $woocommerce->plugin_url(); ?> /assets/images/ajax-loader.gif) no-repeat center', opacity: 0.6 } }); var data = { action: 'woocommerce_revoke_access_to_download', product_id: product, download_id: file, order_id: '<?php echo $post->ID; ?> ', security: '<?php echo wp_create_nonce("revoke-access"); ?> ' }; jQuery.post('<?php echo admin_url('admin-ajax.php'); ?> ', data, function(response) { // Success jQuery(el).fadeOut('300', function(){ jQuery(el).remove(); }); }); } else { jQuery(el).fadeOut('300', function(){ jQuery(el).remove(); }); } } return false; }); }); <?php $javascript = ob_get_clean(); $woocommerce->add_inline_js($javascript); }
/** * Renders coupon options. */ public static function woocommerce_coupon_options() { global $post, $woocommerce; // // Volume discounts based on cart items // echo '<div class="options_group">'; echo '<p>'; echo '<strong>'; echo __('Volume Discount', WOO_VOLDISC_PLUGIN_DOMAIN); echo '</strong>'; echo '</p>'; $product_ids = !empty($post) && !empty($post->ID) ? get_post_meta($post->ID, '_vd_product_ids', false) : array(); echo '<p class="form-field _vd_product_ids_field">'; echo '<label for="_vd_product_ids">'; echo __('Products', WOO_VOLDISC_PLUGIN_DOMAIN); echo '</label>'; printf('<select id="_vd_product_ids" class="ajax_chosen_select_products_and_variations _vd_product_ids multiselect" name="_vd_product_ids[]" multiple="multiple" title="%s" data-placeholder="%s">', __('Start typing to search for products.', WOO_VOLDISC_PLUGIN_DOMAIN), __('Search for a product …', WOO_VOLDISC_PLUGIN_DOMAIN)); foreach ($product_ids as $product_id) { $product = get_product($product_id); $product_name = woocommerce_get_formatted_product_name($product); printf('<option value="%s" %s>%s</option>', esc_attr($product_id), ' selected="selected" ', wp_kses_post($product_name)); } echo '</select>'; printf('<img class="help_tip" data-tip="%s" src="%s" height="16" width="16" />', __('For a customer to be allowed to apply this coupon, at least one of the chosen products must be in the cart and its quantity must be within the given minimum and maximum.', WOO_VOLDISC_PLUGIN_DOMAIN), esc_attr($woocommerce->plugin_url() . '/assets/images/help.png')); echo '</p>'; $term_ids = !empty($post) && !empty($post->ID) ? get_post_meta($post->ID, '_vd_term_ids', false) : array(); echo '<p class="form-field _vd_product_ids_field">'; echo '<label for="_vd_term_ids">'; echo __('Product Categories', WOO_VOLDISC_PLUGIN_DOMAIN); echo '</label>'; printf('<select id="_vd_term_ids" class="chosen_select" name="_vd_term_ids[]" multiple="multiple" title="%s" data-placeholder="%s">', __('Start typing to search for categories.', WOO_VOLDISC_PLUGIN_DOMAIN), __('Search for a category …', WOO_VOLDISC_PLUGIN_DOMAIN)); $categories = get_terms('product_cat', 'orderby=name&hide_empty=0'); if ($categories) { foreach ($categories as $category) { printf('<option value="%s" %s>%s</option>', esc_attr($category->term_id), in_array($category->term_id, $term_ids) ? ' selected="selected" ' : '', esc_html($category->name)); } } echo '</select>'; printf('<img class="help_tip" data-tip="%s" src="%s" height="16" width="16" />', __('If one or more categories are chosen, the coupon is valid if at least one product in the selected categories is in the cart and its quantity is within the given minimum and maximum.', WOO_VOLDISC_PLUGIN_DOMAIN), esc_attr($woocommerce->plugin_url() . '/assets/images/help.png')); echo '</p>'; woocommerce_wp_text_input(array('id' => '_vd_min', 'label' => __('Minimum', WOO_VOLDISC_PLUGIN_DOMAIN), 'placeholder' => __('no restriction', WOO_VOLDISC_PLUGIN_DOMAIN), 'description' => __('Input the minimum quantity that must be in the cart. The condition is met, if for any of the chosen products, or any product in the selected categories, the minimum quantity is in the cart.', WOO_VOLDISC_PLUGIN_DOMAIN), 'desc_tip' => true)); woocommerce_wp_text_input(array('id' => '_vd_max', 'label' => __('Maximum', WOO_VOLDISC_PLUGIN_DOMAIN), 'placeholder' => __('no restriction', WOO_VOLDISC_PLUGIN_DOMAIN), 'description' => __('Input the maximum quantity allowed in the cart. The condition is met, if for any of the chosen products, or any product in the selected categories, the quantity in the cart does not exceed the maximum.', WOO_VOLDISC_PLUGIN_DOMAIN), 'desc_tip' => true)); woocommerce_wp_checkbox(array('id' => '_vd_auto', 'label' => __('Apply automatically', WOO_VOLDISC_PLUGIN_DOMAIN), 'description' => __('Apply this coupon automatically when valid based on these conditions.', WOO_VOLDISC_PLUGIN_DOMAIN))); woocommerce_wp_checkbox(array('id' => '_vd_sum_by_term_id', 'label' => __('Sum categories', WOO_VOLDISC_PLUGIN_DOMAIN), 'description' => __('Sum the number of units per category. If this is enabled, the quantity restrictions are based on the totals per category, instead of per individual product. This applies only to products in the selected categories, if any.', WOO_VOLDISC_PLUGIN_DOMAIN))); echo '<p class="description">'; echo __('The coupon <strong>will only be restricted</strong>, if at least one product or category and a minimum or a maximum (or both) are set.', WOO_VOLDISC_PLUGIN_DOMAIN); echo ' '; echo __('For product <strong>variations</strong>, if a variable product is chosen (i.e. the parent to its variations), the quantity in the cart used to check the minimum or maximum is the combined total of all variations in the cart.', WOO_VOLDISC_PLUGIN_DOMAIN); echo ' '; echo __('If a product variation is chosen (i.e. a product variation derived by attribute from its parent product), the quantity check is made for that variation only, independent of other variations in the cart.', WOO_VOLDISC_PLUGIN_DOMAIN); echo ' '; echo __('If both products and categories are indicated, one of the specified products or a product that belongs to one of the categories must meet the quantity restrictions.', WOO_VOLDISC_PLUGIN_DOMAIN); echo '</p>'; echo '<p>'; echo __('<strong>Display Options</strong>', WOO_VOLDISC_PLUGIN_DOMAIN); echo ' - '; echo __('For the products indicated and products in the selected categories, the product displayed can be enhanced with information based on the coupon\'s description and volume discount.', WOO_VOLDISC_PLUGIN_DOMAIN); echo '</p>'; echo '<p>'; echo __('Show the <em>coupon description</em> for products on these pages:', WOO_VOLDISC_PLUGIN_DOMAIN); echo '</p>'; $description_display = get_post_meta($post->ID, '_vd_description_display', false); foreach (self::$display_indexes as $key => $label) { woocommerce_wp_checkbox(array('id' => '_vd_description_display_' . $key, 'label' => $label, 'value' => in_array($key, $description_display) ? 'yes' : '')); } echo '<p>'; echo __('Show the <em>volume discount info</em> for products on these pages:', WOO_VOLDISC_PLUGIN_DOMAIN); echo '</p>'; $info_display = get_post_meta($post->ID, '_vd_info_display', false); foreach (self::$display_indexes as $key => $label) { woocommerce_wp_checkbox(array('id' => '_vd_info_display_' . $key, 'label' => $label, 'value' => in_array($key, $info_display) ? 'yes' : '')); } echo '<p>'; echo __('<strong>Auto-apply Display Options</strong>', WOO_VOLDISC_PLUGIN_DOMAIN); echo '</p>'; woocommerce_wp_textarea_input(array('id' => '_vd_auto_message_display', 'label' => __('Message', WOO_VOLDISC_PLUGIN_DOMAIN), 'description' => __('If not empty, display a message when the coupon is automatically applied.', WOO_VOLDISC_PLUGIN_DOMAIN))); woocommerce_wp_checkbox(array('id' => '_vd_auto_description_display', 'label' => __('Description', WOO_VOLDISC_PLUGIN_DOMAIN), 'description' => __('Display the coupon description when the coupon is automatically applied.', WOO_VOLDISC_PLUGIN_DOMAIN))); woocommerce_wp_checkbox(array('id' => '_vd_auto_info_display', 'label' => __('Volume Discount Info', WOO_VOLDISC_PLUGIN_DOMAIN), 'description' => __('Display the <em>volume discount info</em> when the coupon is automatically applied.', WOO_VOLDISC_PLUGIN_DOMAIN))); echo '</div>'; // .options_group }
/** * Displays the coupon data meta box. * * @access public * @param mixed $post * @return void */ function woocommerce_coupon_data_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 } </style> <div id="coupon_options" class="panel woocommerce_options_panel"> <?php echo '<div class="options_group">'; // Description woocommerce_wp_text_input(array('id' => 'coupon_description', 'label' => __('Coupon description', 'woocommerce'), 'description' => __('Optionally enter a description for this coupon for your reference.', 'woocommerce'), 'value' => $post->post_excerpt, 'name' => 'excerpt')); echo '</div><div class="options_group">'; // Type woocommerce_wp_select(array('id' => 'discount_type', 'label' => __('Discount type', 'woocommerce'), 'options' => $woocommerce->get_coupon_discount_types())); // Amount woocommerce_wp_text_input(array('id' => 'coupon_amount', 'label' => __('Coupon amount', 'woocommerce'), 'placeholder' => '0.00', 'description' => __('Value of the coupon.', 'woocommerce'), 'type' => 'number', 'custom_attributes' => array('step' => 'any', 'min' => '0'))); // Free Shipping woocommerce_wp_checkbox(array('id' => 'free_shipping', 'label' => __('Enable 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 checked.', 'woocommerce'), admin_url('admin.php?page=woocommerce_settings&tab=shipping§ion=WC_Shipping_Free_Shipping')))); // Individual use woocommerce_wp_checkbox(array('id' => 'individual_use', 'label' => __('Individual use', 'woocommerce'), 'description' => __('Check this box if the coupon cannot be used in conjunction with other coupons.', 'woocommerce'))); // 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'))); // 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">'; // minimum spend woocommerce_wp_text_input(array('id' => 'minimum_amount', 'label' => __('Minimum amount', 'woocommerce'), 'placeholder' => __('No minimum', 'woocommerce'), 'description' => __('This field allows you to set the minimum subtotal needed to use the coupon.', 'woocommerce'), 'type' => 'number', 'custom_attributes' => array('step' => 'any', 'min' => '0'))); 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 = get_product($product_id); $product_name = woocommerce_get_formatted_product_name($product); echo '<option value="' . esc_attr($product_id) . '" selected="selected">' . wp_kses_post($product_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 $woocommerce->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 = get_product($product_id); $product_name = woocommerce_get_formatted_product_name($product); echo '<option value="' . esc_attr($product_id) . '" selected="selected">' . esc_html($product_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 $woocommerce->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 $woocommerce->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 $woocommerce->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.', 'woocommerce'), 'value' => implode(', ', (array) get_post_meta($post->ID, 'customer_email', true)), 'type' => 'email', 'custom_attributes' => array('multiple' => 'multiple'))); echo '</div><div class="options_group">'; // Usage limit woocommerce_wp_text_input(array('id' => 'usage_limit', 'label' => __('Usage limit', 'woocommerce'), 'placeholder' => _x('Unlimited usage', 'placeholder', 'woocommerce'), 'description' => __('How many times this coupon can be used before it is void.', 'woocommerce'), 'type' => 'number', 'custom_attributes' => array('step' => '1', 'min' => '0'))); // Expiry date woocommerce_wp_text_input(array('id' => 'expiry_date', 'label' => __('Expiry date', 'woocommerce'), 'placeholder' => _x('Never expire', 'placeholder', 'woocommerce'), 'description' => __('The date this coupon will expire, <code>YYYY-MM-DD</code>.', 'woocommerce'), 'class' => 'short 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])"))); echo '</div>'; do_action('woocommerce_coupon_options'); ?> </div> <?php }
/** * Extra controls to be displayed between bulk actions and pagination, which * includes our Filters: Customers, Products, Availability Dates * * @see WP_List_Table::extra_tablenav(); * @since 1.0 * @param string $which the placement, one of 'top' or 'bottom' */ public function extra_tablenav($which) { global $woocommerce; if ('top' == $which) { echo '<div class="alignleft actions">'; // Customers, products if (version_compare(WOOCOMMERCE_VERSION, '2.3.0', '>')) { ?> <select id="dropdown_customers" name="_customer_user"> <option value=""><?php _e('Show all customers', 'wc-pre-orders'); ?> </option> <?php if (!empty($_GET['_customer_user'])) { $user = get_user_by('id', absint($_GET['_customer_user'])); echo '<option value="' . absint($user->ID) . '" '; selected(1, 1); echo '>' . esc_html($user->display_name) . ' (#' . absint($user->ID) . ' – ' . esc_html($user->user_email) . ')</option>'; } ?> </select> <select id="dropdown_products" name="_product"> <option value=""><?php _e('Show all Products', 'wc-pre-orders'); ?> </option> <?php if (!empty($_GET['_product'])) { $product = get_product(absint($_GET['_product'])); if (method_exists($product, 'get_formatted_name')) { $product_name = $product->get_formatted_name(); } else { $product_name = woocommerce_get_formatted_product_name($product); } echo '<option value="' . absint($product->id) . '" '; selected(1, 1); echo '>' . esc_html($product_name) . '</option>'; } ?> </select> <?php } else { $user_string = ''; $user_id = ''; if (!empty($_GET['_customer_user'])) { $user_id = absint($_GET['_customer_user']); $user = get_user_by('id', $user_id); $user_string = esc_html($user->display_name) . ' (#' . absint($user->ID) . ' – ' . esc_html($user->user_email); } $product_name = ''; $product_id = ''; if (!empty($_GET['_product'])) { $product_id = absint($_GET['_product']); $product = get_product($product_id); $product_name = $product->get_formatted_name(); } ?> <input type="hidden" id="dropdown_customers" class="wc-customer-search" name="_customer_user" data-placeholder="<?php _e('Search for a customer…', 'wc-pre-orders'); ?> " data-selected="<?php echo esc_attr($user_string); ?> " value="<?php echo $user_id; ?> " data-allow_clear="true" style="width: 250px;" /> <input type="hidden" id="dropdown_products" class="wc-product-search" name="_product" data-placeholder="<?php _e('Search for a product…', 'wc-pre-orders'); ?> " data-selected="<?php echo esc_attr($product_name); ?> " value="<?php echo $product_id; ?> " data-allow_clear="true" style="width: 250px;" /> <?php } $this->render_availability_dates_dropdown(); submit_button(__('Filter'), 'button', false, false, array('id' => 'post-query-submit')); echo '</div>'; // Bulk action fields echo '<div id="bulk-action-fields" style="clear:left;padding-top:10px;display:none;">'; echo '<textarea cols="62" rows="3" name="customer_message" placeholder="' . __('Optional message to include in the email to the customer', 'wc-pre-orders') . '"></textarea>'; echo '</div>'; $javascript = "\n\t\t\t\t\$( 'select[name=\"action\"]' ).change( function() {\n\t\t\t\t\tif ( -1 == \$(this).val() ) {\n\t\t\t\t\t\t\$( '#bulk-action-fields' ).slideUp();\n\t\t\t\t\t} else {\n\t\t\t\t\t\t\$( '#bulk-action-fields' ).slideDown();\n\t\t\t\t\t}\n\t\t\t\t}).change();\n\n\t\t\t\t\$( 'select[name=\"action2\"]' ).change( function() {\n\t\t\t\t\tif ( -1 == \$(this).val() ) {\n\t\t\t\t\t\t\$('#bulk-action-fields2').slideUp();\n\t\t\t\t\t} else {\n\t\t\t\t\t\t\$('#bulk-action-fields2').slideDown();\n\t\t\t\t\t}\n\t\t\t\t}).change();\n\n\t\t\t\t\$( 'span.cancel' ).click( function( e ) {\n\t\t\t\t\tif ( ! window.confirm( '" . __('Are you sure you want to cancel this pre-order?', 'wc-pre-orders') . "' ) ) {\n\t\t\t\t\t\te.preventDefault();\n\t\t\t\t\t}\n\t\t\t\t});\n\t\t\t"; if (version_compare(WOOCOMMERCE_VERSION, '2.3.0', '>')) { $chosen = "\n\t\t\t\t\t// Ajax Chosen Product Selectors\n\t\t\t\t\t\$('select#dropdown_availability_dates').css('width', '250px').chosen();\n\n\t\t\t\t\t\$('select#dropdown_customers').css('width', '250px').ajaxChosen({\n\t\t\t\t\t\tmethod: 'GET',\n\t\t\t\t\t\turl: '" . admin_url('admin-ajax.php') . "',\n\t\t\t\t\t\tdataType: 'json',\n\t\t\t\t\t\tafterTypeDelay: 100,\n\t\t\t\t\t\tminTermLength: 1,\n\t\t\t\t\t\tdata: {\n\t\t\t\t\t\t\taction: 'woocommerce_json_search_customers',\n\t\t\t\t\t\t\tsecurity: '" . wp_create_nonce("search-customers") . "',\n\t\t\t\t\t\t\tdefault: '" . __('Show all customers', 'wc-pre-orders') . "'\n\t\t\t\t\t\t}\n\t\t\t\t\t}, function (data) {\n\n\t\t\t\t\t\tvar terms = {};\n\n\t\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\t});\n\n\t\t\t\t\t\treturn terms;\n\t\t\t\t\t});\n\n\t\t\t\t\t\$('select#dropdown_products').css( 'width', '250px').ajaxChosen({\n\t\t\t\t\t\tmethod: 'GET',\n\t\t\t\t\t\turl: '" . admin_url('admin-ajax.php') . "',\n\t\t\t\t\t\tdataType: 'json',\n\t\t\t\t\t\tafterTypeDelay: 100,\n\t\t\t\t\t\tdata: {\n\t\t\t\t\t\t\taction: 'woocommerce_json_search_products',\n\t\t\t\t\t\t\tsecurity: '" . wp_create_nonce('search-products') . "'\n\t\t\t\t\t\t}\n\t\t\t\t\t}, function (data) {\n\n\t\t\t\t\t\tvar terms = {};\n\n\t\t\t\t\t\tjQuery.each(data, function (i, val) {\n\t\t\t\t\t\t\tterms[i] = val;\n\t\t\t\t\t\t});\n\n\t\t\t\t\t\treturn terms;\n\t\t\t\t\t});\n\t\t\t\t"; $javascript = $chosen . $javascript; } if (function_exists('wc_enqueue_js')) { wc_enqueue_js($javascript); } else { $woocommerce->add_inline_js($javascript); } } elseif ('bottom' == $which) { // Bulk action fields echo '<div id="bulk-action-fields2" style="clear:left;padding-top:10px;display:none;">'; echo '<textarea cols="62" rows="3" name="customer_message2" placeholder="' . __('Optional message to include in the email to the customer', 'wc-pre-orders') . '"></textarea>'; echo '</div>'; } }
/** * Extra controls to be displayed between bulk actions and pagination, which * includes our Filters: Customers, Products, Availability Dates * * @see WP_List_Table::extra_tablenav(); * @since 1.0 * @param string $which the placement, one of 'top' or 'bottom' */ public function extra_tablenav($which) { global $woocommerce; if ('top' == $which) { echo '<div class="alignleft actions">'; // Customers, products ?> <select id="dropdown_customers" name="_customer_user"> <option value=""><?php _e('Show all customers', WC_Pre_Orders::TEXT_DOMAIN); ?> </option> <?php if (!empty($_GET['_customer_user'])) { $user = get_user_by('id', absint($_GET['_customer_user'])); echo '<option value="' . absint($user->ID) . '" '; selected(1, 1); echo '>' . esc_html($user->display_name) . ' (#' . absint($user->ID) . ' – ' . esc_html($user->user_email) . ')</option>'; } ?> </select> <select id="dropdown_products" name="_product"> <option value=""><?php _e('Show all Products', WC_Pre_Orders::TEXT_DOMAIN); ?> </option> <?php if (!empty($_GET['_product'])) { $product = get_product(absint($_GET['_product'])); echo '<option value="' . absint($product->id) . '" '; selected(1, 1); echo '>' . esc_html(woocommerce_get_formatted_product_name($product)) . '</option>'; } ?> </select> <?php $this->render_availability_dates_dropdown(); submit_button(__('Filter'), 'button', false, false, array('id' => 'post-query-submit')); echo '</div>'; // Bulk action fields echo '<div id="bulk-action-fields" style="clear:left;padding-top:10px;display:none;">'; echo '<textarea cols="62" rows="3" name="customer_message" placeholder="' . __('Optional message to include in the email to the customer', WC_Pre_Orders::TEXT_DOMAIN) . '"></textarea>'; echo '</div>'; // javascript $woocommerce->add_inline_js("\n\t\t\t\t// Ajax Chosen Product Selectors\n\t\t\t\t\$('select#dropdown_availability_dates').css('width', '250px').chosen();\n\n\t\t\t\t\$('select#dropdown_customers').css('width', '250px').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_customers',\n\t\t\t\t\t\tsecurity: '" . wp_create_nonce("search-customers") . "',\n\t\t\t\t\t\tdefault: '" . __('Show all customers', WC_Pre_Orders::TEXT_DOMAIN) . "'\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\tterms[i] = val;\n\t\t\t\t\t});\n\n\t\t\t\t\treturn terms;\n\t\t\t\t});\n\n\t\t\t\t\$('select#dropdown_products').css( 'width', '250px').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\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\tjQuery.each(data, function (i, val) {\n\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\n\t\t\t\t\$('select[name=\"action\"]').change( function() {\n\t\t\t\t\tif (-1 == \$(this).val()) \$('#bulk-action-fields').slideUp();\n\t\t\t\t\telse \$('#bulk-action-fields').slideDown();\n\t\t\t\t}).change();\n\n\t\t\t\t\$('select[name=\"action2\"]').change( function() {\n\t\t\t\t\tif (-1 == \$(this).val()) \$('#bulk-action-fields2').slideUp();\n\t\t\t\t\telse \$('#bulk-action-fields2').slideDown();\n\t\t\t\t}).change();\n\n\t\t\t\t\$('span.cancel').click(function(e) {\n\t\t\t\t\tif(!confirm('" . __('Are you sure you want to cancel this pre-order?', WC_Pre_Orders::TEXT_DOMAIN) . "')) {\n\t\t\t\t\t\te.preventDefault();\n\t\t\t\t\t}\n\t\t\t\t});\n\t\t\t"); } elseif ('bottom' == $which) { // Bulk action fields echo '<div id="bulk-action-fields2" style="clear:left;padding-top:10px;display:none;">'; echo '<textarea cols="62" rows="3" name="customer_message2" placeholder="' . __('Optional message to include in the email to the customer', WC_Pre_Orders::TEXT_DOMAIN) . '"></textarea>'; echo '</div>'; } }