public function init_form_fields() { $zakladni = array('enabled' => array('title' => 'Povolit', 'type' => 'checkbox', 'label' => 'Aktivovat a zobrazit v nabídce dostupných možností dopravy.', 'default' => 'no'), 'dpd_parcelshop_nazev' => array('title' => 'Název', 'type' => 'text', 'description' => 'Název pro zobrazení v eshopu.', 'default' => 'DPD ParcelShop', 'css' => 'width: 300px;'), 'dpd_parcelshop_zakladni-cena' => array('title' => 'Základní cena', 'type' => 'price', 'description' => 'Pokud nebude cena vyplněna, tak bude nulová.', 'default' => '', 'css' => 'width: 100px;', 'placeholder' => wc_format_localized_price(0)), 'dpd_parcelshop_dobirka' => array('title' => 'Poplatek za dobírku', 'type' => 'price', 'description' => 'Pro fungování dodatečného poplatku za dobírku je třeba použít plugin <a href="https://wordpress.org/plugins/woocommerce-pay-for-payment/">WooCommerce Pay for Payment</a> a nastavit u něj stejný poplatek za dobírku (menu Pokladna - Hotově při doručení).', 'default' => '', 'css' => 'width: 100px;', 'placeholder' => wc_format_localized_price(0))); $slovensko = array('dpd_parcelshop_zakladni-cena-slovensko' => array('title' => 'Základní cena (Slovensko)', 'type' => 'price', 'description' => 'Pokud nebude cena vyplněna, tak bude nulová.', 'default' => '', 'css' => 'width: 100px;', 'placeholder' => wc_format_localized_price(0)), 'dpd_parcelshop_dobirka-slovensko' => array('title' => 'Poplatek za dobírku (Slovensko)', 'type' => 'price', 'description' => 'Pro fungování dodatečného poplatku za dobírku je třeba použít plugin <a href="https://wordpress.org/plugins/woocommerce-pay-for-payment/">WooCommerce Pay for Payment</a> a nastavit u něj stejný poplatek za dobírku (menu Pokladna - Hotově při doručení).', 'default' => '', 'css' => 'width: 100px;', 'placeholder' => wc_format_localized_price(0))); $zvolene_zeme = WC()->countries->get_shipping_countries(); if (array_key_exists('SK', $zvolene_zeme)) { $this->form_fields = array_merge($zakladni, $slovensko); } else { $this->form_fields = $zakladni; } }
/** * Output a text input box. * * @param array $field */ function woocommerce_wp_text_input($field) { global $thepostid, $post; $thepostid = empty($thepostid) ? $post->ID : $thepostid; $field['placeholder'] = isset($field['placeholder']) ? $field['placeholder'] : ''; $field['class'] = isset($field['class']) ? $field['class'] : 'short'; $field['style'] = isset($field['style']) ? $field['style'] : ''; $field['wrapper_class'] = isset($field['wrapper_class']) ? $field['wrapper_class'] : ''; $field['value'] = isset($field['value']) ? $field['value'] : get_post_meta($thepostid, $field['id'], true); $field['name'] = isset($field['name']) ? $field['name'] : $field['id']; $field['type'] = isset($field['type']) ? $field['type'] : 'text'; $field['desc_tip'] = isset($field['desc_tip']) ? $field['desc_tip'] : false; $data_type = empty($field['data_type']) ? '' : $field['data_type']; switch ($data_type) { case 'price': $field['class'] .= ' wc_input_price'; $field['value'] = wc_format_localized_price($field['value']); break; case 'decimal': $field['class'] .= ' wc_input_decimal'; $field['value'] = wc_format_localized_decimal($field['value']); break; case 'stock': $field['class'] .= ' wc_input_stock'; $field['value'] = wc_stock_amount($field['value']); break; case 'url': $field['class'] .= ' wc_input_url'; $field['value'] = esc_url($field['value']); break; default: break; } // Custom attribute handling $custom_attributes = array(); if (!empty($field['custom_attributes']) && is_array($field['custom_attributes'])) { foreach ($field['custom_attributes'] as $attribute => $value) { $custom_attributes[] = esc_attr($attribute) . '="' . esc_attr($value) . '"'; } } echo '<p class="form-field ' . esc_attr($field['id']) . '_field ' . esc_attr($field['wrapper_class']) . '"> <label for="' . esc_attr($field['id']) . '">' . wp_kses_post($field['label']) . '</label>'; if (!empty($field['description']) && false !== $field['desc_tip']) { echo wc_help_tip($field['description']); } echo '<input type="' . esc_attr($field['type']) . '" class="' . esc_attr($field['class']) . '" style="' . esc_attr($field['style']) . '" name="' . esc_attr($field['name']) . '" id="' . esc_attr($field['id']) . '" value="' . esc_attr($field['value']) . '" placeholder="' . esc_attr($field['placeholder']) . '" ' . implode(' ', $custom_attributes) . ' /> '; if (!empty($field['description']) && false === $field['desc_tip']) { echo '<span class="description">' . wp_kses_post($field['description']) . '</span>'; } echo '</p>'; }
/** * Output a text input box. * * @access public * @param array $field * @return void */ function woocommerce_wp_text_input($field) { global $thepostid, $post, $woocommerce; $thepostid = empty($thepostid) ? $post->ID : $thepostid; $field['placeholder'] = isset($field['placeholder']) ? $field['placeholder'] : ''; $field['class'] = isset($field['class']) ? $field['class'] : 'short'; $field['wrapper_class'] = isset($field['wrapper_class']) ? $field['wrapper_class'] : ''; $field['value'] = isset($field['value']) ? $field['value'] : get_post_meta($thepostid, $field['id'], true); $field['name'] = isset($field['name']) ? $field['name'] : $field['id']; $field['type'] = isset($field['type']) ? $field['type'] : 'text'; $data_type = empty($field['data_type']) ? '' : $field['data_type']; switch ($data_type) { case 'price': $field['class'] .= ' wc_input_price'; $field['value'] = wc_format_localized_price($field['value']); break; case 'decimal': $field['class'] .= ' wc_input_decimal'; $field['value'] = wc_format_localized_decimal($field['value']); break; } // Custom attribute handling $custom_attributes = array(); if (!empty($field['custom_attributes']) && is_array($field['custom_attributes'])) { foreach ($field['custom_attributes'] as $attribute => $value) { $custom_attributes[] = esc_attr($attribute) . '="' . esc_attr($value) . '"'; } } echo '<p class="form-field ' . esc_attr($field['id']) . '_field ' . esc_attr($field['wrapper_class']) . '"><label for="' . esc_attr($field['id']) . '">' . wp_kses_post($field['label']) . '</label><input type="' . esc_attr($field['type']) . '" class="' . esc_attr($field['class']) . '" name="' . esc_attr($field['name']) . '" id="' . esc_attr($field['id']) . '" value="' . esc_attr($field['value']) . '" placeholder="' . esc_attr($field['placeholder']) . '" ' . implode(' ', $custom_attributes) . ' /> '; if (!empty($field['description'])) { if (isset($field['desc_tip']) && false !== $field['desc_tip']) { echo '<img class="help_tip" data-tip="' . esc_attr($field['description']) . '" src="' . esc_url(WC()->plugin_url()) . '/assets/images/help.png" height="16" width="16" />'; } else { echo '<span class="description">' . wp_kses_post($field['description']) . '</span>'; } } echo '</p>'; }
/** * 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 }
/** * init_form_fields function. * * @access public * @return void */ function init_form_fields() { $this->form_fields = array('enabled' => array('title' => __('Enable', 'woocommerce'), 'type' => 'checkbox', 'label' => __('Enable local delivery', 'woocommerce'), 'default' => 'no'), 'title' => array('title' => __('Title', 'woocommerce'), 'type' => 'text', 'description' => __('This controls the title which the user sees during checkout.', 'woocommerce'), 'default' => __('Local Delivery', 'woocommerce'), 'desc_tip' => true), 'type' => array('title' => __('Fee Type', 'woocommerce'), 'type' => 'select', 'description' => __('How to calculate delivery charges', 'woocommerce'), 'default' => 'fixed', 'options' => array('fixed' => __('Fixed amount', 'woocommerce'), 'percent' => __('Percentage of cart total', 'woocommerce'), 'product' => __('Fixed amount per product', 'woocommerce')), 'desc_tip' => true), 'fee' => array('title' => __('Delivery Fee', 'woocommerce'), 'type' => 'price', 'description' => __('What fee do you want to charge for local delivery, disregarded if you choose free. Leave blank to disable.', 'woocommerce'), 'default' => '', 'desc_tip' => true, 'placeholder' => wc_format_localized_price(0)), 'codes' => array('title' => __('Zip/Post Codes', 'woocommerce'), 'type' => 'textarea', 'description' => __('What zip/post codes would you like to offer delivery to? Separate codes with a comma. Accepts wildcards, e.g. P* will match a postcode of PE30.', 'woocommerce'), 'default' => '', 'desc_tip' => true, 'placeholder' => '12345, 56789 etc'), 'availability' => array('title' => __('Method availability', 'woocommerce'), 'type' => 'select', 'default' => 'all', 'class' => 'availability', 'options' => array('all' => __('All allowed countries', 'woocommerce'), 'specific' => __('Specific Countries', 'woocommerce'))), 'countries' => array('title' => __('Specific Countries', 'woocommerce'), 'type' => 'multiselect', 'class' => 'chosen_select', 'css' => 'width: 450px;', 'default' => '', 'options' => WC()->countries->get_shipping_countries(), 'custom_attributes' => array('data-placeholder' => __('Select some countries', 'woocommerce')))); }
<?php if (!defined('ABSPATH')) { exit; } //Campos del formulario $campos = array('activo' => array('title' => __('Enable/Disable', 'apg_free_shipping'), 'type' => 'checkbox', 'label' => __('Enable this shipping method', 'apg_free_shipping'), 'default' => 'yes'), 'title' => array('title' => __('Method Title', 'apg_free_shipping'), 'type' => 'text', 'description' => __('This controls the title which the user sees during checkout.', 'apg_free_shipping'), 'default' => $this->method_title, 'desc_tip' => true), 'requires' => array('title' => __('Free Shipping Requires...', 'apg_free_shipping'), 'type' => 'select', 'class' => 'wc-enhanced-select', 'options' => array('' => __('N/A', 'apg_free_shipping'), 'cupon' => __('A valid free shipping coupon', 'apg_free_shipping'), 'importe_minimo' => __('A minimum order amount (defined below)', 'apg_free_shipping'), 'cualquiera' => __('A minimum order amount OR a coupon', 'apg_free_shipping'), 'ambos' => __('A minimum order amount AND a coupon', 'apg_free_shipping'))), 'importe_minimo' => array('title' => __('Minimum Order Amount', 'apg_free_shipping'), 'type' => 'price', 'description' => __('Users will need to spend this amount to get free shipping (if enabled above).', 'apg_free_shipping'), 'default' => '0', 'desc_tip' => true, 'placeholder' => wc_format_localized_price(0))); if (WC()->shipping->get_shipping_classes()) { $campos['clases_excluidas'] = array('title' => __('No shipping (Shipping class)', 'apg_free_shipping'), 'desc_tip' => sprintf(__("Select the shipping class where %s doesn't accept free shippings.", 'apg_free_shipping'), get_bloginfo('name')), 'css' => 'width: 450px;', 'default' => '', 'type' => 'multiselect', 'class' => 'wc-enhanced-select', 'options' => array('todas' => __('All enabled shipping class', 'apg_free_shipping')) + $this->clases_de_envio); } $campos['muestra'] = array('title' => __('Show only APG Free Shipping', 'apg_free_shipping'), 'type' => 'checkbox', 'label' => __("Don't show others shipping cost.", 'apg_free_shipping'), 'default' => 'no'); return $campos;
/** * Initialise Gateway Settings Form Fields. */ public function init_form_fields() { $this->form_fields = array('enabled' => array('title' => __('Enable/Disable', 'woocommerce'), 'type' => 'checkbox', 'label' => __('Once disabled, this legacy method will no longer be available.', 'woocommerce'), 'default' => 'no'), 'title' => array('title' => __('Method Title', 'woocommerce'), 'type' => 'text', 'description' => __('This controls the title which the user sees during checkout.', 'woocommerce'), 'default' => __('Free Shipping', 'woocommerce'), 'desc_tip' => true), 'availability' => array('title' => __('Method availability', 'woocommerce'), 'type' => 'select', 'default' => 'all', 'class' => 'availability wc-enhanced-select', 'options' => array('all' => __('All allowed countries', 'woocommerce'), 'specific' => __('Specific Countries', 'woocommerce'))), 'countries' => array('title' => __('Specific Countries', 'woocommerce'), 'type' => 'multiselect', 'class' => 'wc-enhanced-select', 'css' => 'width: 450px;', 'default' => '', 'options' => WC()->countries->get_shipping_countries(), 'custom_attributes' => array('data-placeholder' => __('Select some countries', 'woocommerce'))), 'requires' => array('title' => __('Free Shipping Requires...', 'woocommerce'), 'type' => 'select', 'class' => 'wc-enhanced-select', 'default' => '', 'options' => array('' => __('N/A', 'woocommerce'), 'coupon' => __('A valid free shipping coupon', 'woocommerce'), 'min_amount' => __('A minimum order amount (defined below)', 'woocommerce'), 'either' => __('A minimum order amount OR a coupon', 'woocommerce'), 'both' => __('A minimum order amount AND a coupon', 'woocommerce'))), 'min_amount' => array('title' => __('Minimum Order Amount', 'woocommerce'), 'type' => 'price', 'placeholder' => wc_format_localized_price(0), 'description' => __('Users will need to spend this amount to get free shipping (if enabled above).', 'woocommerce'), 'default' => '0', 'desc_tip' => true)); }
/** * Load variations via AJAX */ public static function load_variations() { ob_start(); check_ajax_referer('load-variations', 'security'); // Check permissions again and make sure we have what we need if (!current_user_can('edit_products') || empty($_POST['product_id']) || empty($_POST['attributes'])) { die(-1); } global $post; $product_id = absint($_POST['product_id']); $post = get_post($product_id); // Set $post global so its available like within the admin screens $per_page = !empty($_POST['per_page']) ? absint($_POST['per_page']) : 10; $page = !empty($_POST['page']) ? absint($_POST['page']) : 1; // Get attributes $attributes = array(); foreach ($_POST['attributes'] as $key => $value) { $attributes[wc_clean($key)] = array_map('wc_clean', $value); } // Get tax classes $tax_classes = WC_Tax::get_tax_classes(); $tax_class_options = array(); $tax_class_options[''] = __('Standard', 'woocommerce'); if (!empty($tax_classes)) { foreach ($tax_classes as $class) { $tax_class_options[sanitize_title($class)] = esc_attr($class); } } // Set backorder options $backorder_options = array('no' => __('Do not allow', 'woocommerce'), 'notify' => __('Allow, but notify customer', 'woocommerce'), 'yes' => __('Allow', 'woocommerce')); // set stock status options $stock_status_options = array('instock' => __('In stock', 'woocommerce'), 'outofstock' => __('Out of stock', 'woocommerce')); $parent_data = array('id' => $product_id, 'attributes' => $attributes, 'tax_class_options' => $tax_class_options, 'sku' => get_post_meta($product_id, '_sku', true), 'weight' => wc_format_localized_decimal(get_post_meta($product_id, '_weight', true)), 'length' => wc_format_localized_decimal(get_post_meta($product_id, '_length', true)), 'width' => wc_format_localized_decimal(get_post_meta($product_id, '_width', true)), 'height' => wc_format_localized_decimal(get_post_meta($product_id, '_height', true)), 'tax_class' => get_post_meta($product_id, '_tax_class', true), 'backorder_options' => $backorder_options, 'stock_status_options' => $stock_status_options); if (!$parent_data['weight']) { $parent_data['weight'] = wc_format_localized_decimal(0); } if (!$parent_data['length']) { $parent_data['length'] = wc_format_localized_decimal(0); } if (!$parent_data['width']) { $parent_data['width'] = wc_format_localized_decimal(0); } if (!$parent_data['height']) { $parent_data['height'] = wc_format_localized_decimal(0); } // Get variations $args = array('post_type' => 'product_variation', 'post_status' => array('private', 'publish'), 'posts_per_page' => $per_page, 'paged' => $page, 'orderby' => 'ID', 'order' => 'DESC', 'post_parent' => $product_id); $variations = get_posts($args); $loop = 0; if ($variations) { foreach ($variations as $variation) { $variation_id = absint($variation->ID); $variation_meta = get_post_meta($variation_id); $variation_data = array(); $shipping_classes = get_the_terms($variation_id, 'product_shipping_class'); $variation_fields = array('_sku' => '', '_stock' => '', '_regular_price' => '', '_sale_price' => '', '_weight' => '', '_length' => '', '_width' => '', '_height' => '', '_download_limit' => '', '_download_expiry' => '', '_downloadable_files' => '', '_downloadable' => '', '_virtual' => '', '_thumbnail_id' => '', '_sale_price_dates_from' => '', '_sale_price_dates_to' => '', '_manage_stock' => '', '_stock_status' => '', '_backorders' => null, '_tax_class' => null, '_variation_description' => ''); foreach ($variation_fields as $field => $value) { $variation_data[$field] = isset($variation_meta[$field][0]) ? maybe_unserialize($variation_meta[$field][0]) : $value; } // Add the variation attributes foreach ($variation_meta as $key => $value) { if (0 !== strpos($key, 'attribute_')) { continue; } /** * Pre 2.4 handling where 'slugs' were saved instead of the full text attribute. * Attempt to get full version of the text attribute from the parent. */ if (sanitize_title($value[0]) === $value[0] && version_compare(get_post_meta($product_id, '_product_version', true), '2.4.0', '<')) { foreach ($attributes as $attribute) { if ($key !== 'attribute_' . sanitize_title($attribute['name'])) { continue; } $text_attributes = wc_get_text_attributes($attribute['value']); foreach ($text_attributes as $text_attribute) { if (sanitize_title($text_attribute) === $value[0]) { $value[0] = $text_attribute; } } } } $variation_data[$key] = $value[0]; } // Formatting $variation_data['_regular_price'] = wc_format_localized_price($variation_data['_regular_price']); $variation_data['_sale_price'] = wc_format_localized_price($variation_data['_sale_price']); $variation_data['_weight'] = wc_format_localized_decimal($variation_data['_weight']); $variation_data['_length'] = wc_format_localized_decimal($variation_data['_length']); $variation_data['_width'] = wc_format_localized_decimal($variation_data['_width']); $variation_data['_height'] = wc_format_localized_decimal($variation_data['_height']); $variation_data['_thumbnail_id'] = absint($variation_data['_thumbnail_id']); $variation_data['image'] = $variation_data['_thumbnail_id'] ? wp_get_attachment_thumb_url($variation_data['_thumbnail_id']) : ''; $variation_data['shipping_class'] = $shipping_classes && !is_wp_error($shipping_classes) ? current($shipping_classes)->term_id : ''; // Stock BW compat if ('' !== $variation_data['_stock']) { $variation_data['_manage_stock'] = 'yes'; } include 'admin/meta-boxes/views/html-variation-admin.php'; $loop++; } } die; }
/** * Init form fields. */ public function init_form_fields() { $this->form_fields = array('enabled' => array('title' => __('Enable', 'woocommerce'), 'type' => 'checkbox', 'label' => __('Once disabled, this legacy method will no longer be available.', 'woocommerce'), 'default' => 'no'), 'title' => array('title' => __('Title', 'woocommerce'), 'type' => 'text', 'description' => __('This controls the title which the user sees during checkout.', 'woocommerce'), 'default' => __('Local delivery', 'woocommerce'), 'desc_tip' => true), 'type' => array('title' => __('Fee type', 'woocommerce'), 'type' => 'select', 'class' => 'wc-enhanced-select', 'description' => __('How to calculate delivery charges', 'woocommerce'), 'default' => 'fixed', 'options' => array('fixed' => __('Fixed amount', 'woocommerce'), 'percent' => __('Percentage of cart total', 'woocommerce'), 'product' => __('Fixed amount per product', 'woocommerce')), 'desc_tip' => true), 'fee' => array('title' => __('Delivery fee', 'woocommerce'), 'type' => 'price', 'description' => __('What fee do you want to charge for local delivery, disregarded if you choose free. Leave blank to disable.', 'woocommerce'), 'default' => '', 'desc_tip' => true, 'placeholder' => wc_format_localized_price(0)), 'codes' => array('title' => __('Allowed ZIP/post codes', 'woocommerce'), 'type' => 'text', 'desc_tip' => __('What ZIP/post codes are available for local delivery?', 'woocommerce'), 'default' => '', 'description' => __('Separate codes with a comma. Accepts wildcards, e.g. <code>P*</code> will match a postcode of PE30. Also accepts a pattern, e.g. <code>NG1___</code> would match NG1 1AA but not NG10 1AA', 'woocommerce'), 'placeholder' => 'e.g. 12345, 56789'), 'availability' => array('title' => __('Method availability', 'woocommerce'), 'type' => 'select', 'default' => 'all', 'class' => 'availability wc-enhanced-select', 'options' => array('all' => __('All allowed countries', 'woocommerce'), 'specific' => __('Specific Countries', 'woocommerce'))), 'countries' => array('title' => __('Specific countries', 'woocommerce'), 'type' => 'multiselect', 'class' => 'wc-enhanced-select', 'css' => 'width: 450px;', 'default' => '', 'options' => WC()->countries->get_shipping_countries(), 'custom_attributes' => array('data-placeholder' => __('Select some countries', 'woocommerce')))); }
/** * 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 }
/** * Initialise Gateway Settings Form Fields * * @access public * @return void */ function init_form_fields() { $this->form_fields = array('enabled' => array('title' => __('Enable/Disable', 'woocommerce'), 'type' => 'checkbox', 'label' => __('Enable this shipping method', 'woocommerce'), 'default' => 'no'), 'title' => array('title' => __('Method Title', 'woocommerce'), 'type' => 'text', 'description' => __('This controls the title which the user sees during checkout.', 'woocommerce'), 'default' => __('International Delivery', 'woocommerce'), 'desc_tip' => true), 'availability' => array('title' => __('Availability', 'woocommerce'), 'type' => 'select', 'description' => '', 'default' => 'including', 'options' => array('including' => __('Selected countries', 'woocommerce'), 'excluding' => __('Excluding selected countries', 'woocommerce'))), 'countries' => array('title' => __('Countries', 'woocommerce'), 'type' => 'multiselect', 'class' => 'chosen_select', 'css' => 'width: 450px;', 'default' => '', 'options' => WC()->countries->get_shipping_countries(), 'custom_attributes' => array('data-placeholder' => __('Select some countries', 'woocommerce'))), 'tax_status' => array('title' => __('Tax Status', 'woocommerce'), 'type' => 'select', 'default' => 'taxable', 'options' => array('taxable' => __('Taxable', 'woocommerce'), 'none' => __('None', 'woocommerce'))), 'type' => array('title' => __('Cost Added...', 'woocommerce'), 'type' => 'select', 'default' => 'order', 'options' => array('order' => __('Per Order - charge shipping for the entire order as a whole', 'woocommerce'), 'item' => __('Per Item - charge shipping for each item individually', 'woocommerce'), 'class' => __('Per Class - charge shipping for each shipping class in an order', 'woocommerce'))), 'cost' => array('title' => __('Cost', 'woocommerce'), 'type' => 'price', 'placeholder' => wc_format_localized_price(0), 'description' => __('Cost excluding tax. Enter an amount, e.g. 2.50. Default is 0', 'woocommerce'), 'default' => '', 'desc_tip' => true), 'fee' => array('title' => __('Handling Fee', 'woocommerce'), 'type' => 'text', 'description' => __('Fee excluding tax. Enter an amount, e.g. 2.50, or a percentage, e.g. 5%. Leave blank to disable.', 'woocommerce'), 'default' => '', 'desc_tip' => true, 'placeholder' => wc_format_localized_price(0)), 'minimum_fee' => array('title' => __('Minimum Handling Fee', 'woocommerce'), 'type' => 'decimal', 'description' => __('Enter a minimum fee amount. Fee\'s less than this will be increased. Leave blank to disable.', 'woocommerce'), 'default' => '', 'desc_tip' => true, 'placeholder' => wc_format_localized_decimal('0'))); }
/** * Variable Products meta for WC pre 2.3 */ public static function output_pre($loop, $variation_data) { $variation_id = isset($variation_data['variation_post_id']) ? $variation_data['variation_post_id'] : -1; $delivery_times = get_the_terms($variation_id, 'product_delivery_time'); $delivery_time = $delivery_times && !is_wp_error($delivery_times) ? current($delivery_times)->term_id : ''; ?> <tr> <td> <label><?php _e('Unit', 'woocommerce-germanized'); ?> :</label> <select name="variable_unit[<?php echo $loop; ?> ]"> <option value="parent" <?php selected(is_null(isset($variation_data['_unit'][0]) ? $variation_data['_unit'][0] : null), true); ?> ><?php _e('None', 'woocommerce-germanized'); ?> </option> <?php foreach (WC_germanized()->units->get_units() as $key => $value) { echo '<option value="' . esc_attr($key) . '" ' . selected($key === (isset($variation_data['_unit'][0]) ? $variation_data['_unit'][0] : ''), true, false) . '>' . esc_html($value) . '</option>'; } ?> </select> </td> <td> <label for="variable_unit_base"><?php echo __('Unit Base', 'woocommerce-germanized'); ?> :</label> <input class="input-text wc_input_decimal" size="6" type="text" name="variable_unit_base[<?php echo $loop; ?> ]" value="<?php echo isset($variation_data['_unit_base'][0]) ? esc_attr(wc_format_localized_decimal($variation_data['_unit_base'][0])) : ''; ?> " placeholder="" /> </td> </tr> <tr> <td> <label for="variable_unit_price_regular"><?php echo __('Regular Unit Price', 'woocommerce-germanized') . ' (' . get_woocommerce_currency_symbol() . ')'; ?> :</label> <input class="input-text wc_input_price" size="5" type="text" name="variable_unit_price_regular[<?php echo $loop; ?> ]" value="<?php echo isset($variation_data['_unit_price_regular'][0]) ? esc_attr(wc_format_localized_price($variation_data['_unit_price_regular'][0])) : ''; ?> " placeholder="" /> </td> <td> <label for="variable_unit_price_sale"><?php echo __('Sale Unit Price', 'woocommerce-germanized') . ' (' . get_woocommerce_currency_symbol() . ')'; ?> :</label> <input class="input-text wc_input_price" size="5" type="text" name="variable_unit_price_sale[<?php echo $loop; ?> ]" value="<?php echo isset($variation_data['_unit_price_sale'][0]) ? esc_attr(wc_format_localized_price($variation_data['_unit_price_sale'][0])) : ''; ?> " placeholder="" /> </td> </tr> <tr> <td class="hide_if_variation_virtual"> <label><?php _e('Delivery Time', 'woocommerce-germanized'); ?> :</label> <?php $args = array('taxonomy' => 'product_delivery_time', 'hide_empty' => 0, 'show_option_none' => __('None', 'woocommerce-germanized'), 'name' => 'variable_delivery_time[' . $loop . ']', 'id' => '', 'selected' => isset($delivery_time) ? esc_attr($delivery_time) : '', 'echo' => 0); echo wp_dropdown_categories($args); ?> </td> </tr> <tr> <td colspan="2" class="variable_cart_mini_desc_pre"> <label for="variable_product_mini_desc"><?php echo __('Optional Mini Description', 'woocommerce-germanized'); ?> :</label> <?php wp_editor(htmlspecialchars_decode(isset($variation_data['_mini_desc'][0]) ? $variation_data['_mini_desc'][0] : ''), 'wc_gzd_product_mini_desc_' . $loop, array('textarea_name' => 'variable_product_mini_desc[' . $loop . ']', 'textarea_rows' => 5, 'media_buttons' => false, 'teeny' => true)); ?> </td> </tr> <?php }
/** * Display recurring order totals on the "Edit Order" page. * * @param int $post_id The post ID of the shop_order post object. * @since 1.2.4 * @return void */ public static function recurring_order_totals_meta_box_section($post_id) { global $woocommerce, $wpdb, $current_screen; $order = new WC_Order($post_id); $display_none = ' style="display: none"'; $contains_subscription = self::order_contains_subscription($order) ? true : false; $chosen_gateway = WC_Subscriptions_Payment_Gateways::get_payment_gateway(get_post_meta($post_id, '_recurring_payment_method', true)); $manual_renewal = self::requires_manual_renewal($post_id); $changes_supported = $chosen_gateway === false || $manual_renewal == 'true' || $chosen_gateway->supports('subscription_amount_changes') ? 'true' : 'false'; $data = get_post_meta($post_id); if (WC_Subscriptions::is_woocommerce_pre('2.2')) { ?> <div class="clear"></div> </div> <?php } ?> <div id="gateway_support"<?php if (!$contains_subscription) { echo $display_none; } ?> > <input type="hidden" name="gateway_supports_subscription_changes" value="<?php echo $changes_supported; ?> "> <div class="error"<?php if (!$contains_subscription || $changes_supported == 'true') { echo $display_none; } ?> > <p><?php printf(__('The %s payment gateway is used to charge automatic subscription payments for this order. This gateway <strong>does not</strong> support changing a subscription\'s details.', 'woocommerce-subscriptions'), get_post_meta($post_id, '_recurring_payment_method_title', true)); ?> </p> <p> <?php _e('It is strongly recommended you <strong>do not change</strong> any of the recurring totals or subscription item\'s details.', 'woocommerce-subscriptions'); ?> <a href="http://docs.woothemes.com/document/subscriptions/add-or-modify-a-subscription/#section-4"><?php _e('Learn More', 'woocommerce-subscriptions'); ?> »</a> </p> </div> </div> <div id="recurring_order_totals"<?php if (!$contains_subscription) { echo $display_none; } ?> > <?php if (WC_Subscriptions::is_woocommerce_pre('2.2')) { ?> <h3><?php _e('Recurring Totals', 'woocommerce-subscriptions'); ?> </h3> <?php } ?> <?php if ('add' !== $current_screen->action) { // Can't add recurring shipping to a manually added subscription ?> <div class="totals_group"> <h4><span class="tax_total_display inline_total"></span><?php _e('Shipping for Renewal Orders', 'woocommerce-subscriptions'); ?> </h4> <div id="recurring_shipping_rows"> <?php if (!WC_Subscriptions::is_woocommerce_pre('2.1')) { if ($woocommerce->shipping()) { $shipping_methods = $woocommerce->shipping->load_shipping_methods(); } foreach (self::get_recurring_shipping_methods($order) as $item_id => $item) { $chosen_method = $item['method_id']; $shipping_title = $item['name']; $shipping_cost = $item['cost']; include plugin_dir_path(WC_Subscriptions::$plugin_file) . 'templates/admin/post-types/writepanels/order-shipping-html.php'; } // Shipping created pre 2.1 if (isset($data['_recurring_shipping_method'])) { $item_id = 'old'; // so that when saving, we know to delete the data in the old form $chosen_method = !empty($data['_recurring_shipping_method'][0]) ? $data['_recurring_shipping_method'][0] : ''; $shipping_title = !empty($data['_recurring_shipping_method_title'][0]) ? $data['_recurring_shipping_method_title'][0] : ''; $shipping_cost = !empty($data['_order_recurring_shipping_total'][0]) ? $data['_order_recurring_shipping_total'][0] : '0.00'; include plugin_dir_path(WC_Subscriptions::$plugin_file) . 'templates/admin/post-types/writepanels/order-shipping-html.php'; } ?> <?php } else { // WC < 2.1 ?> <ul class="totals"> <li class="wide"> <label><?php _e('Label:', 'woocommerce-subscriptions'); ?> </label> <input type="text" id="_recurring_shipping_method_title" name="_recurring_shipping_method_title" placeholder="<?php _e('The shipping title for renewal orders', 'woocommerce-subscriptions'); ?> " value="<?php echo $order->recurring_shipping_method_title; ?> " class="first" /> </li> <li class="left"> <label><?php _e('Cost:', 'woocommerce-subscriptions'); ?> </label> <input type="text" id="_order_recurring_shipping_total" name="_order_recurring_shipping_total" placeholder="0.00 <?php _e('(ex. tax)', 'woocommerce-subscriptions'); ?> " value="<?php echo self::get_recurring_shipping_total($order); ?> " class="first" /> </li> <li class="right"> <label><?php _e('Method:', 'woocommerce-subscriptions'); ?> </label> <select name="_recurring_shipping_method" id="_recurring_shipping_method" class="first"> <option value=""><?php _e('N/A', 'woocommerce-subscriptions'); ?> </option> <?php $chosen_shipping_method = $order->recurring_shipping_method; $found_method = false; if ($woocommerce->shipping()) { foreach ($woocommerce->shipping->load_shipping_methods() as $method) { if (strpos($chosen_shipping_method, $method->id) === 0) { $value = $chosen_shipping_method; } else { $value = $method->id; } echo '<option value="' . esc_attr($value) . '" ' . selected($chosen_shipping_method == $value, true, false) . '>' . esc_html($method->get_title()) . '</option>'; if ($chosen_shipping_method == $value) { $found_method = true; } } } if (!$found_method && !empty($chosen_shipping_method)) { echo '<option value="' . esc_attr($chosen_shipping_method) . '" selected="selected">' . __('Other', 'woocommerce-subscriptions') . '</option>'; } else { echo '<option value="other">' . __('Other', 'woocommerce-subscriptions') . '</option>'; } ?> </select> </li> </ul> <?php } // ! WC_Subscriptions::is_woocommerce_pre( '2.1' ) ?> </div> <div class="clear"></div> </div> <?php } ?> <?php if ('yes' == get_option('woocommerce_calc_taxes')) { ?> <div class="totals_group tax_rows_group"> <h4> <span class="tax_total_display inline_total"></span> <?php _e('Recurring Taxes', 'woocommerce-subscriptions'); ?> <a class="tips" data-tip="<?php _e('These rows contain taxes included in each recurring amount for this subscription. This allows you to display multiple or compound taxes rather than a single total on future subscription renewal orders.', 'woocommerce-subscriptions'); ?> " href="#">[?]</a> </h4> <div id="recurring_tax_rows" class="total_rows"> <?php $loop = 0; $taxes = self::get_recurring_taxes($order); if (is_array($taxes) && sizeof($taxes) > 0) { $rates = $wpdb->get_results("SELECT tax_rate_id, tax_rate_country, tax_rate_state, tax_rate_name, tax_rate_priority FROM {$wpdb->prefix}woocommerce_tax_rates ORDER BY tax_rate_name"); $tax_codes = array(); foreach ($rates as $rate) { $code = array(); $code[] = $rate->tax_rate_country; $code[] = $rate->tax_rate_state; $code[] = $rate->tax_rate_name ? sanitize_title($rate->tax_rate_name) : 'TAX'; $code[] = absint($rate->tax_rate_priority); $tax_codes[$rate->tax_rate_id] = strtoupper(implode('-', array_filter($code))); } foreach ($taxes as $item_id => $item) { include plugin_dir_path(WC_Subscriptions::$plugin_file) . 'templates/admin/post-types/writepanels/order-tax-html.php'; $loop++; } } ?> </div> <h4 style="padding-bottom: 10px;"><a href="#" class="add_recurring_tax_row"><?php _e('+ Add tax row', 'woocommerce-subscriptions'); ?> </a></h4> <div class="clear"></div> </div> <?php if (WC_Subscriptions::is_woocommerce_pre('2.1')) { ?> <div class="totals_group"> <h4><span class="tax_total_display inline_total"></span><?php _e('Tax Totals', 'woocommerce-subscriptions'); ?> </h4> <ul class="totals"> <li class="left"> <label><?php _e('Recurring Sales Tax:', 'woocommerce-subscriptions'); ?> </label> <input type="number" step="any" min="0" id="_order_recurring_tax_total" name="_order_recurring_tax_total" placeholder="0.00" value="<?php echo self::get_recurring_total_tax($order); ?> " class="calculated" /> </li> <li class="right"> <label><?php _e('Shipping Tax:', 'woocommerce-subscriptions'); ?> </label> <input type="number" step="any" min="0" id="_order_recurring_shipping_tax_total" name="_order_recurring_shipping_tax_total" placeholder="0.00" value="<?php echo self::get_recurring_shipping_tax_total($order); ?> " class="calculated" /> </li> </ul> <div class="clear"></div> </div> <?php } // WC_Subscriptions::is_woocommerce_pre( '2.1' ) ?> <?php } // woocommerce_calc_taxes ?> <div class="totals_group"> <h4><label for="_order_recurring_discount_total"><?php _e('Recurring Order Discount', 'woocommerce-subscriptions'); ?> <a class="tips" data-tip="<?php _e('The discounts applied to each recurring payment charged in the future.', 'woocommerce-subscriptions'); ?> " href="#">[?]</a></label></h4> <input type="text" class="wc_input_price" id="_order_recurring_discount_total" name="_order_recurring_discount_total" placeholder="<?php echo wc_format_localized_price(0); ?> " value="<?php echo esc_attr(wc_format_localized_price(self::get_recurring_discount_total($order))); ?> " style="margin: 6px 0 10px;"/> </div> <div class="totals_group"> <h4><label for="_order_recurring_total"><?php _e('Recurring Order Total', 'woocommerce-subscriptions'); ?> <a class="tips" data-tip="<?php _e('The total amounts charged for each future recurring payment.', 'woocommerce-subscriptions'); ?> " href="#">[?]</a></label></h4> <input type="text" id="_order_recurring_total" name="_order_recurring_total" placeholder="<?php echo wc_format_localized_price(0); ?> " value="<?php echo esc_attr(wc_format_localized_price(self::get_recurring_total($order))); ?> " class="calculated" style="margin: 6px 0 10px;"/> </div> <div class="totals_group"> <h4><?php _e('Recurring Payment Method:', 'woocommerce-subscriptions'); ?> </h4> <div class="<?php echo $order->recurring_payment_method; ?> " style="padding-top: 4px; font-style: italic; margin: 2px 0 10px;"><?php echo $manual_renewal || empty($order->recurring_payment_method) ? __('Manual', 'woocommerce-subscriptions') : $order->recurring_payment_method_title; ?> </div> </div> <?php if (!WC_Subscriptions::is_woocommerce_pre('2.2')) { ?> </div> <?php } }
$found_method = true; } } if (!$found_method && !empty($chosen_method)) { echo '<option value="' . esc_attr($chosen_method) . '" selected="selected">' . __('Other', 'woocommerce') . '</option>'; } else { echo '<option value="other">' . __('Other', 'woocommerce') . '</option>'; } ?> </optgroup> </select> </p> <p class="last"> <input type="text" class="shipping_cost wc_input_price" name="recurring_shipping_cost[<?php echo $item_id ? $item_id : 'new][]'; ?> ]" placeholder="<?php echo wc_format_localized_price(0); ?> " value="<?php echo esc_attr(wc_format_localized_price($shipping_cost)); ?> " /> </p> <?php do_action('woocommerce_admin_order_totals_after_shipping_item', $item_id); ?> <a href="#" class="delete_total_row">×</a> <div class="clear"></div> </div>
break; case 'no': $inherit_wc_deposit_enabled .= ' (' . esc_html__('no', 'woocommerce-deposits') . ')'; break; } ?> <div id="deposits<?php echo $variation_id ? "[{$loop}]" : ''; ?> " class="panel woocommerce_options_panel woocommerce_deposits_panel"> <div class="options_group"> <?php woocommerce_wp_select(array('id' => '_wc_deposit_enabled' . ($variation_id ? "[{$loop}]" : ''), 'label' => __('Enable Deposits', 'woocommerce-deposits'), 'description' => __('Specify if users can pay a deposit for this product.', 'woocommerce-deposits'), 'options' => array('' => $inherit_wc_deposit_enabled, 'optional' => __('Yes - deposits are optional', 'woocommerce-deposits'), 'forced' => __('Yes - deposits are required', 'woocommerce-deposits'), 'no' => __('No', 'woocommerce-deposits')), 'style' => 'min-width:50%;', 'desc_tip' => true, 'class' => 'select', 'value' => $variation_id ? get_post_meta($variation_id, '_wc_deposit_enabled', true) : null, 'wrapper_class' => $variation_id ? '_wc_deposit_enabled_field' : null)); woocommerce_wp_select(array('id' => '_wc_deposit_type' . ($variation_id ? "[{$loop}]" : ''), 'label' => __('Deposit Type', 'woocommerce-deposits'), 'description' => __('Choose how customers can pay for this product using a deposit.', 'woocommerce-deposits'), 'options' => array('' => $inherit_wc_deposit_type, 'percent' => __('Percentage', 'woocommerce-deposits'), 'fixed' => __('Fixed Amount', 'woocommerce-deposits'), 'plan' => __('Payment Plan', 'woocommerce-deposits')), 'style' => 'min-width:50%;', 'desc_tip' => true, 'class' => 'select', 'value' => $variation_id ? get_post_meta($variation_id, '_wc_deposit_type', true) : null, 'wrapper_class' => $variation_id ? '_wc_deposit_type_field' : null)); woocommerce_wp_checkbox(array('id' => '_wc_deposit_multiple_cost_by_booking_persons' . ($variation_id ? "[{$loop}]" : ''), 'label' => __('Booking Persons', 'woocommerce-deposits'), 'description' => __('Multiply fixed deposits by the number of persons booking', 'woocommerce-deposits'), 'wrapper_class' => 'show_if_booking' . ($variation_id ? ' _wc_deposit_multiple_cost_by_booking_persons_field' : ''), 'cbvalue' => $variation_id ? get_post_meta($variation_id, '_wc_deposit_multiple_cost_by_booking_persons', true) ? 'yes' : 'no' : null)); woocommerce_wp_text_input(array('id' => '_wc_deposit_amount' . ($variation_id ? "[{$loop}]" : ''), 'label' => __('Deposit Amount', 'woocommerce-deposits'), 'placeholder' => wc_format_localized_price(0), 'description' => __('The amount of deposit needed. Do not include currency or percent symbols. You will need to invoice the remainder manually.', 'woocommerce'), 'data_type' => 'price', 'desc_tip' => true, 'value' => $variation_id ? get_post_meta($variation_id, '_wc_deposit_amount', true) : null, 'wrapper_class' => $variation_id ? '_wc_deposit_amount_field' : null)); ?> <input type="hidden" class="_wc_deposits_default_enabled_field" value="<?php echo esc_attr(get_option('wc_deposits_default_enabled', 'no')); ?> " /> <input type="hidden" class="_wc_deposits_default_type_field" value="<?php echo esc_attr(get_option('wc_deposits_default_type', 'percent')); ?> " /> <input type="hidden" class="_wc_deposits_default_plans_field" value="<?php echo esc_attr(implode(',', $default_payment_plans)); ?> " /> <input type="hidden" class="_wc_deposits_default_amount_field" value="<?php
public static function column_display($column_name, $post_id) { switch ($column_name) { case 'price': /* Custom inline data for nyp */ $nyp = get_post_meta($post_id, '_nyp', true); $suggested = WC_Name_Your_Price_Helpers::get_suggested_price($post_id); $suggested = wc_format_localized_price($suggested); $min = WC_Name_Your_Price_Helpers::get_minimum_price($post_id); $min = wc_format_localized_price($min); $is_nyp_allowed = has_term(array('simple'), 'product_type', $post_id) ? 'yes' : 'no'; echo ' <div class="hidden" id="nyp_inline_' . $post_id . '"> <div class="nyp">' . $nyp . '</div> <div class="suggested_price">' . $suggested . '</div> <div class="min_price">' . $min . '</div> <div class="is_nyp_allowed">' . $is_nyp_allowed . '</div> </div> '; break; } }
function woo_ce_get_product_data($product_id = 0, $args = array()) { // Get Product defaults $weight_unit = get_option('woocommerce_weight_unit'); $dimension_unit = get_option('woocommerce_dimension_unit'); $height_unit = $dimension_unit; $width_unit = $dimension_unit; $length_unit = $dimension_unit; $product = get_post($product_id); $_product = function_exists('wc_get_product') ? wc_get_product($product_id) : false; $product->parent_id = ''; $product->parent_sku = ''; if ($product->post_type == 'product_variation') { // Assign Parent ID for Variants then check if Parent exists if ($product->parent_id = $product->post_parent) { $product->parent_sku = get_post_meta($product->post_parent, '_sku', true); } else { $product->parent_id = ''; } } $product->product_id = $product_id; $product->sku = get_post_meta($product_id, '_sku', true); $product->name = get_the_title($product_id); $product->permalink = get_permalink($product_id); $product->product_url = method_exists($_product, 'get_permalink') ? $_product->get_permalink() : get_permalink($product_id); $product->slug = $product->post_name; $product->description = $product->post_content; $product->excerpt = $product->post_excerpt; $product->regular_price = get_post_meta($product_id, '_regular_price', true); // Check that a valid price has been provided and that wc_format_localized_price() exists if (isset($product->regular_price) && $product->regular_price != '' && function_exists('wc_format_localized_price')) { $product->regular_price = wc_format_localized_price($product->regular_price); } $product->price = get_post_meta($product_id, '_price', true); if ($product->regular_price != '' && $product->regular_price != $product->price) { $product->price = $product->regular_price; } // Check that a valid price has been provided and that wc_format_localized_price() exists if (isset($product->price) && $product->price != '' && function_exists('wc_format_localized_price')) { $product->price = wc_format_localized_price($product->price); } $product->sale_price = get_post_meta($product_id, '_sale_price', true); // Check that a valid price has been provided and that wc_format_localized_price() exists if (isset($product->sale_price) && $product->sale_price != '' && function_exists('wc_format_localized_price')) { $product->sale_price = wc_format_localized_price($product->sale_price); } $product->sale_price_dates_from = woo_ce_format_sale_price_dates(get_post_meta($product_id, '_sale_price_dates_from', true)); $product->sale_price_dates_to = woo_ce_format_sale_price_dates(get_post_meta($product_id, '_sale_price_dates_to', true)); $product->post_date = woo_ce_format_date($product->post_date); $product->post_modified = woo_ce_format_date($product->post_modified); $product->type = woo_ce_get_product_assoc_type($product_id); if ($product->post_type == 'product_variation') { $product->type = __('Variation', 'woo_ce'); } $product->visibility = woo_ce_format_visibility(get_post_meta($product_id, '_visibility', true)); $product->featured = woo_ce_format_switch(get_post_meta($product_id, '_featured', true)); $product->virtual = woo_ce_format_switch(get_post_meta($product_id, '_virtual', true)); $product->downloadable = woo_ce_format_switch(get_post_meta($product_id, '_downloadable', true)); $product->weight = get_post_meta($product_id, '_weight', true); $product->weight_unit = $product->weight != '' ? $weight_unit : ''; $product->height = get_post_meta($product_id, '_height', true); $product->height_unit = $product->height != '' ? $height_unit : ''; $product->width = get_post_meta($product_id, '_width', true); $product->width_unit = $product->width != '' ? $width_unit : ''; $product->length = get_post_meta($product_id, '_length', true); $product->length_unit = $product->length != '' ? $length_unit : ''; $product->category = woo_ce_get_product_assoc_categories($product_id, $product->parent_id); $product->tag = woo_ce_get_product_assoc_tags($product_id); $product->manage_stock = woo_ce_format_switch(get_post_meta($product_id, '_manage_stock', true)); $product->allow_backorders = woo_ce_format_switch(get_post_meta($product_id, '_backorders', true)); $product->sold_individually = woo_ce_format_switch(get_post_meta($product_id, '_sold_individually', true)); $product->upsell_ids = woo_ce_get_product_assoc_upsell_ids($product_id); $product->crosssell_ids = woo_ce_get_product_assoc_crosssell_ids($product_id); $product->quantity = get_post_meta($product_id, '_stock', true); $product->stock_status = woo_ce_format_stock_status(get_post_meta($product_id, '_stock_status', true), $product->quantity); $product->image = woo_ce_get_product_assoc_featured_image($product_id); $product->product_gallery = woo_ce_get_product_assoc_product_gallery($product_id); $product->tax_status = woo_ce_format_tax_status(get_post_meta($product_id, '_tax_status', true)); $product->tax_class = woo_ce_format_tax_class(get_post_meta($product_id, '_tax_class', true)); $product->external_url = get_post_meta($product_id, '_product_url', true); $product->button_text = get_post_meta($product_id, '_button_text', true); $product->file_download = woo_ce_get_product_assoc_file_downloads($product_id); $product->download_limit = get_post_meta($product_id, '_download_limit', true); $product->download_expiry = get_post_meta($product_id, '_download_expiry', true); $product->download_type = woo_ce_format_download_type(get_post_meta($product_id, '_download_type', true)); $product->purchase_note = get_post_meta($product_id, '_purchase_note', true); $product->product_status = woo_ce_format_product_status($product->post_status); $product->enable_reviews = woo_ce_format_comment_status($product->comment_status); $product->menu_order = $product->menu_order; // Attributes // Scan for global Attributes first if ($attributes = woo_ce_get_product_attributes()) { if ($product->post_type == 'product_variation') { // We're dealing with a single Variation, strap yourself in. foreach ($attributes as $attribute) { $attribute_value = get_post_meta($product_id, sprintf('attribute_pa_%s', $attribute->attribute_name), true); if (!empty($attribute_value)) { $term_id = term_exists($attribute_value, sprintf('pa_%s', $attribute->attribute_name)); if ($term_id !== 0 && $term_id !== null && !is_wp_error($term_id)) { $term = get_term($term_id['term_id'], sprintf('pa_%s', $attribute->attribute_name)); $attribute_value = $term->name; unset($term); } unset($term_id); } $product->{'attribute_' . $attribute->attribute_name} = $attribute_value; unset($attribute_value); } } else { // Either the Variation Parent or a Simple Product, scan for global and custom Attributes $product->attributes = maybe_unserialize(get_post_meta($product_id, '_product_attributes', true)); if (!empty($product->attributes)) { // Check for taxonomy-based attributes foreach ($attributes as $attribute) { if (isset($product->attributes['pa_' . $attribute->attribute_name])) { $product->{'attribute_' . $attribute->attribute_name} = woo_ce_get_product_assoc_attributes($product_id, $product->attributes['pa_' . $attribute->attribute_name], 'product'); } else { $product->{'attribute_' . $attribute->attribute_name} = woo_ce_get_product_assoc_attributes($product_id, $attribute, 'global'); } } // Check for per-Product attributes (custom) foreach ($product->attributes as $key => $attribute) { if ($attribute['is_taxonomy'] == 0) { if (!isset($product->{'attribute_' . $key})) { $product->{'attribute_' . $key} = $attribute['value']; } } } } } } // Advanced Google Product Feed - http://plugins.leewillis.co.uk/downloads/wp-e-commerce-product-feeds/ if (function_exists('woocommerce_gpf_install')) { $product->gpf_data = get_post_meta($product_id, '_woocommerce_gpf_data', true); $product->gpf_availability = isset($product->gpf_data['availability']) ? woo_ce_format_gpf_availability($product->gpf_data['availability']) : ''; $product->gpf_condition = isset($product->gpf_data['condition']) ? woo_ce_format_gpf_condition($product->gpf_data['condition']) : ''; $product->gpf_brand = isset($product->gpf_data['brand']) ? $product->gpf_data['brand'] : ''; $product->gpf_product_type = isset($product->gpf_data['product_type']) ? $product->gpf_data['product_type'] : ''; $product->gpf_google_product_category = isset($product->gpf_data['google_product_category']) ? $product->gpf_data['google_product_category'] : ''; $product->gpf_gtin = isset($product->gpf_data['gtin']) ? $product->gpf_data['gtin'] : ''; $product->gpf_mpn = isset($product->gpf_data['mpn']) ? $product->gpf_data['mpn'] : ''; $product->gpf_gender = isset($product->gpf_data['gender']) ? $product->gpf_data['gender'] : ''; $product->gpf_age_group = isset($product->gpf_data['age_group']) ? $product->gpf_data['age_group'] : ''; $product->gpf_color = isset($product->gpf_data['color']) ? $product->gpf_data['color'] : ''; $product->gpf_size = isset($product->gpf_data['size']) ? $product->gpf_data['size'] : ''; } // All in One SEO Pack - http://wordpress.org/extend/plugins/all-in-one-seo-pack/ if (function_exists('aioseop_activate')) { $product->aioseop_keywords = get_post_meta($product_id, '_aioseop_keywords', true); $product->aioseop_description = get_post_meta($product_id, '_aioseop_description', true); $product->aioseop_title = get_post_meta($product_id, '_aioseop_title', true); $product->aioseop_titleatr = get_post_meta($product_id, '_aioseop_titleatr', true); $product->aioseop_menulabel = get_post_meta($product_id, '_aioseop_menulabel', true); } // WordPress SEO - http://wordpress.org/plugins/wordpress-seo/ if (function_exists('wpseo_admin_init')) { $product->wpseo_focuskw = get_post_meta($product_id, '_yoast_wpseo_focuskw', true); $product->wpseo_metadesc = get_post_meta($product_id, '_yoast_wpseo_metadesc', true); $product->wpseo_title = get_post_meta($product_id, '_yoast_wpseo_title', true); $product->wpseo_googleplus_description = get_post_meta($product_id, '_yoast_wpseo_google-plus-description', true); $product->wpseo_opengraph_description = get_post_meta($product_id, '_yoast_wpseo_opengraph-description', true); } // Ultimate SEO - http://wordpress.org/plugins/seo-ultimate/ if (function_exists('su_wp_incompat_notice')) { $product->useo_meta_title = get_post_meta($product_id, '_su_title', true); $product->useo_meta_description = get_post_meta($product_id, '_su_description', true); $product->useo_meta_keywords = get_post_meta($product_id, '_su_keywords', true); $product->useo_social_title = get_post_meta($product_id, '_su_og_title', true); $product->useo_social_description = get_post_meta($product_id, '_su_og_description', true); $product->useo_meta_noindex = get_post_meta($product_id, '_su_meta_robots_noindex', true); $product->useo_meta_noautolinks = get_post_meta($product_id, '_su_disable_autolinks', true); } // WooCommerce MSRP Pricing - http://woothemes.com/woocommerce/ if (function_exists('woocommerce_msrp_activate')) { $product->msrp = get_post_meta($product_id, '_msrp_price', true); if ($product->msrp == false && $product->post_type == 'product_variation') { $product->msrp = get_post_meta($product_id, '_msrp', true); } // Check that a valid price has been provided and that wc_format_localized_price() exists if (isset($product->msrp) && $product->msrp != '' && function_exists('wc_format_localized_price')) { $product->msrp = wc_format_localized_price($product->msrp); } } // Allow Plugin/Theme authors to add support for additional Product columns $product = apply_filters('woo_ce_product_item', $product, $product_id); return $product; }
function render_admin_field($field) { ob_start(); $field['placeholder'] = isset($field['placeholder']) ? $field['placeholder'] : ''; $field['value'] = isset($field['value']) ? $field['value'] : get_post_meta($thepostid, $field['id'], true); $field['name'] = isset($field['name']) ? $field['name'] : $field['id']; $field['value_type'] = isset($field['value_type']) ? $field['value_type'] : 'text'; $field['class'] = isset($field['class']) ? $field['class'] : ''; $data_type = empty($field['data_type']) ? '' : $field['data_type']; switch ($data_type) { case 'price': $field['class'] = ' wc_input_price'; $field['value'] = wc_format_localized_price($field['value']); break; case 'decimal': $field['class'] = ' wc_input_decimal'; $field['value'] = wc_format_localized_decimal($field['value']); break; case 'stock': $field['class'] = ' wc_input_stock'; $field['value'] = wc_stock_amount($field['value']); break; case 'url': $field['class'] = ' wc_input_url'; $field['value'] = esc_url($field['value']); break; default: break; } if ($field["location"] != "product_cat_add_form_fields" && $field["location"] != "product_cat_edit_form_fields") { ?> <p class="form-field <?php echo esc_attr($field['name']); ?> _field "> <label for="<?php echo esc_attr($field['name']); ?> "><?php echo wp_kses_post($field['label']); echo isset($field["required"]) && $field["required"] == "yes" ? ' <span>*</span>' : ''; ?> </label> <input type="text" class="wccaf-field <?php echo esc_attr($field['class']); ?> " name="<?php echo esc_attr($field['name']); ?> " id="<?php echo esc_attr($field['name']); ?> " value="<?php echo esc_attr($field['value']); ?> " placeholder="<?php echo esc_attr($field['placeholder']); ?> " wccaf-type="text" wccaf-pattern="mandatory" wccaf-mandatory="<?php echo $field["required"]; ?> " /> <?php if (!empty($field['description'])) { if (isset($field['desc_tip']) && "no" != $field['desc_tip']) { ?> <img class="help_tip" data-tip="<?php echo wp_kses_post($field['description']); ?> " src="<?php echo esc_url(wcff()->info["dir"]); ?> /assets/images/help.png" height="16" width="16" /> <?php } else { ?> <span class="description"><?php echo wp_kses_post($field['description']); ?> </span> <?php } } ?> <span class="wccaf-validation-message wccaf-is-valid-<?php echo $this->valid; ?> "><?php echo $field["message"]; ?> </span> </p> <?php } else { if ($field["location"] == "product_cat_add_form_fields") { ?> <div class="form-field"> <label for="<?php echo esc_attr($field['name']); ?> "><?php echo wp_kses_post($field['label']); echo isset($field["required"]) && $field["required"] == "yes" ? ' <span>*</span>' : ''; ?> </label> <input type="text" class="wccaf-field <?php echo esc_attr($field['class']); ?> " name="<?php echo esc_attr($field['name']); ?> " id="<?php echo esc_attr($field['name']); ?> " value="<?php echo esc_attr($field['value']); ?> " placeholder="<?php echo esc_attr($field['placeholder']); ?> " wccaf-type="text" wccaf-pattern="mandatory" wccaf-mandatory="<?php echo $field["required"]; ?> " /> <p class="description"><?php echo wp_kses_post($field['description']); ?> </p> <span class="wccaf-validation-message wccaf-is-valid-<?php echo $this->valid; ?> "><?php echo $field["message"]; ?> </span> </div> <?php } else { if ($field["location"] == "product_cat_edit_form_fields") { ?> <tr class="form-field"> <th scope="row" valign="top"><label for="<?php echo esc_attr($field['name']); ?> "><?php echo wp_kses_post($field['label']); echo isset($field["required"]) && $field["required"] == "yes" ? ' <span>*</span>' : ''; ?> </label></th> <td> <input type="text" class="wccaf-field <?php echo esc_attr($field['class']); ?> " name="<?php echo esc_attr($field['name']); ?> " id="<?php echo esc_attr($field['name']); ?> " value="<?php echo esc_attr($field['value']); ?> " placeholder="<?php echo esc_attr($field['placeholder']); ?> " wccaf-type="text" wccaf-pattern="mandatory" wccaf-mandatory="<?php echo $field["required"]; ?> " /> <p class="description"><?php echo wp_kses_post($field['description']); ?> </p> <span class="wccaf-validation-message wccaf-is-valid-<?php echo $this->valid; ?> "><?php echo $field["message"]; ?> </span> </td> </tr> <?php } } } return ob_get_clean(); }
private function makeCostString() { $baseCost = $this->fee ? wc_format_localized_price($this->fee) : null; $weightRate = null; if ($cost = $this->weightRate->getCost()) { $weightRate .= wc_format_localized_price($cost); $weightUnit = get_option('woocommerce_weight_unit'); $step = $this->weightRate->getStep(); $weightRate = sprintf(__('%s per %s %s', 'woowbs'), $weightRate, $step ? wc_format_localized_decimal($step) : null, $weightUnit); if ($skip = $this->weightRate->getSkip()) { $weightRate = sprintf(__('%s (from %s %s)', 'woowbs'), $weightRate, $skip, $weightUnit); } } $cost = null; if ($baseCost && $weightRate) { $cost = sprintf(__('%s + %s'), $baseCost, $weightRate); } else { if ($baseCost || $weightRate) { $cost = $baseCost . $weightRate; } else { $cost = __('Free', 'woowbs'); } } return $cost; }
/** * Show the variable product options. * * @access public * @return void */ function dokan_variable_product_type_options() { global $post, $woocommerce; $data = array(); $attributes = maybe_unserialize(get_post_meta($post->ID, '_product_attributes', true)); // See if any are set $variation_attribute_found = false; if ($attributes) { foreach ($attributes as $attribute) { if (isset($attribute['is_variation'])) { $variation_attribute_found = true; break; } } } // Get tax classes $tax_classes = array_filter(array_map('trim', explode("\n", get_option('woocommerce_tax_classes')))); $tax_class_options = array(); $tax_class_options[''] = __('Standard', 'woocommerce'); if ($tax_classes) { foreach ($tax_classes as $class) { $tax_class_options[sanitize_title($class)] = esc_attr($class); } } // var_dump( $attributes, $tax_classes, $tax_class_options ); ?> <div id="variable_product_options" class="wc-metaboxes-wrapper"> <div id="variable_product_options_inner"> <?php if (!$variation_attribute_found) { ?> <div id="message" class="inline woocommerce-message"> <div class="squeezer"> <h4><?php _e('Before adding variations, add and save some attributes on the <strong>Attributes</strong> tab.', 'woocommerce'); ?> </h4> <p class="submit"><a class="button-primary" href="http://docs.woothemes.com/document/product-variations/" target="_blank"><?php _e('Learn more', 'woocommerce'); ?> </a></p> </div> </div> <?php } else { ?> <div class="woocommerce_variations wc-metaboxes"> <?php // Get parent data $parent_data = array('id' => $post->ID, 'attributes' => $attributes, 'tax_class_options' => $tax_class_options, 'sku' => get_post_meta($post->ID, '_sku', true), 'weight' => get_post_meta($post->ID, '_weight', true), 'length' => get_post_meta($post->ID, '_length', true), 'width' => get_post_meta($post->ID, '_width', true), 'height' => get_post_meta($post->ID, '_height', true), 'tax_class' => get_post_meta($post->ID, '_tax_class', true)); if (!$parent_data['weight']) { $parent_data['weight'] = '0.00'; } if (!$parent_data['length']) { $parent_data['length'] = '0'; } if (!$parent_data['width']) { $parent_data['width'] = '0'; } if (!$parent_data['height']) { $parent_data['height'] = '0'; } // Get variations $args = array('post_type' => 'product_variation', 'post_status' => array('private', 'publish'), 'numberposts' => -1, 'orderby' => 'menu_order', 'order' => 'asc', 'post_parent' => $post->ID); $variations = get_posts($args); $loop = 0; // var_dump( $variations ); if ($variations) { foreach ($variations as $variation) { $variation_id = absint($variation->ID); $variation_post_status = esc_attr($variation->post_status); $variation_data = get_post_meta($variation_id); $variation_data['variation_post_id'] = $variation_id; // Grab shipping classes $shipping_classes = get_the_terms($variation_id, 'product_shipping_class'); $shipping_class = $shipping_classes && !is_wp_error($shipping_classes) ? current($shipping_classes)->term_id : ''; $variation_fields = array('_sku', '_stock', '_list_price_mrp', '_regular_price', '_sale_price', '_weight', '_length', '_width', '_height', '_download_limit', '_download_expiry', '_downloadable_files', '_downloadable', '_virtual', '_thumbnail_id', '_sale_price_dates_from', '_sale_price_dates_to'); foreach ($variation_fields as $field) { ${$field} = isset($variation_data[$field][0]) ? maybe_unserialize($variation_data[$field][0]) : ''; } $_tax_class = isset($variation_data['_tax_class'][0]) ? $variation_data['_tax_class'][0] : null; $image_id = absint($_thumbnail_id); $image = $image_id ? wp_get_attachment_thumb_url($image_id) : ''; // Locale formatting $_regular_price = wc_format_localized_price($_regular_price); $_sale_price = wc_format_localized_price($_sale_price); $_weight = wc_format_localized_decimal($_weight); $_length = wc_format_localized_decimal($_length); $_width = wc_format_localized_decimal($_width); $_height = wc_format_localized_decimal($_height); include DOKAN_INC_DIR . '/woo-views/variation-admin-html.php'; $loop++; } } ?> </div> <!-- .woocommerce_variations --> <p class="toolbar"> <button type="button" class="btn btn-sm btn-success button-primary add_variation" <?php disabled($variation_attribute_found, false); ?> ><?php _e('Add Variation', 'woocommerce'); ?> </button> <button type="button" class="btn btn-sm btn-default link_all_variations" <?php disabled($variation_attribute_found, false); ?> ><?php _e('Link all variations', 'woocommerce'); ?> </button> <strong><?php _e('Default selections:', 'woocommerce'); ?> </strong> <?php $default_attributes = maybe_unserialize(get_post_meta($post->ID, '_default_attributes', true)); foreach ($attributes as $attribute) { // Only deal with attributes that are variations if (!$attribute['is_variation']) { continue; } // Get current value for variation (if set) $variation_selected_value = isset($default_attributes[sanitize_title($attribute['name'])]) ? $default_attributes[sanitize_title($attribute['name'])] : ''; // Name will be something like attribute_pa_color echo '<select name="default_attribute_' . sanitize_title($attribute['name']) . '"><option value="">' . __('No default', 'woocommerce') . ' ' . esc_html(wc_attribute_label($attribute['name'])) . '…</option>'; // Get terms for attribute taxonomy or value if its a custom attribute if ($attribute['is_taxonomy']) { $post_terms = wp_get_post_terms($post->ID, $attribute['name']); foreach ($post_terms as $term) { echo '<option ' . selected($variation_selected_value, $term->slug, false) . ' value="' . esc_attr($term->slug) . '">' . apply_filters('woocommerce_variation_option_name', esc_html($term->name)) . '</option>'; } } else { $options = array_map('trim', explode('|', $attribute['value'])); foreach ($options as $option) { echo '<option ' . selected(sanitize_title($variation_selected_value), sanitize_title($option), false) . ' value="' . esc_attr(sanitize_title($option)) . '">' . esc_html(apply_filters('woocommerce_variation_option_name', $option)) . '</option>'; } } echo '</select>'; } ?> </p> <!-- .toolbar --> <?php } ?> </div> </div> <?php /** * Product Type Javascript */ ob_start(); ?> jQuery(function($){ var variation_sortable_options = { items:'.woocommerce_variation', cursor:'move', axis:'y', handle: 'h3', scrollSensitivity:40, forcePlaceholderSize: true, helper: 'clone', opacity: 0.65, placeholder: 'wc-metabox-sortable-placeholder', start:function(event,ui){ ui.item.css('background-color','#f6f6f6'); }, stop:function(event,ui){ ui.item.removeAttr('style'); variation_row_indexes(); } }; // Add a variation jQuery('#variable_product_options').on('click', 'button.add_variation', function(){ jQuery('.woocommerce_variations').block({ message: null, overlayCSS: { background: '#fff url(<?php echo $woocommerce->plugin_url(); ?> /assets/images/ajax-loader.gif) no-repeat center', opacity: 0.6 } }); var loop = jQuery('.woocommerce_variation').size(); var data = { action: 'dokan_add_variation', post_id: <?php echo $post->ID; ?> , loop: loop, security: '<?php echo wp_create_nonce("add-variation"); ?> ' }; jQuery.post('<?php echo admin_url('admin-ajax.php'); ?> ', data, function(response) { jQuery('.woocommerce_variations').append( response ); jQuery(".tips").tooltip(); jQuery('input.variable_is_downloadable, input.variable_is_virtual').change(); jQuery('.woocommerce_variations').unblock(); jQuery('#variable_product_options').trigger('woocommerce_variations_added'); }); return false; }); jQuery('#variable_product_options').on('click', 'button.link_all_variations', function(){ var answer = confirm('<?php echo esc_js(__('Are you sure you want to link all variations? This will create a new variation for each and every possible combination of variation attributes (max 50 per run).', 'woocommerce')); ?> '); if (answer) { jQuery('#variable_product_options').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: 'dokan_link_all_variations', post_id: <?php echo $post->ID; ?> , security: '<?php echo wp_create_nonce("link-variations"); ?> ' }; jQuery.post('<?php echo admin_url('admin-ajax.php'); ?> ', data, function(response) { var count = parseInt( response ); if (count==1) { alert( count + ' <?php echo esc_js(__("variation added", 'dokan')); ?> '); } else if (count==0 || count>1) { alert( count + ' <?php echo esc_js(__("variations added", 'dokan')); ?> '); } else { alert('<?php echo esc_js(__("No variations added", 'dokan')); ?> '); } if (count>0) { var this_page = window.location.toString(); this_page = this_page.replace( 'post-new.php?', 'post.php?post=<?php echo $post->ID; ?> &action=edit&' ); $('#variable_product_options').load( this_page + ' #variable_product_options_inner', function() { $('#variable_product_options').unblock(); jQuery('#variable_product_options').trigger('woocommerce_variations_added'); } ); } else { $('#variable_product_options').unblock(); } }); } return false; }); jQuery('#variable_product_options').on('click', 'button.remove_variation', function(e){ e.preventDefault(); var answer = confirm('<?php echo esc_js(__('Are you sure you want to remove this variation?', 'dokan')); ?> '); if (answer){ var el = jQuery(this).parent().parent(); var variation = jQuery(this).attr('rel'); if (variation>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_remove_variation', variation_id: variation, security: '<?php echo wp_create_nonce("delete-variation"); ?> ' }; 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; }); jQuery('#variable_product_options').on('change', 'input.variable_is_downloadable', function(){ jQuery(this).closest('.woocommerce_variation').find('.show_if_variation_downloadable').hide(); if (jQuery(this).is(':checked')) { jQuery(this).closest('.woocommerce_variation').find('.show_if_variation_downloadable').show(); } }); jQuery('#variable_product_options').on('change', 'input.variable_is_virtual', function(){ jQuery(this).closest('.woocommerce_variation').find('.hide_if_variation_virtual').show(); if (jQuery(this).is(':checked')) { jQuery(this).closest('.woocommerce_variation').find('.hide_if_variation_virtual').hide(); } }); jQuery('input.variable_is_downloadable, input.variable_is_virtual').change(); // Ordering $('#variable_product_options').on( 'woocommerce_variations_added', function() { $('.woocommerce_variations').sortable( variation_sortable_options ); } ); $('.woocommerce_variations').sortable( variation_sortable_options ); function variation_row_indexes() { $('.woocommerce_variations .woocommerce_variation').each(function(index, el){ $('.variation_menu_order', el).val( parseInt( $(el).index('.woocommerce_variations .woocommerce_variation') ) ); }); }; // Uploader var variable_image_frame; var setting_variation_image_id; var setting_variation_image; var wp_media_post_id = wp.media.model.settings.post.id; wp.media.view.settings.post = <?php echo json_encode(array('param' => 'dokan', 'post_id' => $post->ID)); // big juicy hack. ?> ; jQuery('#variable_product_options').on('click', '.upload_image_button', function( event ) { console.log('choose file'); var $button = jQuery( this ); var post_id = $button.attr('rel'); var $parent = $button.closest('.upload_image'); setting_variation_image = $parent; setting_variation_image_id = post_id; event.preventDefault(); if ( $button.is('.remove') ) { setting_variation_image.find( '.upload_image_id' ).val( '' ); setting_variation_image.find( 'img' ).attr( 'src', '<?php echo woocommerce_placeholder_img_src(); ?> ' ); setting_variation_image.find( '.upload_image_button' ).removeClass( 'remove' ); } else { // If the media frame already exists, reopen it. if ( variable_image_frame ) { variable_image_frame.uploader.uploader.param( 'post_id', setting_variation_image_id ); variable_image_frame.open(); return; } else { wp.media.model.settings.post.id = setting_variation_image_id; wp.media.model.settings.type = 'dokan'; } // Create the media frame. variable_image_frame = wp.media.frames.variable_image = wp.media({ // Set the title of the modal. title: '<?php echo esc_js(__('Choose an image', 'woocommerce')); ?> ', button: { text: '<?php echo esc_js(__('Set variation image', 'woocommerce')); ?> ' } }); // When an image is selected, run a callback. variable_image_frame.on( 'select', function() { attachment = variable_image_frame.state().get('selection').first().toJSON(); setting_variation_image.find( '.upload_image_id' ).val( attachment.id ); setting_variation_image.find( '.upload_image_button' ).addClass( 'remove' ); setting_variation_image.find( 'img' ).attr( 'src', attachment.url ); wp.media.model.settings.post.id = wp_media_post_id; }); // Finally, open the modal. variable_image_frame.open(); } }); // Restore ID jQuery('a.add_media').on('click', function() { wp.media.model.settings.post.id = wp_media_post_id; } ); }); <?php $javascript = ob_get_clean(); wc_enqueue_js($javascript); }
/** * Output the metabox */ public static function output() { global $woocommerce, $theorder, $wpdb, $post; if (!is_object($theorder)) { $theorder = new WC_Order($post->ID); } $order = $theorder; $data = get_post_meta($post->ID); ?> <div class="totals_group"> <h4><span class="tax_total_display inline_total"></span><?php _e('Shipping', 'woocommerce'); ?> </h4> <div id="shipping_rows" class="total_rows"> <?php if (WC()->shipping()) { $shipping_methods = WC()->shipping->load_shipping_methods(); } foreach ($order->get_shipping_methods() as $item_id => $item) { $chosen_method = $item['method_id']; $shipping_title = $item['name']; $shipping_cost = $item['cost']; include 'views/html-order-shipping.php'; } // Pre 2.1 if (isset($data['_shipping_method'])) { $item_id = ''; $chosen_method = !empty($data['_shipping_method'][0]) ? $data['_shipping_method'][0] : ''; $shipping_title = !empty($data['_shipping_method_title'][0]) ? $data['_shipping_method_title'][0] : ''; $shipping_cost = !empty($data['_order_shipping'][0]) ? $data['_order_shipping'][0] : ''; include 'views/html-order-shipping.php'; } ?> </div> <h4><a href="#" class="add_total_row" data-row="<?php $item_id = ''; $chosen_method = ''; $shipping_cost = ''; $shipping_title = __('Shipping', 'woocommerce'); ob_start(); include 'views/html-order-shipping.php'; echo esc_attr(ob_get_clean()); ?> "><?php _e('+ Add shipping cost', 'woocommerce'); ?> <span class="tips" data-tip="<?php _e('These are the shipping and handling costs for the order.', 'woocommerce'); ?> ">[?]</span></a></a></h4> <div class="clear"></div> <?php do_action('woocommerce_admin_order_totals_after_shipping', $post->ID); ?> </div> <?php if (get_option('woocommerce_calc_taxes') == 'yes') { ?> <div class="totals_group tax_rows_group"> <h4><span class="tax_total_display inline_total"></span><?php _e('Taxes', 'woocommerce'); ?> </h4> <div id="tax_rows" class="total_rows"> <?php global $wpdb; $rates = $wpdb->get_results("SELECT tax_rate_id, tax_rate_country, tax_rate_state, tax_rate_name, tax_rate_priority FROM {$wpdb->prefix}woocommerce_tax_rates ORDER BY tax_rate_name"); $tax_codes = array(); foreach ($rates as $rate) { $code = array(); $code[] = $rate->tax_rate_country; $code[] = $rate->tax_rate_state; $code[] = $rate->tax_rate_name ? sanitize_title($rate->tax_rate_name) : 'TAX'; $code[] = absint($rate->tax_rate_priority); $tax_codes[$rate->tax_rate_id] = strtoupper(implode('-', array_filter($code))); } foreach ($order->get_taxes() as $item_id => $item) { include 'views/html-order-tax.php'; } ?> </div> <h4><a href="#" class="add_total_row" data-row="<?php $item_id = ''; $item = ''; ob_start(); include 'views/html-order-tax.php'; echo esc_attr(ob_get_clean()); ?> "><?php _e('+ Add tax row', 'woocommerce'); ?> <span class="tips" data-tip="<?php _e('These rows contain taxes for this order. This allows you to display multiple or compound taxes rather than a single total.', 'woocommerce'); ?> ">[?]</span></a></a></h4> <div class="clear"></div> </div> <?php } ?> <div class="totals_group"> <h4><label for="_order_discount"><?php _e('Order Discount', 'woocommerce'); ?> </label></h4> <input type="text" class="wc_input_price" id="_order_discount" name="_order_discount" placeholder="<?php echo wc_format_localized_price(0); ?> " value="<?php if (isset($data['_order_discount'][0])) { echo esc_attr(wc_format_localized_price($data['_order_discount'][0])); } ?> " /> </div> <div class="totals_group"> <h4><label for="_order_total"><?php _e('Order Total', 'woocommerce'); ?> </label></h4> <input type="text" class="wc_input_price" id="_order_total" name="_order_total" placeholder="<?php echo wc_format_localized_price(0); ?> " value="<?php if (isset($data['_order_total'][0])) { echo esc_attr(wc_format_localized_price($data['_order_total'][0])); } ?> " /> </div> <?php $coupons = $order->get_items(array('coupon')); if ($coupons) { ?> <div class="totals_group"> <ul class="wc_coupon_list"><?php foreach ($coupons as $item_id => $item) { $post_id = $wpdb->get_var($wpdb->prepare("SELECT ID FROM {$wpdb->posts} WHERE post_title = %s AND post_type = 'shop_coupon' AND post_status = 'publish' LIMIT 1;", $item['name'])); $link = $post_id ? add_query_arg(array('post' => $post_id, 'action' => 'edit'), admin_url('post.php')) : add_query_arg(array('s' => $item['name'], 'post_status' => 'all', 'post_type' => 'shop_coupon'), admin_url('edit.php')); echo '<li class="tips code" data-tip="' . esc_attr(wc_price($item['discount_amount'])) . '"><a href="' . esc_url($link) . '"><span>' . esc_html($item['name']) . '</span></a></li>'; } ?> </ul> </div> <?php } ?> <p class="buttons"> <?php if (get_option('woocommerce_calc_taxes') == 'yes') { ?> <button type="button" class="button calc_line_taxes"><?php _e('Calculate Tax', 'woocommerce'); ?> </button> <?php } ?> <button type="button" class="button calc_totals button-primary"><?php _e('Calculate Total', 'woocommerce'); ?> </button> </p> <?php }
/** * Init form fields. */ public function init_form_fields() { $this->instance_form_fields = array('title' => array('title' => __('Title', 'woocommerce'), 'type' => 'text', 'description' => __('This controls the title which the user sees during checkout.', 'woocommerce'), 'default' => $this->method_title, 'desc_tip' => true), 'requires' => array('title' => __('Free shipping requires...', 'woocommerce'), 'type' => 'select', 'class' => 'wc-enhanced-select', 'default' => '', 'options' => array('' => __('N/A', 'woocommerce'), 'coupon' => __('A valid free shipping coupon', 'woocommerce'), 'min_amount' => __('A minimum order amount', 'woocommerce'), 'either' => __('A minimum order amount OR a coupon', 'woocommerce'), 'both' => __('A minimum order amount AND a coupon', 'woocommerce'))), 'min_amount' => array('title' => __('Minimum order amount', 'woocommerce'), 'type' => 'price', 'placeholder' => wc_format_localized_price(0), 'description' => __('Users will need to spend this amount to get free shipping (if enabled above).', 'woocommerce'), 'default' => '0', 'desc_tip' => true)); }
/** * Show options for the variable product type */ public static function output_variations() { global $post; $attributes = maybe_unserialize(get_post_meta($post->ID, '_product_attributes', true)); // See if any are set $variation_attribute_found = false; if ($attributes) { foreach ($attributes as $attribute) { if (isset($attribute['is_variation'])) { $variation_attribute_found = true; break; } } } // Get tax classes $tax_classes = WC_Tax::get_tax_classes(); $tax_class_options = array(); $tax_class_options[''] = __('Standard', 'woocommerce'); if ($tax_classes) { foreach ($tax_classes as $class) { $tax_class_options[sanitize_title($class)] = esc_attr($class); } } $backorder_options = array('no' => __('Do not allow', 'woocommerce'), 'notify' => __('Allow, but notify customer', 'woocommerce'), 'yes' => __('Allow', 'woocommerce')); $stock_status_options = array('instock' => __('In stock', 'woocommerce'), 'outofstock' => __('Out of stock', 'woocommerce')); ?> <div id="variable_product_options" class="panel wc-metaboxes-wrapper"><div id="variable_product_options_inner"> <?php if (!$variation_attribute_found) { ?> <div id="message" class="inline woocommerce-message"> <p><?php _e('Before adding variations, add and save some attributes on the <strong>Attributes</strong> tab.', 'woocommerce'); ?> </p> <p class="submit"><a class="button-primary" href="<?php echo esc_url(apply_filters('woocommerce_docs_url', 'http://docs.woothemes.com/document/variable-product/', 'product-variations')); ?> " target="_blank"><?php _e('Learn more', 'woocommerce'); ?> </a></p> </div> <?php } else { ?> <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> <select id="field_to_edit"> <option value=""><?php _e('Choose a field to bulk edit…', 'woocommerce'); ?> </option> <optgroup label="<?php esc_attr_e('Status', 'woocommerce'); ?> "> <option value="toggle_enabled"><?php _e('Toggle "Enabled"', 'woocommerce'); ?> </option> <option value="toggle_downloadable"><?php _e('Toggle "Downloadable"', 'woocommerce'); ?> </option> <option value="toggle_virtual"><?php _e('Toggle "Virtual"', 'woocommerce'); ?> </option> <option value="delete_all"><?php _e('Delete all variations', 'woocommerce'); ?> </option> </optgroup> <optgroup label="<?php esc_attr_e('Pricing', 'woocommerce'); ?> "> <option value="variable_regular_price"><?php _e('Prices', 'woocommerce'); ?> </option> <option value="variable_regular_price_increase"><?php _e('Prices increase by (fixed amount or %)', 'woocommerce'); ?> </option> <option value="variable_regular_price_decrease"><?php _e('Prices decrease by (fixed amount or %)', 'woocommerce'); ?> </option> <option value="variable_sale_price"><?php _e('Sale prices', 'woocommerce'); ?> </option> <option value="variable_sale_price_increase"><?php _e('Sale prices increase by (fixed amount or %)', 'woocommerce'); ?> </option> <option value="variable_sale_price_decrease"><?php _e('Sale prices decrease by (fixed amount or %)', 'woocommerce'); ?> </option> <option value="variable_sale_schedule"><?php _e('Scheduled sale dates', 'woocommerce'); ?> </option> </optgroup> <optgroup label="<?php esc_attr_e('Inventory', 'woocommerce'); ?> "> <option value="toggle_manage_stock"><?php _e('Toggle "Manage stock"', 'woocommerce'); ?> </option> <option value="variable_stock"><?php _e('Stock', 'woocommerce'); ?> </option> </optgroup> <optgroup label="<?php esc_attr_e('Shipping', 'woocommerce'); ?> "> <option value="variable_length"><?php _e('Length', 'woocommerce'); ?> </option> <option value="variable_width"><?php _e('Width', 'woocommerce'); ?> </option> <option value="variable_height"><?php _e('Height', 'woocommerce'); ?> </option> <option value="variable_weight"><?php _e('Weight', 'woocommerce'); ?> </option> </optgroup> <optgroup label="<?php esc_attr_e('Downloadable products', 'woocommerce'); ?> "> <option value="variable_download_limit"><?php _e('Download limit', 'woocommerce'); ?> </option> <option value="variable_download_expiry"><?php _e('Download Expiry', 'woocommerce'); ?> </option> </optgroup> <?php do_action('woocommerce_variable_product_bulk_edit_actions'); ?> </select> <a class="button bulk_edit"><?php _e('Go', 'woocommerce'); ?> </a> </p> <div class="woocommerce_variations wc-metaboxes"> <?php // Get parent data $parent_data = array('id' => $post->ID, 'attributes' => $attributes, 'tax_class_options' => $tax_class_options, 'sku' => get_post_meta($post->ID, '_sku', true), 'weight' => wc_format_localized_decimal(get_post_meta($post->ID, '_weight', true)), 'length' => wc_format_localized_decimal(get_post_meta($post->ID, '_length', true)), 'width' => wc_format_localized_decimal(get_post_meta($post->ID, '_width', true)), 'height' => wc_format_localized_decimal(get_post_meta($post->ID, '_height', true)), 'tax_class' => get_post_meta($post->ID, '_tax_class', true), 'backorder_options' => $backorder_options, 'stock_status_options' => $stock_status_options); if (!$parent_data['weight']) { $parent_data['weight'] = wc_format_localized_decimal(0); } if (!$parent_data['length']) { $parent_data['length'] = wc_format_localized_decimal(0); } if (!$parent_data['width']) { $parent_data['width'] = wc_format_localized_decimal(0); } if (!$parent_data['height']) { $parent_data['height'] = wc_format_localized_decimal(0); } // Get variations $args = array('post_type' => 'product_variation', 'post_status' => array('private', 'publish'), 'numberposts' => -1, 'orderby' => 'menu_order', 'order' => 'asc', 'post_parent' => $post->ID); $variations = get_posts($args); $loop = 0; if ($variations) { foreach ($variations as $variation) { $variation_id = absint($variation->ID); $variation_meta = get_post_meta($variation_id); $variation_data = array(); $shipping_classes = get_the_terms($variation_id, 'product_shipping_class'); $variation_fields = array('_sku' => '', '_stock' => '', '_regular_price' => '', '_sale_price' => '', '_weight' => '', '_length' => '', '_width' => '', '_height' => '', '_download_limit' => '', '_download_expiry' => '', '_downloadable_files' => '', '_downloadable' => '', '_virtual' => '', '_thumbnail_id' => '', '_sale_price_dates_from' => '', '_sale_price_dates_to' => '', '_manage_stock' => '', '_stock_status' => '', '_backorders' => null, '_tax_class' => null); foreach ($variation_fields as $field => $value) { $variation_data[$field] = isset($variation_meta[$field][0]) ? maybe_unserialize($variation_meta[$field][0]) : $value; } // Add the variation attributes foreach ($variation_meta as $key => $value) { if (false !== strpos($key, 'attribute_')) { $variation_data[$key] = $value; } } // Formatting $variation_data['_regular_price'] = wc_format_localized_price($variation_data['_regular_price']); $variation_data['_sale_price'] = wc_format_localized_price($variation_data['_sale_price']); $variation_data['_weight'] = wc_format_localized_decimal($variation_data['_weight']); $variation_data['_length'] = wc_format_localized_decimal($variation_data['_length']); $variation_data['_width'] = wc_format_localized_decimal($variation_data['_width']); $variation_data['_height'] = wc_format_localized_decimal($variation_data['_height']); $variation_data['_thumbnail_id'] = absint($variation_data['_thumbnail_id']); $variation_data['image'] = $variation_data['_thumbnail_id'] ? wp_get_attachment_thumb_url($variation_data['_thumbnail_id']) : ''; $variation_data['shipping_class'] = $shipping_classes && !is_wp_error($shipping_classes) ? current($shipping_classes)->term_id : ''; // Stock BW compat if ('' !== $variation_data['_stock']) { $variation_data['_manage_stock'] = 'yes'; } include 'views/html-variation-admin.php'; $loop++; } } ?> </div> <p class="toolbar"> <button type="button" class="button button-primary add_variation" <?php disabled($variation_attribute_found, false); ?> ><?php _e('Add Variation', 'woocommerce'); ?> </button> <button type="button" class="button link_all_variations" <?php disabled($variation_attribute_found, false); ?> ><?php _e('Link all variations', 'woocommerce'); ?> </button> <strong><?php _e('Defaults', 'woocommerce'); ?> : <span class="tips" data-tip="<?php _e('These are the attributes that will be pre-selected on the frontend.', 'woocommerce'); ?> ">[?]</span></strong> <?php $default_attributes = maybe_unserialize(get_post_meta($post->ID, '_default_attributes', true)); foreach ($attributes as $attribute) { // Only deal with attributes that are variations if (!$attribute['is_variation']) { continue; } // Get current value for variation (if set) $variation_selected_value = isset($default_attributes[sanitize_title($attribute['name'])]) ? $default_attributes[sanitize_title($attribute['name'])] : ''; // Name will be something like attribute_pa_color echo '<select name="default_attribute_' . sanitize_title($attribute['name']) . '"><option value="">' . __('No default', 'woocommerce') . ' ' . esc_html(wc_attribute_label($attribute['name'])) . '…</option>'; // Get terms for attribute taxonomy or value if its a custom attribute if ($attribute['is_taxonomy']) { $post_terms = wp_get_post_terms($post->ID, $attribute['name']); foreach ($post_terms as $term) { echo '<option ' . selected($variation_selected_value, $term->slug, false) . ' value="' . esc_attr($term->slug) . '">' . apply_filters('woocommerce_variation_option_name', esc_html($term->name)) . '</option>'; } } else { $options = array_map('trim', explode(WC_DELIMITER, $attribute['value'])); foreach ($options as $option) { echo '<option ' . selected(sanitize_title($variation_selected_value), sanitize_title($option), false) . ' value="' . esc_attr(sanitize_title($option)) . '">' . esc_html(apply_filters('woocommerce_variation_option_name', $option)) . '</option>'; } } echo '</select>'; } ?> </p> <?php } ?> </div></div> <?php }
/** * Test wc_format_localized_price(). * * @since 2.2 */ public function test_wc_format_localized_price() { // save default $decimal_sep = get_option('woocommerce_price_decimal_sep'); update_option('woocommerce_price_decimal_sep', ','); $this->assertEquals('1,17', wc_format_localized_price('1.17')); // restore default update_option('woocommerce_price_decimal_sep', $decimal_sep); }
/** * Calc line tax */ public function calc_line_taxes() { global $wpdb; check_ajax_referer('calc-totals', 'security'); $this->json_headers(); $tax = new WC_Tax(); $taxes = $tax_rows = $item_taxes = $shipping_taxes = array(); $order_id = absint($_POST['order_id']); $order = new WC_Order($order_id); $country = strtoupper(esc_attr($_POST['country'])); $state = strtoupper(esc_attr($_POST['state'])); $postcode = strtoupper(esc_attr($_POST['postcode'])); $city = sanitize_title(esc_attr($_POST['city'])); $items = isset($_POST['items']) ? $_POST['items'] : array(); $shipping = $_POST['shipping']; $item_tax = 0; // Calculate sales tax first if (sizeof($items) > 0) { foreach ($items as $item_id => $item) { $item_id = absint($item_id); $line_subtotal = isset($item['line_subtotal']) ? wc_format_decimal($item['line_subtotal']) : 0; $line_total = wc_format_decimal($item['line_total']); $tax_class = sanitize_text_field($item['tax_class']); $product_id = $order->get_item_meta($item_id, '_product_id', true); if (!$item_id || '0' == $tax_class) { continue; } // Get product details if (get_post_type($product_id) == 'product') { $_product = get_product($product_id); $item_tax_status = $_product->get_tax_status(); } else { $item_tax_status = 'taxable'; } // Only calc if taxable if ('taxable' == $item_tax_status) { $tax_rates = $tax->find_rates(array('country' => $country, 'state' => $state, 'postcode' => $postcode, 'city' => $city, 'tax_class' => $tax_class)); $line_subtotal_taxes = $tax->calc_tax($line_subtotal, $tax_rates, false); $line_taxes = $tax->calc_tax($line_total, $tax_rates, false); $line_subtotal_tax = array_sum($line_subtotal_taxes); $line_tax = array_sum($line_taxes); if ($line_subtotal_tax < 0) { $line_subtotal_tax = 0; } if ($line_tax < 0) { $line_tax = 0; } $item_taxes[$item_id] = array('line_subtotal_tax' => wc_format_localized_price($line_subtotal_tax), 'line_tax' => wc_format_localized_price($line_tax)); $item_tax += $line_tax; // Sum the item taxes foreach (array_keys($taxes + $line_taxes) as $key) { $taxes[$key] = (isset($line_taxes[$key]) ? $line_taxes[$key] : 0) + (isset($taxes[$key]) ? $taxes[$key] : 0); } } } } // Now calculate shipping tax $matched_tax_rates = array(); $tax_rates = $tax->find_rates(array('country' => $country, 'state' => $state, 'postcode' => $postcode, 'city' => $city, 'tax_class' => '')); if ($tax_rates) { foreach ($tax_rates as $key => $rate) { if (isset($rate['shipping']) && 'yes' == $rate['shipping']) { $matched_tax_rates[$key] = $rate; } } } $shipping_taxes = $tax->calc_shipping_tax($shipping, $matched_tax_rates); $shipping_tax = $tax->round(array_sum($shipping_taxes)); // Remove old tax rows $wpdb->query($wpdb->prepare("DELETE FROM {$wpdb->prefix}woocommerce_order_itemmeta WHERE order_item_id IN ( SELECT order_item_id FROM {$wpdb->prefix}woocommerce_order_items WHERE order_id = %d AND order_item_type = 'tax' )", $order_id)); $wpdb->query($wpdb->prepare("DELETE FROM {$wpdb->prefix}woocommerce_order_items WHERE order_id = %d AND order_item_type = 'tax'", $order_id)); // Get tax rates $rates = $wpdb->get_results("SELECT tax_rate_id, tax_rate_country, tax_rate_state, tax_rate_name, tax_rate_priority FROM {$wpdb->prefix}woocommerce_tax_rates ORDER BY tax_rate_name"); $tax_codes = array(); foreach ($rates as $rate) { $code = array(); $code[] = $rate->tax_rate_country; $code[] = $rate->tax_rate_state; $code[] = $rate->tax_rate_name ? sanitize_title($rate->tax_rate_name) : 'TAX'; $code[] = absint($rate->tax_rate_priority); $tax_codes[$rate->tax_rate_id] = strtoupper(implode('-', array_filter($code))); } // Now merge to keep tax rows ob_start(); foreach (array_keys($taxes + $shipping_taxes) as $key) { $item = array(); $item['rate_id'] = $key; $item['name'] = $tax_codes[$key]; $item['label'] = $tax->get_rate_label($key); $item['compound'] = $tax->is_compound($key) ? 1 : 0; $item['tax_amount'] = wc_format_decimal(isset($taxes[$key]) ? $taxes[$key] : 0); $item['shipping_tax_amount'] = wc_format_decimal(isset($shipping_taxes[$key]) ? $shipping_taxes[$key] : 0); if (!$item['label']) { $item['label'] = WC()->countries->tax_or_vat(); } // Add line item $item_id = wc_add_order_item($order_id, array('order_item_name' => $item['name'], 'order_item_type' => 'tax')); // Add line item meta if ($item_id) { wc_add_order_item_meta($item_id, 'rate_id', $item['rate_id']); wc_add_order_item_meta($item_id, 'label', $item['label']); wc_add_order_item_meta($item_id, 'compound', $item['compound']); wc_add_order_item_meta($item_id, 'tax_amount', $item['tax_amount']); wc_add_order_item_meta($item_id, 'shipping_tax_amount', $item['shipping_tax_amount']); } include 'admin/post-types/meta-boxes/views/html-order-tax.php'; } $tax_row_html = ob_get_clean(); // Return echo json_encode(array('item_tax' => $item_tax, 'item_taxes' => $item_taxes, 'shipping_tax' => $shipping_tax, 'tax_row_html' => $tax_row_html)); // Quit out die; }
echo esc_attr(wc_format_localized_price(0)); ?> " value="<?php if (isset($item['tax_amount'])) { echo esc_attr(wc_format_localized_price($item['tax_amount'])); } ?> " /> </p> <p class="last"> <label><?php esc_html_e('Shipping Tax:', 'woocommerce-subscriptions'); ?> </label> <input type="text" class="order_taxes_shipping_amount wc_input_price" name="recurring_order_taxes_shipping_amount[<?php echo esc_attr($item_id); ?> ]" placeholder="<?php echo esc_attr(wc_format_localized_price(0)); ?> " value="<?php if (isset($item['shipping_tax_amount'])) { echo esc_attr(wc_format_localized_price($item['shipping_tax_amount'])); } ?> " /> </p> <a href="#" class="delete_recurring_tax_row">×</a> <div class="clear"></div> </div>
<tr> <td class="label"><?php _e('Order Total', 'woocommerce'); ?> :</td> <td class="total"> <div class="view"><?php echo $order->get_formatted_order_total(); ?> </div> <div class="edit" style="display: none;"> <input type="text" class="wc_input_price" id="_order_total" name="_order_total" placeholder="<?php echo wc_format_localized_price(0); ?> " value="<?php echo isset($data['_order_total'][0]) ? esc_attr(wc_format_localized_price($data['_order_total'][0])) : ''; ?> " /> <div class="clear"></div> </div> </td> <td> <?php if ($order->is_editable()) { ?> <div class="wc-order-edit-line-item-actions"> <a class="edit-order-item" href="#"></a> </div> <?php } ?>
/** * Generate Price Input HTML. * * @param mixed $key * @param mixed $data * @since 1.0.0 * @return string */ public function generate_price_html($key, $data) { $field = $this->get_field_key($key); $defaults = array('title' => '', 'disabled' => false, 'class' => '', 'css' => '', 'placeholder' => '', 'type' => 'text', 'desc_tip' => false, 'description' => '', 'custom_attributes' => array()); $data = wp_parse_args($data, $defaults); ob_start(); ?> <tr valign="top"> <th scope="row" class="titledesc"> <label for="<?php echo esc_attr($field); ?> "><?php echo wp_kses_post($data['title']); ?> </label> <?php echo $this->get_tooltip_html($data); ?> </th> <td class="forminp"> <fieldset> <legend class="screen-reader-text"><span><?php echo wp_kses_post($data['title']); ?> </span></legend> <input class="wc_input_price input-text regular-input <?php echo esc_attr($data['class']); ?> " type="text" name="<?php echo esc_attr($field); ?> " id="<?php echo esc_attr($field); ?> " style="<?php echo esc_attr($data['css']); ?> " value="<?php echo esc_attr(wc_format_localized_price($this->get_option($key))); ?> " placeholder="<?php echo esc_attr($data['placeholder']); ?> " <?php disabled($data['disabled'], true); ?> <?php echo $this->get_custom_attribute_html($data); ?> /> <?php echo $this->get_description_html($data); ?> </fieldset> </td> </tr> <?php return ob_get_clean(); }
?> "data-subtotal_tax="<?php echo $item_subtotal_tax; ?> " /> </div> </div> <div class="refund" style="display: none;"> <input type="text" name="refund_line_tax[<?php echo absint($item_id); ?> ][<?php echo absint($tax_item_id); ?> ]" placeholder="<?php echo wc_format_localized_price(0); ?> " class="refund_line_tax wc_input_price" data-tax_id="<?php echo absint($tax_item_id); ?> " /> </div> </td> <?php } } ?> <td class="wc-order-edit-line-item"> <?php if ($order->is_editable()) {
/** * Get setting form fields for instances of this shipping method within zones. * @return array */ public function get_instance_form_fields() { return array('title' => array('title' => __('Title', 'woocommerce'), 'type' => 'text', 'description' => __('This controls the title which the user sees during checkout.', 'woocommerce'), 'default' => $this->method_title, 'desc_tip' => true), 'requires' => array('title' => __('Free Shipping Requires...', 'woocommerce'), 'type' => 'select', 'class' => 'wc-enhanced-select', 'default' => '', 'options' => array('' => __('N/A', 'woocommerce'), 'coupon' => __('A valid free shipping coupon', 'woocommerce'), 'min_amount' => __('A minimum order amount', 'woocommerce'), 'either' => __('A minimum order amount OR a coupon', 'woocommerce'), 'both' => __('A minimum order amount AND a coupon', 'woocommerce'))), 'min_amount' => array('title' => __('Minimum Order Amount', 'woocommerce'), 'type' => 'price', 'placeholder' => wc_format_localized_price(0), 'description' => __('Users will need to spend this amount to get free shipping (if enabled above).', 'woocommerce'), 'default' => '0', 'desc_tip' => true)); wc_enqueue_js("\n\t\t\tjQuery( function( \$ ) {\n\t\t\t\t\$('#woocommerce_free_shipping_requires').change(function(){\n\t\t\t\t\tif ( \$(this).val() === 'coupon' || \$(this).val() === '' ) {\n\t\t\t\t\t\t\$('#woocommerce_free_shipping_min_amount').closest('tr').hide();\n\t\t\t\t\t} else {\n\t\t\t\t\t\t\$('#woocommerce_free_shipping_min_amount').closest('tr').show();\n\t\t\t\t\t}\n\t\t\t\t}).change();\n\t\t\t});\n\t\t"); }