cart_shipping_calc

The evolve cart shipping calc function.

Description

cart_shipping_calc(); 

Usage

  1. if ( !function_exists( 'cart_shipping_calc' ) ) { 
  2. require_once '/library/woo-config.php'; 
  3.  
  4.  
  5. // NOTICE! Understand what this does before running. 
  6. $result = cart_shipping_calc(); 
  7.  

Defined (1)

The function is defined in the following location(s).

/library/woo-config.php  
  1. function cart_shipping_calc() { 
  2. global $woocommerce; 
  3.  
  4. if (get_option('woocommerce_enable_shipping_calc') === 'no' || !WC()->cart->needs_shipping()) { 
  5. return; 
  6.  
  7. ?> 
  8.  
  9. <div class="shipping_calculator" action="<?php echo esc_url(WC()->cart->get_cart_url()); ?>" method="post"> 
  10.  
  11. <h2><?php _e('Calculate Shipping', 'evolve'); ?></h2> 
  12.  
  13. <div class="evolve-shipping-calculator-form"> 
  14.  
  15. <p class="form-row form-row-wide"> 
  16. <select name="calc_shipping_country" id="calc_shipping_country" class="country_to_state" rel="calc_shipping_state"> 
  17. <option value=""><?php _e('Select a country…', 'evolve'); ?></option> 
  18. <?php 
  19. foreach (WC()->countries->get_shipping_countries() as $key => $value) 
  20. echo '<option value="' . esc_attr($key) . '"' . selected(WC()->customer->get_shipping_country(), esc_attr($key), false) . '>' . esc_html($value) . '</option>'; 
  21. ?> 
  22. </select> 
  23. </p> 
  24.  
  25. <p class="form-row form-row-wide"> 
  26. <?php 
  27. $current_cc = WC()->customer->get_shipping_country(); 
  28. $current_r = WC()->customer->get_shipping_state(); 
  29. $states = WC()->countries->get_states($current_cc); 
  30.  
  31. // Hidden Input 
  32. if (is_array($states) && empty($states)) { 
  33. ?><input type="hidden" name="calc_shipping_state" id="calc_shipping_state" placeholder="<?php _e('State / county', 'evolve'); ?>" /><?php 
  34. // Dropdown Input 
  35. } elseif (is_array($states)) { 
  36. ?><span> 
  37. <select name="calc_shipping_state" id="calc_shipping_state" placeholder="<?php _e('State / county', 'evolve'); ?>"> 
  38. <option value=""><?php _e('Select a state…', 'evolve'); ?></option> 
  39. <?php 
  40. foreach ($states as $ckey => $cvalue) 
  41. echo '<option value="' . esc_attr($ckey) . '" ' . selected($current_r, $ckey, false) . '>' . esc_html( $cvalue ) . '</option>'; 
  42. ?> 
  43. </select> 
  44. </span><?php 
  45. // Standard Input 
  46. } else { 
  47. ?><input type="text" class="input-text" value="<?php echo esc_attr($current_r); ?>" placeholder="<?php _e('State / county', 'evolve'); ?>" name="calc_shipping_state" id="calc_shipping_state" /><?php 
  48. ?> 
  49. </p> 
  50.  
  51. <?php if (apply_filters('woocommerce_shipping_calculator_enable_city', false)) : ?> 
  52.  
  53. <p class="form-row form-row-wide"> 
  54. <input type="text" class="input-text" value="<?php echo esc_attr(WC()->customer->get_shipping_city()); ?>" placeholder="<?php _e('City', 'evolve'); ?>" name="calc_shipping_city" id="calc_shipping_city" /> 
  55. </p> 
  56.  
  57. <?php 
  58. endif; 
  59.  
  60. ?> 
  61.  
  62. <p class="form-row form-row-wide"> 
  63. <input type="text" class="input-text" value="<?php echo esc_attr(WC()->customer->get_shipping_postcode()); ?>" placeholder="<?php _e('Postcode / Zip', 'evolve'); ?>" name="calc_shipping_postcode" id="calc_shipping_postcode" /> 
  64. </p> 
  65.  
  66. <?php endif; ?> 
  67.  
  68. <p><button type="submit" name="calc_shipping" value="1" class="button"><?php _e('Update Totals', 'evolve'); ?></button></p> 
  69.  
  70. <?php wp_nonce_field('woocommerce-cart'); ?> 
  71. </div> 
  72. </div> 
  73.  
  74. <?php