@@ -4,37 +4,37 @@ discard block |
||
| 4 | 4 | */ |
| 5 | 5 | class wps_product_variation_interface |
| 6 | 6 | { |
| 7 | - /** |
|
| 8 | - * Array of variations. |
|
| 9 | - * |
|
| 10 | - * @var array |
|
| 11 | - */ |
|
| 12 | - private $variations = null; |
|
| 13 | - /** |
|
| 14 | - * Call hooks. |
|
| 15 | - */ |
|
| 16 | - public function __construct() |
|
| 17 | - { |
|
| 7 | + /** |
|
| 8 | + * Array of variations. |
|
| 9 | + * |
|
| 10 | + * @var array |
|
| 11 | + */ |
|
| 12 | + private $variations = null; |
|
| 13 | + /** |
|
| 14 | + * Call hooks. |
|
| 15 | + */ |
|
| 16 | + public function __construct() |
|
| 17 | + { |
|
| 18 | 18 | add_action('init', array($this, 'init')); |
| 19 | - add_action('add_meta_boxes', array($this, 'add_meta_boxes'), 11, 2); |
|
| 20 | - add_action('save_post', array($this, 'save_post'), 10, 2); |
|
| 21 | - add_filter('wpshop_attribute_output_def', array($this, 'wpshop_attribute_output_def'), 10, 2); |
|
| 22 | - } |
|
| 23 | - /** |
|
| 24 | - * Call private functions if class is activate. |
|
| 25 | - * |
|
| 26 | - * @param string $name Name of function to call. |
|
| 27 | - * @param array $arguments Array of arguments to pass. |
|
| 28 | - * @return mixed Return of real function called. |
|
| 29 | - */ |
|
| 30 | - public function __call($name, $arguments) |
|
| 31 | - { |
|
| 32 | - if (method_exists($this, $name)) { |
|
| 33 | - if ($this->is_activate()) { |
|
| 34 | - return call_user_func_array(array($this, $name), $arguments); |
|
| 35 | - } |
|
| 36 | - } |
|
| 37 | - } |
|
| 19 | + add_action('add_meta_boxes', array($this, 'add_meta_boxes'), 11, 2); |
|
| 20 | + add_action('save_post', array($this, 'save_post'), 10, 2); |
|
| 21 | + add_filter('wpshop_attribute_output_def', array($this, 'wpshop_attribute_output_def'), 10, 2); |
|
| 22 | + } |
|
| 23 | + /** |
|
| 24 | + * Call private functions if class is activate. |
|
| 25 | + * |
|
| 26 | + * @param string $name Name of function to call. |
|
| 27 | + * @param array $arguments Array of arguments to pass. |
|
| 28 | + * @return mixed Return of real function called. |
|
| 29 | + */ |
|
| 30 | + public function __call($name, $arguments) |
|
| 31 | + { |
|
| 32 | + if (method_exists($this, $name)) { |
|
| 33 | + if ($this->is_activate()) { |
|
| 34 | + return call_user_func_array(array($this, $name), $arguments); |
|
| 35 | + } |
|
| 36 | + } |
|
| 37 | + } |
|
| 38 | 38 | public function init() { |
| 39 | 39 | $_wpnonce = !empty($_REQUEST['_wpnonce']) ? sanitize_text_field(wp_unslash($_REQUEST['_wpnonce'])) : ''; // Input var okay. |
| 40 | 40 | $wps_variation_interface = !empty($_GET['wps_variation_interface']) ? filter_var(wp_unslash($_GET['wps_variation_interface']), FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE) : null; // Input var okay. |
@@ -42,141 +42,141 @@ discard block |
||
| 42 | 42 | $this->is_activate($wps_variation_interface); |
| 43 | 43 | } |
| 44 | 44 | } |
| 45 | - /** |
|
| 46 | - * Get if module is active. |
|
| 47 | - * |
|
| 48 | - * @param boolean $new_val If set & db is different, save it. |
|
| 49 | - * @return boolean Actual state of module. |
|
| 50 | - */ |
|
| 51 | - public function is_activate($new_val = null) |
|
| 52 | - { |
|
| 53 | - if (!isset($this->is_active)) { |
|
| 54 | - $option = get_option('wps_variation_interface_display', null); |
|
| 55 | - if (is_null($option)) { |
|
| 56 | - $new_val = true; |
|
| 57 | - $option = false; |
|
| 58 | - } |
|
| 59 | - $this->is_active = (bool) $option; |
|
| 60 | - } |
|
| 61 | - if (isset($new_val) && $this->is_active !== $new_val) { |
|
| 62 | - update_option('wps_variation_interface_display', $new_val); |
|
| 63 | - $this->is_active = $new_val; |
|
| 64 | - } |
|
| 65 | - return $this->is_active; |
|
| 66 | - } |
|
| 67 | - /** |
|
| 68 | - * Get variations of an element. |
|
| 69 | - * |
|
| 70 | - * @param array $element Direct array attribute of db. |
|
| 71 | - * @return void It set directly in variable class. |
|
| 72 | - */ |
|
| 73 | - private function get_variations($element) |
|
| 74 | - { |
|
| 75 | - if (!isset($this->variations)) { |
|
| 76 | - $variations = wpshop_attributes::get_variation_available_attribute($element); |
|
| 77 | - $this->variations = (array) array_merge((isset($variations['available']) ? $variations['available'] : array()), (isset($variations['unavailable']) ? $variations['unavailable'] : array())); |
|
| 78 | - unset($variations); |
|
| 79 | - } |
|
| 80 | - } |
|
| 81 | - public function add_meta_boxes($post_status, $post) |
|
| 82 | - { |
|
| 83 | - global $pagenow; |
|
| 84 | - if ($this->is_activate()) { |
|
| 85 | - $this->get_variations($post->ID); |
|
| 86 | - remove_meta_box('wpshop_wpshop_variations', WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT, 'normal'); |
|
| 87 | - if ($pagenow !== 'post-new.php' && !empty($this->variations)) { |
|
| 88 | - add_meta_box('wpshop_wpshop_variations', __('Product variation', 'wpshop'), array($this, 'meta_box_variation'), WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT, 'normal', 'default'); |
|
| 89 | - } |
|
| 90 | - } |
|
| 91 | - } |
|
| 92 | - /** |
|
| 93 | - * The metabox. |
|
| 94 | - * |
|
| 95 | - * @param object $post Given by WordPress. |
|
| 96 | - * @return void Display directly. |
|
| 97 | - */ |
|
| 98 | - private function meta_box_variation($post) |
|
| 99 | - { |
|
| 100 | - $this->get_variations($post->ID); |
|
| 101 | - global $wpdb; |
|
| 102 | - $ids = array(); |
|
| 103 | - foreach ($this->variations as $key => $variation) { |
|
| 104 | - $available = wpshop_attributes::get_select_output($variation['attribute_complete_def']); |
|
| 105 | - $this->variations[$key]['available'] = array_keys($available['possible_value']); |
|
| 106 | - $ids = array_merge($ids, array_keys($available['possible_value'])); |
|
| 107 | - } |
|
| 108 | - $query = $wpdb->prepare('SELECT * FROM ' . WPSHOP_DBT_ATTRIBUTE_VALUES_OPTIONS . " WHERE id IN ('" . implode("', '", $ids) . "') AND status = %s", 'valid'); |
|
| 109 | - $product = wpshop_products::get_product_data($post->ID, false, '"publish","draft","future"'); |
|
| 110 | - $is_used_in_variation = wpshop_attributes::getElement('yes', "'valid', 'notused'", 'is_used_in_variation', true); |
|
| 111 | - $attribute_list = array(); |
|
| 112 | - foreach ($is_used_in_variation as $attribute) { |
|
| 113 | - if (in_array($attribute->backend_input, array('multiple-select', 'select', 'radio', 'checkbox'), true)) { |
|
| 114 | - $values = wpshop_attributes::get_select_output($attribute); |
|
| 115 | - if (!empty($values['possible_value'])) { |
|
| 116 | - $attribute->possible_value = $values['possible_value']; |
|
| 117 | - } |
|
| 118 | - } |
|
| 119 | - $attribute_list[$attribute->code] = $attribute; |
|
| 120 | - } |
|
| 121 | - $variation_defining = get_post_meta($post->ID, '_wpshop_variation_defining', true); |
|
| 122 | - $variations_saved = wpshop_products::get_variation($post->ID); |
|
| 123 | - if (!empty($variations_saved)) { |
|
| 124 | - foreach ($variations_saved as $variation_id => $variation) { |
|
| 125 | - $downloadable = get_post_meta($variation_id, 'attribute_option_is_downloadable_', true); |
|
| 126 | - if (!empty($downloadable['file_url'])) { |
|
| 127 | - $variations_saved[$variation_id]['file']['path'] = $downloadable['file_url']; |
|
| 128 | - $variations_saved[$variation_id]['file']['name'] = basename($downloadable['file_url']); |
|
| 129 | - } |
|
| 130 | - } |
|
| 131 | - } |
|
| 132 | - $price_piloting = get_option('wpshop_shop_price_piloting'); |
|
| 133 | - $product_currency = wpshop_tools::wpshop_get_currency(); |
|
| 134 | - wp_enqueue_style('wps-product-variation-interface-style', WPSPDTVARIATION_INTERFACE_ASSETS_MAIN_DIR . '/css/style-backend.css'); |
|
| 135 | - wp_enqueue_script('wps-product-variation-interface-script', WPSPDTVARIATION_INTERFACE_ASSETS_MAIN_DIR . '/js/script-backend.js'); |
|
| 136 | - wp_enqueue_script('wps-product-variation-interface-script-utils', WPSPDTVARIATION_INTERFACE_ASSETS_MAIN_DIR . '/js/script-backend-utils.js'); |
|
| 137 | - wp_localize_script('wps-product-variation-interface-script', 'wps_product_variation_interface', array('variation' => $this->variations, 'nonce_delete' => wp_create_nonce('wpshop_variation_management'), 'variation_value' => $wpdb->get_results($query), 'product_price' => $product['product_price'], 'tx_tva' => $product['tx_tva'], 'attribute_in_variation' => $attribute_list, 'variations_saved' => $variations_saved, 'price_piloting' => $price_piloting, 'currency' => $product_currency, 'variation_defining' => $variation_defining, 'label_file' => __('Click to add file', 'wpshop'))); |
|
| 138 | - require_once wpshop_tools::get_template_part(WPSPDTVARIATION_INTERFACE_DIR, WPSPDTVARIATION_INTERFACE_TEMPLATES_MAIN_DIR, 'backend', 'meta_box_variation'); |
|
| 139 | - } |
|
| 140 | - /** |
|
| 141 | - * Save other values out of old variation interface. |
|
| 142 | - * |
|
| 143 | - * @param int $post_id Id of post. |
|
| 144 | - * @param object $post WP_Post of WordPress. |
|
| 145 | - * @return void |
|
| 146 | - */ |
|
| 147 | - private function save_post($post_id, $post) |
|
| 148 | - { |
|
| 149 | - if (wp_is_post_revision($post_id) || WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT !== $post->post_type || !isset($_REQUEST['wpshop_variation_defining']['options']) || !isset($_REQUEST['wps_pdt_variations'])) { |
|
| 150 | - return; |
|
| 151 | - } |
|
| 152 | - wpshop_products::variation_parameters_save($post_id, $_REQUEST['wpshop_variation_defining']['options']); |
|
| 153 | - remove_action('save_post', array($this, 'save_post')); |
|
| 154 | - foreach ($_REQUEST['wps_pdt_variations'] as $variation_id => $data) { |
|
| 155 | - $variation = array('ID' => $variation_id); |
|
| 156 | - if (isset($data['status']) && 'on' === $data['status']) { |
|
| 157 | - $variation['post_status'] = 'publish'; |
|
| 158 | - } else { |
|
| 159 | - $variation['post_status'] = 'draft'; |
|
| 160 | - } |
|
| 161 | - wp_update_post($variation); |
|
| 162 | - } |
|
| 163 | - add_action('save_post', array($this, 'save_post'), 10, 2); |
|
| 164 | - } |
|
| 165 | - /** |
|
| 166 | - * Delete display in attributes products always in metabox. |
|
| 167 | - * |
|
| 168 | - * @param array $output Result of wpshop_attributes::display_attribute() function. |
|
| 169 | - * @param array $element Direct array attribute of db. |
|
| 170 | - * @return array SAme array $output modified. |
|
| 171 | - */ |
|
| 172 | - public function wpshop_attribute_output_def($output, $element) |
|
| 173 | - { |
|
| 174 | - if ($this->is_activate()) { |
|
| 175 | - $this->get_variations($element); |
|
| 176 | - if (!empty($this->variations) && in_array($output['field_definition']['name'], array_keys($this->variations), true)) { |
|
| 177 | - $output['field'] = ''; |
|
| 178 | - } |
|
| 179 | - } |
|
| 180 | - return $output; |
|
| 181 | - } |
|
| 45 | + /** |
|
| 46 | + * Get if module is active. |
|
| 47 | + * |
|
| 48 | + * @param boolean $new_val If set & db is different, save it. |
|
| 49 | + * @return boolean Actual state of module. |
|
| 50 | + */ |
|
| 51 | + public function is_activate($new_val = null) |
|
| 52 | + { |
|
| 53 | + if (!isset($this->is_active)) { |
|
| 54 | + $option = get_option('wps_variation_interface_display', null); |
|
| 55 | + if (is_null($option)) { |
|
| 56 | + $new_val = true; |
|
| 57 | + $option = false; |
|
| 58 | + } |
|
| 59 | + $this->is_active = (bool) $option; |
|
| 60 | + } |
|
| 61 | + if (isset($new_val) && $this->is_active !== $new_val) { |
|
| 62 | + update_option('wps_variation_interface_display', $new_val); |
|
| 63 | + $this->is_active = $new_val; |
|
| 64 | + } |
|
| 65 | + return $this->is_active; |
|
| 66 | + } |
|
| 67 | + /** |
|
| 68 | + * Get variations of an element. |
|
| 69 | + * |
|
| 70 | + * @param array $element Direct array attribute of db. |
|
| 71 | + * @return void It set directly in variable class. |
|
| 72 | + */ |
|
| 73 | + private function get_variations($element) |
|
| 74 | + { |
|
| 75 | + if (!isset($this->variations)) { |
|
| 76 | + $variations = wpshop_attributes::get_variation_available_attribute($element); |
|
| 77 | + $this->variations = (array) array_merge((isset($variations['available']) ? $variations['available'] : array()), (isset($variations['unavailable']) ? $variations['unavailable'] : array())); |
|
| 78 | + unset($variations); |
|
| 79 | + } |
|
| 80 | + } |
|
| 81 | + public function add_meta_boxes($post_status, $post) |
|
| 82 | + { |
|
| 83 | + global $pagenow; |
|
| 84 | + if ($this->is_activate()) { |
|
| 85 | + $this->get_variations($post->ID); |
|
| 86 | + remove_meta_box('wpshop_wpshop_variations', WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT, 'normal'); |
|
| 87 | + if ($pagenow !== 'post-new.php' && !empty($this->variations)) { |
|
| 88 | + add_meta_box('wpshop_wpshop_variations', __('Product variation', 'wpshop'), array($this, 'meta_box_variation'), WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT, 'normal', 'default'); |
|
| 89 | + } |
|
| 90 | + } |
|
| 91 | + } |
|
| 92 | + /** |
|
| 93 | + * The metabox. |
|
| 94 | + * |
|
| 95 | + * @param object $post Given by WordPress. |
|
| 96 | + * @return void Display directly. |
|
| 97 | + */ |
|
| 98 | + private function meta_box_variation($post) |
|
| 99 | + { |
|
| 100 | + $this->get_variations($post->ID); |
|
| 101 | + global $wpdb; |
|
| 102 | + $ids = array(); |
|
| 103 | + foreach ($this->variations as $key => $variation) { |
|
| 104 | + $available = wpshop_attributes::get_select_output($variation['attribute_complete_def']); |
|
| 105 | + $this->variations[$key]['available'] = array_keys($available['possible_value']); |
|
| 106 | + $ids = array_merge($ids, array_keys($available['possible_value'])); |
|
| 107 | + } |
|
| 108 | + $query = $wpdb->prepare('SELECT * FROM ' . WPSHOP_DBT_ATTRIBUTE_VALUES_OPTIONS . " WHERE id IN ('" . implode("', '", $ids) . "') AND status = %s", 'valid'); |
|
| 109 | + $product = wpshop_products::get_product_data($post->ID, false, '"publish","draft","future"'); |
|
| 110 | + $is_used_in_variation = wpshop_attributes::getElement('yes', "'valid', 'notused'", 'is_used_in_variation', true); |
|
| 111 | + $attribute_list = array(); |
|
| 112 | + foreach ($is_used_in_variation as $attribute) { |
|
| 113 | + if (in_array($attribute->backend_input, array('multiple-select', 'select', 'radio', 'checkbox'), true)) { |
|
| 114 | + $values = wpshop_attributes::get_select_output($attribute); |
|
| 115 | + if (!empty($values['possible_value'])) { |
|
| 116 | + $attribute->possible_value = $values['possible_value']; |
|
| 117 | + } |
|
| 118 | + } |
|
| 119 | + $attribute_list[$attribute->code] = $attribute; |
|
| 120 | + } |
|
| 121 | + $variation_defining = get_post_meta($post->ID, '_wpshop_variation_defining', true); |
|
| 122 | + $variations_saved = wpshop_products::get_variation($post->ID); |
|
| 123 | + if (!empty($variations_saved)) { |
|
| 124 | + foreach ($variations_saved as $variation_id => $variation) { |
|
| 125 | + $downloadable = get_post_meta($variation_id, 'attribute_option_is_downloadable_', true); |
|
| 126 | + if (!empty($downloadable['file_url'])) { |
|
| 127 | + $variations_saved[$variation_id]['file']['path'] = $downloadable['file_url']; |
|
| 128 | + $variations_saved[$variation_id]['file']['name'] = basename($downloadable['file_url']); |
|
| 129 | + } |
|
| 130 | + } |
|
| 131 | + } |
|
| 132 | + $price_piloting = get_option('wpshop_shop_price_piloting'); |
|
| 133 | + $product_currency = wpshop_tools::wpshop_get_currency(); |
|
| 134 | + wp_enqueue_style('wps-product-variation-interface-style', WPSPDTVARIATION_INTERFACE_ASSETS_MAIN_DIR . '/css/style-backend.css'); |
|
| 135 | + wp_enqueue_script('wps-product-variation-interface-script', WPSPDTVARIATION_INTERFACE_ASSETS_MAIN_DIR . '/js/script-backend.js'); |
|
| 136 | + wp_enqueue_script('wps-product-variation-interface-script-utils', WPSPDTVARIATION_INTERFACE_ASSETS_MAIN_DIR . '/js/script-backend-utils.js'); |
|
| 137 | + wp_localize_script('wps-product-variation-interface-script', 'wps_product_variation_interface', array('variation' => $this->variations, 'nonce_delete' => wp_create_nonce('wpshop_variation_management'), 'variation_value' => $wpdb->get_results($query), 'product_price' => $product['product_price'], 'tx_tva' => $product['tx_tva'], 'attribute_in_variation' => $attribute_list, 'variations_saved' => $variations_saved, 'price_piloting' => $price_piloting, 'currency' => $product_currency, 'variation_defining' => $variation_defining, 'label_file' => __('Click to add file', 'wpshop'))); |
|
| 138 | + require_once wpshop_tools::get_template_part(WPSPDTVARIATION_INTERFACE_DIR, WPSPDTVARIATION_INTERFACE_TEMPLATES_MAIN_DIR, 'backend', 'meta_box_variation'); |
|
| 139 | + } |
|
| 140 | + /** |
|
| 141 | + * Save other values out of old variation interface. |
|
| 142 | + * |
|
| 143 | + * @param int $post_id Id of post. |
|
| 144 | + * @param object $post WP_Post of WordPress. |
|
| 145 | + * @return void |
|
| 146 | + */ |
|
| 147 | + private function save_post($post_id, $post) |
|
| 148 | + { |
|
| 149 | + if (wp_is_post_revision($post_id) || WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT !== $post->post_type || !isset($_REQUEST['wpshop_variation_defining']['options']) || !isset($_REQUEST['wps_pdt_variations'])) { |
|
| 150 | + return; |
|
| 151 | + } |
|
| 152 | + wpshop_products::variation_parameters_save($post_id, $_REQUEST['wpshop_variation_defining']['options']); |
|
| 153 | + remove_action('save_post', array($this, 'save_post')); |
|
| 154 | + foreach ($_REQUEST['wps_pdt_variations'] as $variation_id => $data) { |
|
| 155 | + $variation = array('ID' => $variation_id); |
|
| 156 | + if (isset($data['status']) && 'on' === $data['status']) { |
|
| 157 | + $variation['post_status'] = 'publish'; |
|
| 158 | + } else { |
|
| 159 | + $variation['post_status'] = 'draft'; |
|
| 160 | + } |
|
| 161 | + wp_update_post($variation); |
|
| 162 | + } |
|
| 163 | + add_action('save_post', array($this, 'save_post'), 10, 2); |
|
| 164 | + } |
|
| 165 | + /** |
|
| 166 | + * Delete display in attributes products always in metabox. |
|
| 167 | + * |
|
| 168 | + * @param array $output Result of wpshop_attributes::display_attribute() function. |
|
| 169 | + * @param array $element Direct array attribute of db. |
|
| 170 | + * @return array SAme array $output modified. |
|
| 171 | + */ |
|
| 172 | + public function wpshop_attribute_output_def($output, $element) |
|
| 173 | + { |
|
| 174 | + if ($this->is_activate()) { |
|
| 175 | + $this->get_variations($element); |
|
| 176 | + if (!empty($this->variations) && in_array($output['field_definition']['name'], array_keys($this->variations), true)) { |
|
| 177 | + $output['field'] = ''; |
|
| 178 | + } |
|
| 179 | + } |
|
| 180 | + return $output; |
|
| 181 | + } |
|
| 182 | 182 | } |
@@ -1,4 +1,4 @@ discard block |
||
| 1 | -<?php if ( !defined( 'ABSPATH' ) ) exit; |
|
| 1 | +<?php if (!defined('ABSPATH')) exit; |
|
| 2 | 2 | class wps_shipping_mode_ctr { |
| 3 | 3 | |
| 4 | 4 | /** |
@@ -18,34 +18,34 @@ discard block |
||
| 18 | 18 | /** Template Load **/ |
| 19 | 19 | // add_filter( 'wpshop_custom_template', array( $this, 'custom_template_load' ) ); |
| 20 | 20 | |
| 21 | - add_action( 'admin_init', array( $this, 'migrate_default_shipping_mode' ) ); |
|
| 21 | + add_action('admin_init', array($this, 'migrate_default_shipping_mode')); |
|
| 22 | 22 | |
| 23 | 23 | /** Add module option to wpshop general options */ |
| 24 | - add_filter('wpshop_options', array( $this, 'add_options'), 9); |
|
| 25 | - add_action('wsphop_options', array( $this, 'create_options'), 8); |
|
| 24 | + add_filter('wpshop_options', array($this, 'add_options'), 9); |
|
| 25 | + add_action('wsphop_options', array($this, 'create_options'), 8); |
|
| 26 | 26 | |
| 27 | 27 | // Add files in back-office |
| 28 | - add_action( 'admin_enqueue_scripts', array( $this, 'add_scripts_in_admin' ) ); |
|
| 28 | + add_action('admin_enqueue_scripts', array($this, 'add_scripts_in_admin')); |
|
| 29 | 29 | // Add files in front-office |
| 30 | - add_action( 'wp_enqueue_scripts', array( $this, 'add_scripts') ); |
|
| 30 | + add_action('wp_enqueue_scripts', array($this, 'add_scripts')); |
|
| 31 | 31 | |
| 32 | 32 | // Available Shortcodes |
| 33 | - add_shortcode( 'wps_shipping_mode', array( &$this, 'display_shipping_mode') ); |
|
| 34 | - add_shortcode( 'wps_shipping_method', array( &$this, 'display_shipping_methods') ); |
|
| 35 | - add_shortcode( 'wps_shipping_summary', array( &$this, 'display_shipping_summary') ); |
|
| 33 | + add_shortcode('wps_shipping_mode', array(&$this, 'display_shipping_mode')); |
|
| 34 | + add_shortcode('wps_shipping_method', array(&$this, 'display_shipping_methods')); |
|
| 35 | + add_shortcode('wps_shipping_summary', array(&$this, 'display_shipping_summary')); |
|
| 36 | 36 | |
| 37 | - add_action( 'add_meta_boxes', array( $this, 'add_meta_box'), 10, 2 ); |
|
| 37 | + add_action('add_meta_boxes', array($this, 'add_meta_box'), 10, 2); |
|
| 38 | 38 | } |
| 39 | 39 | |
| 40 | - function add_meta_box( $post_type, $post ) { |
|
| 41 | - if ( WPSHOP_NEWTYPE_IDENTIFIER_ORDER == $post_type ) { |
|
| 40 | + function add_meta_box($post_type, $post) { |
|
| 41 | + if (WPSHOP_NEWTYPE_IDENTIFIER_ORDER == $post_type) { |
|
| 42 | 42 | /** Box for shipping information */ |
| 43 | 43 | $shipping_option = get_option('wpshop_shipping_address_choice'); |
| 44 | - $order_meta = get_post_meta( $post->ID, '_order_postmeta', true ); |
|
| 45 | - if (!in_array( $post->post_status, array( 'auto-draft' ) ) && ( !empty($shipping_option['activate']) && $shipping_option['activate'] && ( is_array( $order_meta ) && empty($order_meta['order_payment']['shipping_method'] ) || $order_meta['order_payment']['shipping_method'] != 'default_shipping_mode_for_pos' ) ) ) { |
|
| 44 | + $order_meta = get_post_meta($post->ID, '_order_postmeta', true); |
|
| 45 | + if (!in_array($post->post_status, array('auto-draft')) && (!empty($shipping_option['activate']) && $shipping_option['activate'] && (is_array($order_meta) && empty($order_meta['order_payment']['shipping_method']) || $order_meta['order_payment']['shipping_method'] != 'default_shipping_mode_for_pos'))) { |
|
| 46 | 46 | add_meta_box( |
| 47 | 47 | 'wpshop_order_shipping', |
| 48 | - '<span class="dashicons dashicons-palmtree"></span> '.__('Shipping', 'wpshop'), |
|
| 48 | + '<span class="dashicons dashicons-palmtree"></span> ' . __('Shipping', 'wpshop'), |
|
| 49 | 49 | array($this, 'order_shipping_box'), |
| 50 | 50 | WPSHOP_NEWTYPE_IDENTIFIER_ORDER, 'side', 'low' |
| 51 | 51 | ); |
@@ -58,29 +58,29 @@ discard block |
||
| 58 | 58 | */ |
| 59 | 59 | function add_scripts() { |
| 60 | 60 | //CSS files |
| 61 | - wp_register_style( 'wps_shipping_mode_css', WPS_SHIPPING_MODE_URL . WPS_SHIPPING_MODE_DIR .'/assets/frontend/css/wps_shipping_mode.css', false ); |
|
| 62 | - wp_enqueue_style( 'wps_shipping_mode_css' ); |
|
| 61 | + wp_register_style('wps_shipping_mode_css', WPS_SHIPPING_MODE_URL . WPS_SHIPPING_MODE_DIR . '/assets/frontend/css/wps_shipping_mode.css', false); |
|
| 62 | + wp_enqueue_style('wps_shipping_mode_css'); |
|
| 63 | 63 | // Javascript Files |
| 64 | - wp_enqueue_script( 'jquery' ); |
|
| 65 | - wp_enqueue_script( 'wps_shipping_method_js', WPS_SHIPPING_MODE_URL . WPS_SHIPPING_MODE_DIR .'/assets/frontend/js/shipping_method.js', false ); |
|
| 64 | + wp_enqueue_script('jquery'); |
|
| 65 | + wp_enqueue_script('wps_shipping_method_js', WPS_SHIPPING_MODE_URL . WPS_SHIPPING_MODE_DIR . '/assets/frontend/js/shipping_method.js', false); |
|
| 66 | 66 | } |
| 67 | 67 | |
| 68 | 68 | /** |
| 69 | 69 | * Add JS and CSS files in back-office |
| 70 | 70 | */ |
| 71 | - function add_scripts_in_admin( $hook ) { |
|
| 71 | + function add_scripts_in_admin($hook) { |
|
| 72 | 72 | global $current_screen; |
| 73 | - if ( ! in_array( $current_screen->post_type, array( WPSHOP_NEWTYPE_IDENTIFIER_ORDER ), true ) && $hook !== 'settings_page_wpshop_option' ) |
|
| 73 | + if (!in_array($current_screen->post_type, array(WPSHOP_NEWTYPE_IDENTIFIER_ORDER), true) && $hook !== 'settings_page_wpshop_option') |
|
| 74 | 74 | return; |
| 75 | 75 | |
| 76 | 76 | add_thickbox(); |
| 77 | 77 | wp_enqueue_script('jquery'); |
| 78 | 78 | wp_enqueue_script('jquery-ui-sortable'); |
| 79 | 79 | // Javascript files |
| 80 | - wp_enqueue_script( 'wps_shipping_mode_js', WPS_SHIPPING_MODE_URL . WPS_SHIPPING_MODE_DIR .'/assets/backend/js/wps_shipping_mode.js', false ); |
|
| 80 | + wp_enqueue_script('wps_shipping_mode_js', WPS_SHIPPING_MODE_URL . WPS_SHIPPING_MODE_DIR . '/assets/backend/js/wps_shipping_mode.js', false); |
|
| 81 | 81 | //CSS files |
| 82 | - wp_register_style( 'wps_shipping_mode_css', WPS_SHIPPING_MODE_URL . WPS_SHIPPING_MODE_DIR .'/assets/backend/css/wps_shipping_mode.css', false ); |
|
| 83 | - wp_enqueue_style( 'wps_shipping_mode_css' ); |
|
| 82 | + wp_register_style('wps_shipping_mode_css', WPS_SHIPPING_MODE_URL . WPS_SHIPPING_MODE_DIR . '/assets/backend/css/wps_shipping_mode.css', false); |
|
| 83 | + wp_enqueue_style('wps_shipping_mode_css'); |
|
| 84 | 84 | } |
| 85 | 85 | |
| 86 | 86 | |
@@ -102,7 +102,7 @@ discard block |
||
| 102 | 102 | /** |
| 103 | 103 | * Declare option groups for the module |
| 104 | 104 | */ |
| 105 | - function add_options( $option_group ) { |
|
| 105 | + function add_options($option_group) { |
|
| 106 | 106 | $option_group['wpshop_shipping_option']['subgroups']['wps_shipping_mode']['class'] = ' wpshop_admin_box_options_shipping_mode'; |
| 107 | 107 | return $option_group; |
| 108 | 108 | } |
@@ -111,38 +111,38 @@ discard block |
||
| 111 | 111 | * Create Options |
| 112 | 112 | **/ |
| 113 | 113 | function create_options() { |
| 114 | - add_settings_section('wps_shipping_mode', '<span class="dashicons dashicons-admin-site"></span>'.__('Shipping method', 'wpshop'), '', 'wps_shipping_mode'); |
|
| 115 | - register_setting('wpshop_options', 'wps_shipping_mode', array( $this, 'wpshop_options_validate_wps_shipping_mode')); |
|
| 116 | - add_settings_field('wps_shipping_mode', ''/*__('Shipping Mode', 'wpshop')*/, array( $this, 'display_shipping_mode_in_admin'), 'wps_shipping_mode', 'wps_shipping_mode'); |
|
| 114 | + add_settings_section('wps_shipping_mode', '<span class="dashicons dashicons-admin-site"></span>' . __('Shipping method', 'wpshop'), '', 'wps_shipping_mode'); |
|
| 115 | + register_setting('wpshop_options', 'wps_shipping_mode', array($this, 'wpshop_options_validate_wps_shipping_mode')); |
|
| 116 | + add_settings_field('wps_shipping_mode', ''/*__('Shipping Mode', 'wpshop')*/, array($this, 'display_shipping_mode_in_admin'), 'wps_shipping_mode', 'wps_shipping_mode'); |
|
| 117 | 117 | } |
| 118 | 118 | |
| 119 | 119 | /** |
| 120 | 120 | * WPS Shipping mode Option Validator |
| 121 | 121 | **/ |
| 122 | - function wpshop_options_validate_wps_shipping_mode( $input ) { |
|
| 122 | + function wpshop_options_validate_wps_shipping_mode($input) { |
|
| 123 | 123 | $wps_shipping = new wps_shipping(); |
| 124 | - if ( !empty($input['modes']) ) { |
|
| 125 | - foreach( $input['modes'] as $mode => $mode_det ) { |
|
| 124 | + if (!empty($input['modes'])) { |
|
| 125 | + foreach ($input['modes'] as $mode => $mode_det) { |
|
| 126 | 126 | /** Custom Shipping rules **/ |
| 127 | - $input['modes'][$mode]['custom_shipping_rules']['fees'] = $wps_shipping->shipping_fees_string_2_array( $input['modes'][$mode]['custom_shipping_rules']['fees'] ); |
|
| 127 | + $input['modes'][$mode]['custom_shipping_rules']['fees'] = $wps_shipping->shipping_fees_string_2_array($input['modes'][$mode]['custom_shipping_rules']['fees']); |
|
| 128 | 128 | |
| 129 | 129 | /** Shipping Modes Logo Treatment **/ |
| 130 | - if ( !empty($_FILES[$mode.'_logo']['name']) && empty($_FILES[$mode.'_logo']['error']) ) { |
|
| 131 | - $filename = $_FILES[$mode.'_logo']; |
|
| 132 | - $upload = wp_handle_upload($filename, array('test_form' => false)); |
|
| 133 | - $wp_filetype = wp_check_filetype(basename($filename['name']), null ); |
|
| 130 | + if (!empty($_FILES[$mode . '_logo']['name']) && empty($_FILES[$mode . '_logo']['error'])) { |
|
| 131 | + $filename = $_FILES[$mode . '_logo']; |
|
| 132 | + $upload = wp_handle_upload($filename, array('test_form' => false)); |
|
| 133 | + $wp_filetype = wp_check_filetype(basename($filename['name']), null); |
|
| 134 | 134 | $wp_upload_dir = wp_upload_dir(); |
| 135 | 135 | $attachment = array( |
| 136 | - 'guid' => $wp_upload_dir['url'] . '/' . basename( $filename['name'] ), |
|
| 136 | + 'guid' => $wp_upload_dir['url'] . '/' . basename($filename['name']), |
|
| 137 | 137 | 'post_mime_type' => $wp_filetype['type'], |
| 138 | 138 | 'post_title' => preg_replace(' /\.[^.]+$/', '', basename($filename['name'])), |
| 139 | 139 | 'post_content' => '', |
| 140 | 140 | 'post_status' => 'inherit' |
| 141 | 141 | ); |
| 142 | - $attach_id = wp_insert_attachment( $attachment, $upload['file']); |
|
| 142 | + $attach_id = wp_insert_attachment($attachment, $upload['file']); |
|
| 143 | 143 | require_once(ABSPATH . 'wp-admin/includes/image.php'); |
| 144 | - $attach_data = wp_generate_attachment_metadata( $attach_id, $upload['file'] ); |
|
| 145 | - wp_update_attachment_metadata( $attach_id, $attach_data ); |
|
| 144 | + $attach_data = wp_generate_attachment_metadata($attach_id, $upload['file']); |
|
| 145 | + wp_update_attachment_metadata($attach_id, $attach_data); |
|
| 146 | 146 | |
| 147 | 147 | $input['modes'][$mode]['logo'] = $attach_id; |
| 148 | 148 | } |
@@ -156,38 +156,38 @@ discard block |
||
| 156 | 156 | **/ |
| 157 | 157 | function migrate_default_shipping_mode() { |
| 158 | 158 | $data = array(); |
| 159 | - $shipping_mode_option = get_option( 'wps_shipping_mode' ); |
|
| 160 | - if ( empty($shipping_mode_option) ) { |
|
| 159 | + $shipping_mode_option = get_option('wps_shipping_mode'); |
|
| 160 | + if (empty($shipping_mode_option)) { |
|
| 161 | 161 | $data['modes']['default_shipping_mode']['active'] = 'on'; |
| 162 | 162 | $data['modes']['default_shipping_mode']['name'] = __('Home Delivery', 'wpshop'); |
| 163 | 163 | $data['modes']['default_shipping_mode']['explanation'] = __('Your purchase will be delivered directly to you at home', 'wpshop'); |
| 164 | 164 | /** Check CUstom Shipping **/ |
| 165 | - $custom_shipping_option = get_option( 'wpshop_custom_shipping' ); |
|
| 166 | - if ( !empty($custom_shipping_option) ) { |
|
| 165 | + $custom_shipping_option = get_option('wpshop_custom_shipping'); |
|
| 166 | + if (!empty($custom_shipping_option)) { |
|
| 167 | 167 | $data['modes']['default_shipping_mode']['custom_shipping_rules'] = $custom_shipping_option; |
| 168 | 168 | } |
| 169 | 169 | /** Check Country Limit **/ |
| 170 | - $limit_destination = get_option( 'wpshop_limit_shipping_destination' ); |
|
| 171 | - if ( !empty($custom_shipping_option) ) { |
|
| 170 | + $limit_destination = get_option('wpshop_limit_shipping_destination'); |
|
| 171 | + if (!empty($custom_shipping_option)) { |
|
| 172 | 172 | $data['modes']['default_shipping_mode']['limit_destination'] = $limit_destination; |
| 173 | 173 | } |
| 174 | 174 | |
| 175 | 175 | /** Check Others shipping configurations **/ |
| 176 | 176 | $wpshop_shipping_rules_option = get_option('wpshop_shipping_rules'); |
| 177 | - if ( !empty($wpshop_shipping_rules_option) ){ |
|
| 178 | - if ( !empty($wpshop_shipping_rules_option['min_max']) ) { |
|
| 177 | + if (!empty($wpshop_shipping_rules_option)) { |
|
| 178 | + if (!empty($wpshop_shipping_rules_option['min_max'])) { |
|
| 179 | 179 | $data['modes']['default_shipping_mode']['min_max'] = $wpshop_shipping_rules_option['min_max']; |
| 180 | 180 | } |
| 181 | - if ( !empty($wpshop_shipping_rules_option['free_from']) ) { |
|
| 181 | + if (!empty($wpshop_shipping_rules_option['free_from'])) { |
|
| 182 | 182 | $data['modes']['default_shipping_mode']['free_from'] = $wpshop_shipping_rules_option['free_from']; |
| 183 | 183 | } |
| 184 | - if ( !empty($wpshop_shipping_rules_option['wpshop_shipping_rule_free_shipping']) ) { |
|
| 184 | + if (!empty($wpshop_shipping_rules_option['wpshop_shipping_rule_free_shipping'])) { |
|
| 185 | 185 | $data['modes']['default_shipping_mode']['free_shipping'] = $wpshop_shipping_rules_option['wpshop_shipping_rule_free_shipping']; |
| 186 | 186 | } |
| 187 | 187 | } |
| 188 | 188 | $data['default_choice'] = 'default_shipping_mode'; |
| 189 | 189 | |
| 190 | - update_option( 'wps_shipping_mode', $data ); |
|
| 190 | + update_option('wps_shipping_mode', $data); |
|
| 191 | 191 | } |
| 192 | 192 | } |
| 193 | 193 | |
@@ -195,8 +195,8 @@ discard block |
||
| 195 | 195 | * Display the Admin Interface for Shipping Mode |
| 196 | 196 | **/ |
| 197 | 197 | function display_shipping_mode_in_admin() { |
| 198 | - $shipping_mode_option = get_option( 'wps_shipping_mode' ); |
|
| 199 | - require_once( wpshop_tools::get_template_part( WPS_SHIPPING_MODE_DIR, $this->template_dir, "backend", "shipping-modes") ); |
|
| 198 | + $shipping_mode_option = get_option('wps_shipping_mode'); |
|
| 199 | + require_once(wpshop_tools::get_template_part(WPS_SHIPPING_MODE_DIR, $this->template_dir, "backend", "shipping-modes")); |
|
| 200 | 200 | } |
| 201 | 201 | |
| 202 | 202 | /** |
@@ -205,28 +205,28 @@ discard block |
||
| 205 | 205 | * @param array $shipping_mode |
| 206 | 206 | * @return string |
| 207 | 207 | */ |
| 208 | - function generate_shipping_mode_interface( $k, $shipping_mode ) { |
|
| 208 | + function generate_shipping_mode_interface($k, $shipping_mode) { |
|
| 209 | 209 | global $wpdb; |
| 210 | 210 | $tpl_component = array(); |
| 211 | 211 | |
| 212 | - $shipping_mode_option = get_option( 'wps_shipping_mode'); |
|
| 213 | - $default_shipping_mode = !empty( $shipping_mode_option['default_choice'] ) ? $shipping_mode_option['default_choice'] : ''; |
|
| 212 | + $shipping_mode_option = get_option('wps_shipping_mode'); |
|
| 213 | + $default_shipping_mode = !empty($shipping_mode_option['default_choice']) ? $shipping_mode_option['default_choice'] : ''; |
|
| 214 | 214 | |
| 215 | 215 | $countries = unserialize(WPSHOP_COUNTRY_LIST); |
| 216 | 216 | |
| 217 | 217 | /** Default Weight Unity **/ |
| 218 | - $weight_defaut_unity_option = get_option ('wpshop_shop_default_weight_unity'); |
|
| 219 | - $query = $wpdb->prepare('SELECT name FROM '. WPSHOP_DBT_ATTRIBUTE_UNIT . ' WHERE id=%d', $weight_defaut_unity_option); |
|
| 220 | - $unity = $wpdb->get_var( $query ); |
|
| 218 | + $weight_defaut_unity_option = get_option('wpshop_shop_default_weight_unity'); |
|
| 219 | + $query = $wpdb->prepare('SELECT name FROM ' . WPSHOP_DBT_ATTRIBUTE_UNIT . ' WHERE id=%d', $weight_defaut_unity_option); |
|
| 220 | + $unity = $wpdb->get_var($query); |
|
| 221 | 221 | |
| 222 | 222 | |
| 223 | - $fees_data = ( !empty($shipping_mode) & !empty($shipping_mode['custom_shipping_rules']) && !empty($shipping_mode['custom_shipping_rules']['fees']) ) ? $shipping_mode['custom_shipping_rules']['fees'] : array(); |
|
| 224 | - if(is_array($fees_data)) { |
|
| 223 | + $fees_data = (!empty($shipping_mode) & !empty($shipping_mode['custom_shipping_rules']) && !empty($shipping_mode['custom_shipping_rules']['fees'])) ? $shipping_mode['custom_shipping_rules']['fees'] : array(); |
|
| 224 | + if (is_array($fees_data)) { |
|
| 225 | 225 | $wps_shipping = new wps_shipping(); |
| 226 | 226 | $fees_data = $wps_shipping->shipping_fees_array_2_string($fees_data); |
| 227 | 227 | } |
| 228 | 228 | ob_start(); |
| 229 | - require( wpshop_tools::get_template_part( WPS_SHIPPING_MODE_DIR, $this->template_dir, "backend", "shipping-mode-configuration-interface") ); |
|
| 229 | + require(wpshop_tools::get_template_part(WPS_SHIPPING_MODE_DIR, $this->template_dir, "backend", "shipping-mode-configuration-interface")); |
|
| 230 | 230 | $output = ob_get_contents(); |
| 231 | 231 | ob_end_clean(); |
| 232 | 232 | |
@@ -239,22 +239,22 @@ discard block |
||
| 239 | 239 | * @param array $fees_data |
| 240 | 240 | * @param string $key |
| 241 | 241 | */ |
| 242 | - function generate_shipping_rules_table( $fees_data, $shipping_mode_id ){ |
|
| 242 | + function generate_shipping_rules_table($fees_data, $shipping_mode_id) { |
|
| 243 | 243 | global $wpdb; |
| 244 | 244 | $result = ''; |
| 245 | - if ( !empty( $fees_data) ) { |
|
| 245 | + if (!empty($fees_data)) { |
|
| 246 | 246 | $wps_shipping = new wps_shipping(); |
| 247 | - $shipping_rules =$wps_shipping->shipping_fees_string_2_array( stripslashes($fees_data) ); |
|
| 247 | + $shipping_rules = $wps_shipping->shipping_fees_string_2_array(stripslashes($fees_data)); |
|
| 248 | 248 | $result = ''; |
| 249 | - $tpl_component =''; |
|
| 249 | + $tpl_component = ''; |
|
| 250 | 250 | $tpl_component['CUSTOM_SHIPPING_RULES_LINES'] = ''; |
| 251 | 251 | $tpl_component['SHIPPING_MODE_ID'] = $shipping_mode_id; |
| 252 | 252 | $country_list = unserialize(WPSHOP_COUNTRY_LIST); |
| 253 | - $weight_defaut_unity_option = get_option ('wpshop_shop_default_weight_unity'); |
|
| 254 | - $query = $wpdb->prepare('SELECT unit FROM '. WPSHOP_DBT_ATTRIBUTE_UNIT . ' WHERE id=%d', $weight_defaut_unity_option); |
|
| 255 | - $unity = $wpdb->get_var( $query ); |
|
| 253 | + $weight_defaut_unity_option = get_option('wpshop_shop_default_weight_unity'); |
|
| 254 | + $query = $wpdb->prepare('SELECT unit FROM ' . WPSHOP_DBT_ATTRIBUTE_UNIT . ' WHERE id=%d', $weight_defaut_unity_option); |
|
| 255 | + $unity = $wpdb->get_var($query); |
|
| 256 | 256 | ob_start(); |
| 257 | - require( wpshop_tools::get_template_part( WPS_SHIPPING_MODE_DIR, $this->template_dir, "backend", "shipping-mode-configuration-custom-rules-table") ); |
|
| 257 | + require(wpshop_tools::get_template_part(WPS_SHIPPING_MODE_DIR, $this->template_dir, "backend", "shipping-mode-configuration-custom-rules-table")); |
|
| 258 | 258 | $result = ob_get_contents(); |
| 259 | 259 | ob_end_clean(); |
| 260 | 260 | } |
@@ -274,16 +274,16 @@ discard block |
||
| 274 | 274 | */ |
| 275 | 275 | function display_shipping_methods() { |
| 276 | 276 | $output = $shipping_methods = ''; $no_shipping_mode_for_area = false; |
| 277 | - $shipping_modes = get_option( 'wps_shipping_mode' ); |
|
| 278 | - if( !empty($_SESSION['shipping_address']) ) { |
|
| 279 | - $shipping_modes = $this->get_shipping_mode_for_address( $_SESSION['shipping_address'] ); |
|
| 280 | - if( empty($shipping_modes) ) { |
|
| 277 | + $shipping_modes = get_option('wps_shipping_mode'); |
|
| 278 | + if (!empty($_SESSION['shipping_address'])) { |
|
| 279 | + $shipping_modes = $this->get_shipping_mode_for_address($_SESSION['shipping_address']); |
|
| 280 | + if (empty($shipping_modes)) { |
|
| 281 | 281 | $no_shipping_mode_for_area = true; |
| 282 | 282 | } |
| 283 | 283 | } |
| 284 | - $shipping_modes = apply_filters( 'wps_filter_shipping_methods', $shipping_modes ); |
|
| 284 | + $shipping_modes = apply_filters('wps_filter_shipping_methods', $shipping_modes); |
|
| 285 | 285 | ob_start(); |
| 286 | - require_once( wpshop_tools::get_template_part( WPS_SHIPPING_MODE_DIR, $this->template_dir, "frontend", "shipping-mode", "container") ); |
|
| 286 | + require_once(wpshop_tools::get_template_part(WPS_SHIPPING_MODE_DIR, $this->template_dir, "frontend", "shipping-mode", "container")); |
|
| 287 | 287 | $output = ob_get_contents(); |
| 288 | 288 | ob_end_clean(); |
| 289 | 289 | |
@@ -296,24 +296,24 @@ discard block |
||
| 296 | 296 | */ |
| 297 | 297 | function display_shipping_summary() { |
| 298 | 298 | $output = ''; |
| 299 | - $billing_address_id = ( !empty($_SESSION['billing_address']) ) ? $_SESSION['billing_address'] : null; |
|
| 300 | - $shipping_address_id = ( !empty($_SESSION['shipping_address']) ) ? $_SESSION['shipping_address'] : null; |
|
| 301 | - $shipping_mode = ( !empty($_SESSION['shipping_method']) ) ? $_SESSION['shipping_method'] : null; |
|
| 299 | + $billing_address_id = (!empty($_SESSION['billing_address'])) ? $_SESSION['billing_address'] : null; |
|
| 300 | + $shipping_address_id = (!empty($_SESSION['shipping_address'])) ? $_SESSION['shipping_address'] : null; |
|
| 301 | + $shipping_mode = (!empty($_SESSION['shipping_method'])) ? $_SESSION['shipping_method'] : null; |
|
| 302 | 302 | |
| 303 | - if( !empty($billing_address_id) ) { |
|
| 303 | + if (!empty($billing_address_id)) { |
|
| 304 | 304 | $billing_infos = get_post_meta($billing_address_id, '_wpshop_address_metadata', true); |
| 305 | - $billing_content = wps_address::display_an_address( $billing_infos, $billing_address_id); |
|
| 305 | + $billing_content = wps_address::display_an_address($billing_infos, $billing_address_id); |
|
| 306 | 306 | |
| 307 | - if ( !empty($shipping_address_id) && !empty($shipping_mode) ) { |
|
| 307 | + if (!empty($shipping_address_id) && !empty($shipping_mode)) { |
|
| 308 | 308 | $shipping_infos = get_post_meta($shipping_address_id, '_wpshop_address_metadata', true); |
| 309 | - $shipping_content = wps_address::display_an_address( $shipping_infos, $shipping_address_id); |
|
| 309 | + $shipping_content = wps_address::display_an_address($shipping_infos, $shipping_address_id); |
|
| 310 | 310 | |
| 311 | - $shipping_mode_option = get_option( 'wps_shipping_mode' ); |
|
| 312 | - $shipping_mode = ( !empty($shipping_mode_option) && !empty($shipping_mode_option['modes']) && !empty($shipping_mode_option['modes'][$shipping_mode]) && !empty($shipping_mode_option['modes'][$shipping_mode]['name']) ) ? $shipping_mode_option['modes'][$shipping_mode]['name'] : ''; |
|
| 311 | + $shipping_mode_option = get_option('wps_shipping_mode'); |
|
| 312 | + $shipping_mode = (!empty($shipping_mode_option) && !empty($shipping_mode_option['modes']) && !empty($shipping_mode_option['modes'][$shipping_mode]) && !empty($shipping_mode_option['modes'][$shipping_mode]['name'])) ? $shipping_mode_option['modes'][$shipping_mode]['name'] : ''; |
|
| 313 | 313 | } |
| 314 | 314 | |
| 315 | 315 | ob_start(); |
| 316 | - require( wpshop_tools::get_template_part( WPS_SHIPPING_MODE_DIR, $this->template_dir, "frontend", "shipping-infos", "summary") ); |
|
| 316 | + require(wpshop_tools::get_template_part(WPS_SHIPPING_MODE_DIR, $this->template_dir, "frontend", "shipping-infos", "summary")); |
|
| 317 | 317 | $output = ob_get_contents(); |
| 318 | 318 | ob_end_clean(); |
| 319 | 319 | } |
@@ -327,42 +327,42 @@ discard block |
||
| 327 | 327 | * @param integer $address_id |
| 328 | 328 | * @return string |
| 329 | 329 | */ |
| 330 | - function get_shipping_mode_for_address( $address_id ) { |
|
| 330 | + function get_shipping_mode_for_address($address_id) { |
|
| 331 | 331 | $shipping_modes_to_display = array(); |
| 332 | - if( !empty($address_id) ) { |
|
| 333 | - $shipping_modes = get_option( 'wps_shipping_mode' ); |
|
| 334 | - $address_metadata = /*isset( $postcode ) ? array( 'postcode' => $postcode ) :*/ get_post_meta( $address_id, '_wpshop_address_metadata', true); |
|
| 335 | - if( !empty( $shipping_modes ) && !empty($shipping_modes['modes']) ){ |
|
| 336 | - foreach( $shipping_modes['modes'] as $k => $shipping_mode ) { |
|
| 337 | - if ( !empty($shipping_mode) && !empty($shipping_mode['active']) ) { |
|
| 332 | + if (!empty($address_id)) { |
|
| 333 | + $shipping_modes = get_option('wps_shipping_mode'); |
|
| 334 | + $address_metadata = /*isset( $postcode ) ? array( 'postcode' => $postcode ) :*/ get_post_meta($address_id, '_wpshop_address_metadata', true); |
|
| 335 | + if (!empty($shipping_modes) && !empty($shipping_modes['modes'])) { |
|
| 336 | + foreach ($shipping_modes['modes'] as $k => $shipping_mode) { |
|
| 337 | + if (!empty($shipping_mode) && !empty($shipping_mode['active'])) { |
|
| 338 | 338 | /** Check Country Shipping Limitation **/ |
| 339 | - if ( empty($shipping_mode['limit_destination']) || ( !empty($shipping_mode['limit_destination']) && empty($shipping_mode['limit_destination']['country']) ) || ( !empty($shipping_mode['limit_destination']) && !empty($shipping_mode['limit_destination']['country']) && in_array($address_metadata['country'], $shipping_mode['limit_destination']['country']) ) ) { |
|
| 339 | + if (empty($shipping_mode['limit_destination']) || (!empty($shipping_mode['limit_destination']) && empty($shipping_mode['limit_destination']['country'])) || (!empty($shipping_mode['limit_destination']) && !empty($shipping_mode['limit_destination']['country']) && in_array($address_metadata['country'], $shipping_mode['limit_destination']['country']))) { |
|
| 340 | 340 | /** Check Limit Destination By Postcode **/ |
| 341 | 341 | $visible = true; |
| 342 | 342 | /** Check Postcode limitation **/ |
| 343 | - if ( !empty($shipping_mode['limit_destination']) && !empty($shipping_mode['limit_destination']['postcode']) ) { |
|
| 344 | - $postcodes = explode(',', $shipping_mode['limit_destination']['postcode'] ); |
|
| 345 | - foreach( $postcodes as $postcode_id => $postcode ) { |
|
| 346 | - $postcodes[ $postcode_id ] = trim( str_replace( ' ', '', $postcode) ); |
|
| 343 | + if (!empty($shipping_mode['limit_destination']) && !empty($shipping_mode['limit_destination']['postcode'])) { |
|
| 344 | + $postcodes = explode(',', $shipping_mode['limit_destination']['postcode']); |
|
| 345 | + foreach ($postcodes as $postcode_id => $postcode) { |
|
| 346 | + $postcodes[$postcode_id] = trim(str_replace(' ', '', $postcode)); |
|
| 347 | 347 | } |
| 348 | - if ( !in_array($address_metadata['postcode'], $postcodes) ) { |
|
| 348 | + if (!in_array($address_metadata['postcode'], $postcodes)) { |
|
| 349 | 349 | $visible = false; |
| 350 | 350 | } |
| 351 | 351 | } |
| 352 | 352 | /** Check Department limitation **/ |
| 353 | - $department = isset( $address_metadata['postcode'] ) ? substr( $address_metadata['postcode'], 0, 2 ) : ''; |
|
| 354 | - if ( !empty($shipping_mode['limit_destination']) && !empty($shipping_mode['limit_destination']['department']) ) { |
|
| 355 | - $departments = explode(',', $shipping_mode['limit_destination']['department'] ); |
|
| 356 | - foreach( $departments as $department_id => $d ) { |
|
| 357 | - $departments[ $department_id ] = trim( str_replace( ' ', '', $d) ); |
|
| 353 | + $department = isset($address_metadata['postcode']) ? substr($address_metadata['postcode'], 0, 2) : ''; |
|
| 354 | + if (!empty($shipping_mode['limit_destination']) && !empty($shipping_mode['limit_destination']['department'])) { |
|
| 355 | + $departments = explode(',', $shipping_mode['limit_destination']['department']); |
|
| 356 | + foreach ($departments as $department_id => $d) { |
|
| 357 | + $departments[$department_id] = trim(str_replace(' ', '', $d)); |
|
| 358 | 358 | } |
| 359 | 359 | |
| 360 | - if ( !in_array($department, $departments) ) { |
|
| 360 | + if (!in_array($department, $departments)) { |
|
| 361 | 361 | $visible = false; |
| 362 | 362 | } |
| 363 | 363 | } |
| 364 | 364 | |
| 365 | - if ( $visible ) { |
|
| 365 | + if ($visible) { |
|
| 366 | 366 | $shipping_modes_to_display['modes'][$k] = $shipping_mode; |
| 367 | 367 | } |
| 368 | 368 | } |
@@ -378,12 +378,12 @@ discard block |
||
| 378 | 378 | * Display shipping informations in order administration panel |
| 379 | 379 | * @param object $order : Order post infos |
| 380 | 380 | */ |
| 381 | - function order_shipping_box( $order ) { |
|
| 382 | - $shipping_mode_option = get_option( 'wps_shipping_mode' ); |
|
| 381 | + function order_shipping_box($order) { |
|
| 382 | + $shipping_mode_option = get_option('wps_shipping_mode'); |
|
| 383 | 383 | $order_postmeta = get_post_meta($order->ID, '_order_postmeta', true); |
| 384 | - $shipping_method_name = ( !empty($order_postmeta['order_payment']['shipping_method']) && !empty($shipping_mode_option) && !empty($shipping_mode_option['modes']) && is_array($shipping_mode_option['modes']) && array_key_exists($order_postmeta['order_payment']['shipping_method'], $shipping_mode_option['modes'])) ? $shipping_mode_option['modes'][$order_postmeta['order_payment']['shipping_method']]['name'] : ( (!empty($order_postmeta['order_payment']['shipping_method']) ) ? $order_postmeta['order_payment']['shipping_method'] : '' ); |
|
| 384 | + $shipping_method_name = (!empty($order_postmeta['order_payment']['shipping_method']) && !empty($shipping_mode_option) && !empty($shipping_mode_option['modes']) && is_array($shipping_mode_option['modes']) && array_key_exists($order_postmeta['order_payment']['shipping_method'], $shipping_mode_option['modes'])) ? $shipping_mode_option['modes'][$order_postmeta['order_payment']['shipping_method']]['name'] : ((!empty($order_postmeta['order_payment']['shipping_method'])) ? $order_postmeta['order_payment']['shipping_method'] : ''); |
|
| 385 | 385 | ob_start(); |
| 386 | - require( wpshop_tools::get_template_part( WPS_SHIPPING_MODE_DIR, $this->template_dir, "backend", "order-shipping-infos") ); |
|
| 386 | + require(wpshop_tools::get_template_part(WPS_SHIPPING_MODE_DIR, $this->template_dir, "backend", "order-shipping-infos")); |
|
| 387 | 387 | $output = ob_get_contents(); |
| 388 | 388 | ob_end_clean(); |
| 389 | 389 | echo $output; |