Title: [Plugin: ecommerce] new flat rate option
Last modified: August 19, 2016

---

# [Plugin: ecommerce] new flat rate option

 *  [SPEEEED](https://wordpress.org/support/users/speeeed/)
 * (@speeeed)
 * [16 years, 4 months ago](https://wordpress.org/support/topic/plugin-ecommerce-new-flat-rate-option/)
 * Hi,
 * i would like to make new flat rate option in ecommerce for WP.
    I changed few
   string, it also shows me new option, but value for shipping is at both options
   the same.
 * Could you help me with it?
 * Thanks in advance!
 *     ```
       <?php
       class prevzem {
       	var $internal_name, $name;
       	function prevzem () {
       		$this->internal_name = "prevzem";
       		$this->name="Osebni prevzem";
       		$this->is_external=false;
       		return true;
       	}
   
       	function getId() {
       // 		return $this->usps_id;
       	}
   
       	function setId($id) {
       // 		$usps_id = $id;
       // 		return true;
       	}
   
       	function getName() {
       		return $this->name;
       	}
   
       	function getInternalName() {
       		return $this->internal_name;
       	}
   
       	function getForm() {
       		$shipping = get_option('osebni_prevzem');
       		$output = "<tr><td colspan='2'>" . __('If you do not wish to ship to a particular region, leave the field blank. To offer free shipping to a region, enter 0.', 'wpsc') . "</td>";
       		$output .= "<tr><td colspan='1'><strong>Base Local</strong></td>";
   
       		switch(get_option('base_country')) {
       		  case 'NZ':
       			$output .= "<tr class='rate_row'><td>South Island</td><td>$<input type='text' size='4' name='shipping[southisland]' value='{$shipping['southisland']}'></td></tr>";
       			$output .= "<tr class='rate_row'><td>North Island</td><td>$<input type='text' size='4' name='shipping[northisland]'  value='{$shipping['northisland']}'></td></tr>";
       		  break;
   
       		  case 'US':
       			$output .= "<tr class='rate_row'><td>Continental 48 States</td><td>$<input type='text' size='4' name='shipping[continental]' value='{$shipping['continental']}'></td></tr>";
       			$output .= "<tr class='rate_row'><td>All 50 States</td><td>$<input type='text' size='4' name='shipping[all]'  value='{$shipping['all']}'></td></tr>";
       		  break;
   
       		  default:
       			$output .= "<td>$<input type='text' name='shipping[local]' size='4' value='{$shipping['local']}'></td></tr>";
       		  break;
   
       		}
   
       		if (get_option('base_country')=='NZ') {
       		} else {
       		}
       		$output.= "<tr ><td colspan='2'><strong>Base International</strong></td></tr>";
       		$output .= "<tr class='rate_row'><td>North America</td><td>$<input size='4' type='text' name='shipping[northamerica]'  value='{$shipping['northamerica']}'></td></tr>";
       		$output .= "<tr class='rate_row'><td>South America</td><td>$<input size='4' type='text' name='shipping[southamerica]'  value='{$shipping['southamerica']}'></td></tr>";
       		$output .= "<tr class='rate_row'><td>Asia and Pacific</td><td>$<input size='4' type='text' name='shipping[asiapacific]'  value='{$shipping['asiapacific']}'></td></tr>";
       		$output .= "<tr class='rate_row'><td>Europe</td><td>$<input type='text' size='4' name='shipping[europe]'  value='{$shipping['europe']}'></td></tr>";
       		$output .= "<tr class='rate_row'><td>Africa</td><td>$<input type='text' size='4' name='shipping[africa]'  value='{$shipping['africa']}'></td></tr>";
       		return $output;
       	}
   
       	function submit_form() {
       	  if($_POST['shipping'] != null) {
       			$shipping = (array)get_option('osebni_prevzem');
       			$submitted_shipping = (array)$_POST['shipping'];
       			update_option('osebni_prevzem',array_merge($shipping, $submitted_shipping));
       		}
       		return true;
       	}
   
       	function getQuote($for_display = false) {
       		global $wpdb, $wpsc_cart;
       		if (isset($_POST['country'])) {
       			$country = $_POST['country'];
       			$_SESSION['wpsc_delivery_country'] = $country;
       		} else {
       			$country = $_SESSION['wpsc_delivery_country'];
       		}
   
       		if (get_option('base_country') != $country) {
       			$results = $wpdb->get_var("SELECT <code>continent</code> FROM <code>&quot;.WPSC_TABLE_CURRENCY_LIST.&quot;</code> WHERE <code>isocode</code> IN('{$country}') LIMIT 1");
       			$prevzem = get_option('osebni_prevzem');
   
       			if ($prevzem != '') {
   
       				if($_SESSION['quote_shipping_method'] == $this->internal_name) {
       					if($_SESSION['quote_shipping_option'] != "Osebni prevzem") {
       						$_SESSION['quote_shipping_option'] = null;
       					}
       				}
   
       				if (strlen($prevzem[$results]) > 0) return array("Osebni prevzem"=>(float)$prevzem[$results]);
       			}
       		} else {
       			$prevzem = get_option('osebni_prevzem');
       			$shipping_quotes = array();
       			switch($country) {
       			  case 'NZ':
       				if (strlen($prevzem['northisland']) > 0) $shipping_quotes["North Island"] = (float)$prevzem['northisland'];
       				if (strlen($prevzem['southisland']) > 0) $shipping_quotes["South Island"] = (float)$prevzem['southisland'];
       			  break;
   
       			  case 'US':
       				if (strlen($prevzem['continental']) > 0) $shipping_quotes["Continental 48 States"] = (float)$prevzem['continental'];
       				if (strlen($prevzem['all']) > 0) $shipping_quotes["All 50 States"] = (float)$prevzem['all'];
       			  break;
   
       			  default:
       				if (strlen($prevzem['local']) > 0) $shipping_quotes["Local Shipping"] = (float)$prevzem['local'];			  break;
       			}
       			if($_SESSION['quote_shipping_method'] == $this->internal_name) {
       			  $shipping_options = array_keys($shipping_quotes);
       			  if(array_search($_SESSION['quote_shipping_option'], $shipping_options) === false) {
       					$_SESSION['quote_shipping_option'] = null;
       			  }
       			}
   
       			return $shipping_quotes;
       		}
       	}
   
       	function get_item_shipping($unit_price, $quantity, $weight, $product_id) {
       		global $wpdb;
           if(is_numeric($product_id) && (get_option('do_not_use_shipping') != 1)) {
       			$country_code = $_SESSION['wpsc_delivery_country'];
             $product_list = $wpdb->get_row("SELECT * FROM <code>&quot;.WPSC_TABLE_PRODUCT_LIST.&quot;</code> WHERE <code>id</code>='{$product_id}' LIMIT 1",ARRAY_A);
             if($product_list['no_shipping'] == 0) {
               //if the item has shipping
               //exit("<pre>".print_r($country_code,true)."</pre>");
               if($country_code == get_option('base_country')) {
                 $additional_shipping = $product_list['pnp'];
       				} else {
                 $additional_shipping = $product_list['international_pnp'];
       				}
               $shipping = $quantity * $additional_shipping;
       			} else {
               //if the item does not have shipping
               $shipping = 0;
       			}
       		} else {
             //if the item is invalid or all items do not have shipping
       			$shipping = 0;
       		}
           return $shipping;
       	}
   
       	function get_cart_shipping($total_price, $weight) {
       	  return $output;
       	}
       }
       $prevzem = new prevzem();
       ```
   

The topic ‘[Plugin: ecommerce] new flat rate option’ is closed to new replies.

 * 0 replies
 * 1 participant
 * Last reply from: [SPEEEED](https://wordpress.org/support/users/speeeed/)
 * Last activity: [16 years, 4 months ago](https://wordpress.org/support/topic/plugin-ecommerce-new-flat-rate-option/)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
