/** * Updates shipping settings * * @access public * @param int $ID * @param array $data * @return void */ public static function updateShipping($ID, $data) { $shipping = array(); $methods = ThemexWoo::getShippingMethods(); $defaults = array('free_shipping', 'flat_rate', 'international_delivery', 'local_delivery'); foreach ($defaults as $default) { if (isset($methods[$default])) { $shipping[$default]['enabled'] = sanitize_title(themex_value($default . '_enabled', $data)); $shipping[$default]['availability'] = sanitize_title(themex_value($default . '_availability', $data)); $countries = themex_array($default . '_countries', $data); if (is_array($countries)) { foreach ($countries as &$country) { if (is_array($country) && !empty($country)) { $country = reset($country); } } } $shipping[$default]['countries'] = $countries; if ($default == 'free_shipping') { $shipping[$default]['min_amount'] = ThemexWoo::formatPrice(themex_value($default . '_min_amount', $data), false); } else { if ($default == 'flat_rate') { $shipping[$default]['default_cost'] = ThemexWoo::formatPrice(themex_value($default . '_default_cost', $data), false); $costs = themex_array($default . '_cost', $data); if (is_array($costs)) { foreach ($costs as &$cost) { $cost = ThemexWoo::formatPrice($cost, false); } } $classes = themex_array($default . '_class', $data); $shipping[$default]['costs'] = array(); if (is_array($classes)) { $classes = array_map('sanitize_title', $classes); foreach ($classes as $index => $class) { if (isset($costs[$index]) && !empty($costs[$index])) { $shipping[$default]['costs'][$class] = $costs[$index]; } } } } else { if (in_array($default, array('international_delivery', 'local_delivery'))) { $shipping[$default]['cost'] = ThemexWoo::formatPrice(themex_value($default . '_cost', $data), false); } } } } } ThemexCore::updatePostMeta($ID, 'shipping', $shipping); ThemexInterface::$messages[] = __('Changes have been successfully saved', 'makery'); $_POST['success'] = true; }
?> </h1> </div> <?php ThemexInterface::renderTemplateContent('shop-shipping'); ?> <?php if (!ThemexWoo::isActive() || ThemexCore::checkOption('shop_shipping')) { ?> <span class="secondary"><?php _e('This shop does not exist.', 'makery'); ?> </span> <?php } else { $methods = ThemexWoo::getShippingMethods(); $shipping = ThemexShop::getShipping(ThemexShop::$data['ID']); if (!empty($methods)) { ?> <form action="" method="POST" class="site-form"> <div class="message"> <?php ThemexInterface::renderMessages(themex_value('success', $_POST, false)); ?> </div> <?php if (isset($methods['free_shipping']) && $methods['free_shipping']->enabled == 'yes') { ?> <h3><?php echo $methods['free_shipping']->title; ?>