/** * Updates shipping rates * * @access public * @param array $rates * @param array $package * @return array */ public static function updateShipping($rates, $package) { $products = $package['contents']; $product = reset($products); $total = $package['contents_cost']; $shipping = ThemexShop::getShipping(ThemexUser::getShop($product['data']->post->post_author)); $country = ''; if (isset($package['destination']) && isset($package['destination']['country'])) { $country = $package['destination']['country']; } if (!empty($rates)) { foreach ($rates as $key => $rate) { if (isset($shipping[$key])) { $method = $shipping[$key]; $enabled = themex_value('enabled', $method); $available = themex_value('availability', $method); $amount = themex_value('min_amount', $method); $countries = themex_array('countries', $method); if ($enabled == 'no' || !empty($amount) && $total < $amount || $available == 'specific' && !in_array($country, $countries)) { unset($rates[$key]); } else { if ($key == 'flat_rate') { $default = intval(themex_value('default_cost', $method)); $costs = themex_array('costs', $method); $cost = 0; foreach ($products as $product) { $classes = get_the_terms($product['product_id'], 'product_shipping_class'); if (is_array($classes) && !empty($classes)) { $class = reset($classes); $class = $class->slug; if (isset($costs[$class])) { $cost = $cost + intval($costs[$class]) * $product['quantity']; } else { $cost = $cost + $default * $product['quantity']; } } else { $cost = $cost + $default * $product['quantity']; } } $rates[$key]->cost = $cost; } } } } } return $rates; }
</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; ?> </h3>