Help with wp-weight-rate.php modification

Hi, i am trying to hack the wp-weight-rate plugin so i can have more then one extra box just like Internationl:
i.e If weight is [numer] and above. Shipping Cost - In Country:$ Internatioanl [$] etc.
I need to add several other places just like Internatioanl ( regions in my case for NZ )
Here's my code so far, what am i missing?
( when i save this the values don't get saved; that i put in for my regions). I have added another case and am looping through my NZ region array

switch ($settings['base_country'])
        {
            case 'NZ':
				?>
					<?php
					for ( $i = 0; $i < $settings['shipping']['weight-rate']['rowcount']; $i++ )
					{
					?>

					<tr>
						<td scope="row">
							<?php _e('If weight is ', 'mp'); ?><input type="text" name="mp[shipping][weight-rate][0][minweight]" value="0.01" size="5" maxlength="10" disabled="disabled" /><?php _e(' and above.', 'mp'); ?>
							<?php _e('Shipping Cost - In Country:', 'mp'); echo $mp->format_currency(); ?><input on type="text" name="mp[shipping][weight-rate][0][in_country]" value="<?php echo esc_attr($settings['shipping']['weight-rate']['0']['in_country']); ?>" size="5" maxlength="10" />
							<?php _e('European Union:', 'mp'); echo $mp->format_currency(); ?><input on type="text" name="mp[shipping][weight-rate][0][eu]" value="<?php echo esc_attr($settings['shipping']['weight-rate']['0']['eu']); ?>" size="5" maxlength="10" />
							<?php
								$count = 0; //count($nzRegions);
								$keyCnt = 0;
								foreach ($nzRegions as $key => $value)
							    {
									$cnt++;
									$keyCnt++;

									_e($value, 'mp'); echo $mp->format_currency(); ?>
									<input on
									type="text"
									name="mp[shipping][nick][<?php echo $keyCnt?>][<?php echo $key?>]"
									value="<?php echo esc_attr($settings['shipping']['nick']['$keyCnt']['$key']); ?>"
									size="5"
									maxlength="10" />

								<?php
									if($cnt >= 5 )
									{
										echo "";
										$cnt = 0;
									}
								}
							    ?>
						</td>
					</tr>
					<?php
					}
					?>

and here in the NZ region array:

$nzRegions = array(
"NZ" => "New Zealand",
"NZ-AUK" => "Auckland",
"NZ-BOP" => "Bay of Plenty - Te Moana a Toi Te Huatahi",
"NZ-BOP" => "Bay of Plenty - Te Moana a Toi Te Huatahi",
"NZ-CAN" => "Canterbury - Waitaha",
"NZ-HKB" => "Hawke's Bay - Te Matau a Maui",
"NZ-MWT" => "Manawatu-Wanganui - Manawatu Whanganui",
"NZ-NTL" => "Northland - Te Tai tokerau",
"NZ-OTA" => "Otago - O Takou",
"NZ-STL" => "Southland - Murihiku",
"NZ-TKI" => "Taranaki - Taranaki",
"NZ-WKO" => "Waikato - Waikato",
"NZ-WGN" => "Wellington - Te Whanga-nui-a-Tara",
"NZ-WTC" => "West Coast - Te Taihau a uru",
"NZ-GIS" => "Gisborne District - Turanga nui a Kiwa",
"NZ-MBH" => "Marlborough District",
"NZ-NSN" => "Nelson City - Whakatu",
"NZ-TAS" => "Tasman District",
"NZ-CIT" => "Chatham Islands");

PLease help as i must crack this if i am going to contine to use your plugin for this site and several others
I am quite new to PHP but knowing c# js, and Java help.

Thanks Nick

  • aecnu

    Greetings Nick,

    Thank you for this great coding question, it is certainly appreciated.

    Not being a coder myself I have no idea what is wrong with your script and since it is involving custom coding it is not within the scope of our normal support parameters.

    However, I will see if I can get the lead developer @Aaron in here with his invaluable insight into this plugin for his advice/advise for us.

    Though this may take a bit longer then a normal ticket, I will try to get him in here asap.

    Thank you for being a WPMU Dev Community Member!

    Cheers, Joe

  • nick_gray

    Hi Aaron, thanks a lot for that i finally got it to save, and have formatted the display nicely.
    1. I was wondering where does it save the data ?
    2. now that i allow regions to be added i need to allow the buyer to select a region form a drop down list and then have it calculate the shipping. ( how do i do this ?)
    3. when the user goes to the check out now page ( there is a region list box there - i need that to automatically select the region that was selected on the shipping page )

    thanks heaps for you help.

    Once i complete this code I will post it back for the community, and maybe you could make it part of the next release.

    Here's my code so far for the community if needed:

    `function shipping_settings_box($settings) {
    global $mp;
    $nzRegions = array(
    "NZ-AUK" => "Auckland",
    "NZ-BOP" => "Bay of Plenty - Te Moana a Toi Te Huatahi",
    "NZ-BOP" => "Bay of Plenty - Te Moana a Toi Te Huatahi",
    "NZ-CAN" => "Canterbury - Waitaha",
    "NZ-HKB" => "Hawke's Bay - Te Matau a Maui",
    "NZ-MWT" => "Manawatu-Wanganui - Manawatu Whanganui",
    "NZ-NTL" => "Northland - Te Tai tokerau",
    "NZ-OTA" => "Otago - O Takou",
    "NZ-STL" => "Southland - Murihiku",
    "NZ-TKI" => "Taranaki - Taranaki",
    "NZ-WKO" => "Waikato - Waikato",
    "NZ-WGN" => "Wellington - Te Whanga-nui-a-Tara",
    "NZ-WTC" => "West Coast - Te Taihau a uru",
    "NZ-GIS" => "Gisborne District - Turanga nui a Kiwa",
    "NZ-MBH" => "Marlborough District",
    "NZ-NSN" => "Nelson City - Whakatu",
    "NZ-TAS" => "Tasman District",
    "NZ-CIT" => "Chatham Islands");
    ?>
    <script type="text/javascript">
    jQuery(document).ready(function ($) {

    $("#mp-weight-rate-rows").change(function() {
    $("#mp-shipping-form").submit();
    });
    });
    </script>
    <div id="mp_weight_rate" class="postbox">
    <h3 class='hndle'><span><?php _e('Weight Rate Settings', 'mp'); ?></span></h3>
    <div class="inside">
    <span class="description"><?php _e('Be sure to enter a shipping price for every option or those customers may get free shipping.', 'mp') ?></span>
    <table class="form-table">
    <tr>
    <td scope="row"><?php _e('Number of Layers:', 'mp');?>

    <select name="mp[shipping][weight-rate][rowcount]" id="mp-weight-rate-rows">
    <?php
    for($k = 1; $k<=20; $k++)
    {
    ?>
    <option value="<?php echo $k; ?>" <?php selected($settings['shipping']['weight-rate']['rowcount'], $k); ?>><?php echo $k; ?>
    </option>
    <?php
    }
    ?>
    </select>
    </td>
    </tr>
    <tr>
    <th>
    <?php _e('Each layer must be a higher weight then the one above it.', 'mp') ?>
    </th>
    </tr>
    <?php
    switch ($settings['base_country'])
    {
    case 'NZ':
    ?>
    <?php

    for ( $i = 0; $i < $settings['shipping']['weight-rate']['rowcount']; $i++ )
    {

    ?>
    <tr>
    <td scope="row">
    <?php _e('If weight is ', 'mp');
    // show non-editable input box with a fixed weight to start off with ( for first entry )
    if( $i == 0) { ?>
    <input type="text" name="mp[shipping][weight-rate][0][minweight]" value="0.01" size="5" maxlength="10" disabled="disabled" /><?php _e(' and above.', 'mp'); ?>
    <?php

    }else{ // show editable input box that suer can put weight into
    ?>
    <input type="text" name="mp[shipping][weight-rate][<?php echo $i; ?>][minweight]" value="<?php echo esc_attr($settings['shipping']['weight-rate'][$i]['minweight']); ?>" size="5" maxlength="10" />

    <?php }
    _e('Shipping Cost - In Region:', 'mp');
    ?>

    <?php
    $cnt = 0;
    $keyCnt = 0;
    foreach ($nzRegions as $key => $value)
    {
    $cnt++;
    $keyCnt = $i; //++;

    $keyValue = esc_attr($settings['shipping']['weight-rate'][$keyCnt][$key]);
    //$keyValue = esc_attr($settings['shipping']['weight-rate']['0']['NZ-AUK']) ;

    _e($key, 'mp');?>
    <input on
    title=" <?php echo $value?>"
    type="text"
    name="mp[shipping][weight-rate][<?php echo $keyCnt?>][<?php echo $key?>]"
    value="<?php echo $keyValue; ?>"
    size="5"
    maxlength="10" />
    <?php
    if($cnt >= 9 )
    {
    echo "";
    $cnt = 0;
    }
    }
    ?>
    </td>
    </tr>
    <?php
    }
    ?>

    <?php

    break;
    case 'US':
    ?>

  • nick_gray

    Thanks heaps man for the advice!!!!!!! I have almost got it going. and things look good as i will be breaking into the Taiwan and China market once my system is up. Big market and i'm sure this is the right plugin for the job, nice neat code.

    Anyway i said i almost got it going.
    If i am logged in it works : works means it shows my regions in a option list box on the first checkout page and Selects the correct region, and calculates the shipping as expected.

    But if i'm not logged in the $_POST[] does not seem to have my nzRegions in it.
    If i put the $_POST["nzRegions"] in process_shipping_form(). it never works and i don't get the value even if im logged in.

    But if i put $_POST["nzRegions"] in process_shipping_form() it works if i'm logged in but not if i'm not logged in.

    Any ideas, i'm ripping my heir out over this one ?

    if i need to save this to a session or cookie how do i do that ? but i don't think that is my problem.

    Please checkout http://pitahouse.onecent.co.nz and add some products to the cart and click checkout and select a region. This will be my first customer using MarketPress. BTW i am using MarketPress on a mufti site if that makes a difference.

    I have added, my list box to the template functions php. below:
    ( so the calculate_shipping method can do its work )

    //Prints cart table, for internal use
    function _mp_cart_table($type = 'checkout', $echo = false) {
      global $mp, $blog_id;
      $blog_id = (is_multisite()) ? $blog_id : 1;
      $current_blog_id = $blog_id;
    
    	$global_cart = $mp->get_cart_contents(true);
      if (!$mp->global_cart)  //get subset if needed
      	$selected_cart[$blog_id] = $global_cart[$blog_id];
      else
        $selected_cart = $global_cart;
    
      $content = '';
      if ($type == 'checkout-edit') {
        $content .= apply_filters( 'mp_cart_updated_msg', '' );
    
        $content .= '<form id="mp_cart_form" method="post" action="">';
        $content .= '<table class="mp_cart_contents"><thead><tr>';
        $content .= '<th class="mp_cart_col_product" colspan="2">'.__('Item:', 'mp').'</th>';
        $content .= '<th class="mp_cart_col_price">'.__('Price:', 'mp').'</th>';
        $content .= '<th class="mp_cart_col_quant">'.__('Quantity:', 'mp').'</th></tr></thead><tbody>';
    
        $totals = array();
        $shipping_prices = array();
        $tax_prices = array();
        foreach ($selected_cart as $bid => $cart) {
    
    			if (is_multisite())
            switch_to_blog($bid);
    
          foreach ($cart as $product_id => $variations) {
            foreach ($variations as $variation => $data) {
              $totals[] = $mp->before_tax_price($data['price'], $product_id) * $data['quantity'];
    
              $content .=  '<tr>';
              $content .=  '  <td class="mp_cart_col_thumb">' . mp_product_image( false, 'widget', $product_id, 50 ) . '</td>';
              $content .=  '  <td class="mp_cart_col_product_table"><a href="' . apply_filters('mp_product_url_display_in_cart', $data['url'], $product_id) . '">' . apply_filters('mp_product_name_display_in_cart', $data['name'], $product_id) . '</a>' . '</td>'; // Added WPML
              $content .=  '  <td class="mp_cart_col_price">' . $mp->format_currency('', $data['price'] * $data['quantity']) . '</td>';
              $content .=  '  <td class="mp_cart_col_quant"><input type="text" size="2" name="quant[' . $bid . ':' . $product_id . ':' . $variation . ']" value="' . $data['quantity'] . '" /> <label><input type="checkbox" name="remove[]" value="' . $bid . ':' . $product_id . ':' . $variation . '" /> ' . __('Remove', 'mp') . '</label></td>';
              $content .=  '</tr>';
            }
          }
    
          if ( ($shipping_price = $mp->shipping_price()) !== false )
            $shipping_prices[] = $shipping_price;
    
          if ( ($tax_price = $mp->tax_price()) !== false )
            $tax_prices[] = $tax_price;
        }
        //go back to original blog
        if (is_multisite())
          switch_to_blog($current_blog_id);
    
        $total = array_sum($totals);
    	  # nick gray change, i need this to cal shipping
    	  $content .= apply_filters( 'mp_checkout_shipping_field', '' );

    ==================================================

    and here's my version of the mp-weight rate php:

    <?php
    
    /*
    MarketPress Weight-Rate Shipping Plugin
    Author: Nick Bunn (Salty Dog Interactive)
    Version: 1.1
    */
    
    class MP_Shipping_Weight_Rate extends MP_Shipping_API {
    
    	//private shipping method name. Lowercase alpha (a-z) and dashes (-) only please!
    	var $plugin_name = 'weight-rate';
    
    	//public name of your method, for lists and such.
    	var $public_name = '';
    
    	//set to true if you need to use the shipping_metabox() method to add per-product shipping options
    	var $use_metabox = false;
    
    	//set to true if you want to add per-product weight shipping field
    	var $use_weight = true;
    
    // With PHP 5 property and method visibility (public, protected and private) was introduced and thus var is deprecated.
    	private	$nzRegion;
    
    	private	$nzRegions = array(
      "AUK" => "Auckland",
      "BOP" => "Bay of Plenty - Te Moana a Toi Te Huatahi",
      "CAN" => "Canterbury - Waitaha",
      "HKB" => "Hawke's Bay - Te Matau a Maui",
      "MWT" => "Manawatu-Wanganui - Manawatu Whanganui",
      "NTL" => "Northland - Te Tai tokerau",
      "OTA" => "Otago - O Takou",
      "STL" => "Southland - Murihiku",
      "TKI" => "Taranaki - Taranaki",
      "WKO" => "Waikato - Waikato",
      "WGN" => "Wellington - Te Whanga-nui-a-Tara",
      "WTC" => "West Coast - Te Taihau a uru",
      "GIS" => "Gisborne District - Turanga nui a Kiwa",
      "MBH" => "Marlborough District",
      "NSN" => "Nelson City - Whakatu",
      "TAS" => "Tasman District",
      "CIT" => "Chatham Islands");
    
      /**
       * Runs when your class is instantiated. Use to setup your plugin instead of __construct()
       */
    	function on_creation() {
    		//declare here for translation
    	    $this->public_name = __('Weight Rate', 'mp');
    	}
    
      /**
       * Echo anything you want to add to the top of the shipping screen
       */
    	function before_shipping_form($content) {
    		return $content;
      }
    
      /**
       * Echo anything you want to add to the bottom of the shipping screen
       */
    	function after_shipping_form($content) {
    		return $content;
      }
    
      /**
       * Echo a table row with any extra shipping fields you need to add to the shipping checkout form
       */
    function extra_shipping_field($content)
    {
    
    	$content = '<tr><td align="right">nzRegion[' . $this->nzRegion . "]</td>'";
    
    	$content .= '<td><select name="nzRegions">';
    
    	foreach ($this->nzRegions as $key => $value)
    	{
    		if( $key == $this->nzRegion)
    		{
    			$content .= '<option selected value="' . $key . '">' . $value . "</option>\n";
    		}
    		else
    		{
    			$content .= '<option value="' . $key . '">' . $value . "</option>\n";
    		}
    
    	}
    	$content .= '</select></td></tr>';
    
    	return $content;
    
    	// return $content . '<tr><input type="TEXT" VALUE="test 123"></tr>';
    }
    
    	  /**
       * Use this to process any additional field you may add. Use the $_POST global,
       *  and be sure to save it to both the cookie and usermeta if logged in.
       */
    
    function process_shipping_form()
    {
    
    		#if (isset($_POST['nzRegions']))
    		#{
    	#		$this->nzRegion = $_POST["nzRegions"];
    	#		$_SESSION['mp_shipping_info']['nzRegion'] = trim($_POST['nzRegions']);
    	#	}	
    
    	#SESSION['mp_shipping_info']['phone'] : $meta['phone'];
    	#isset($_POST['country'])
    	#mp_province_field
     }
    
    	/**
       * Echo a settings meta box with whatever settings you need for you shipping module.
       *  Form field names should be prefixed with mp[shipping][plugin_name], like "mp[shipping][plugin_name][mysetting]".
       *  You can access saved settings via $settings array.
       */
    	function shipping_settings_box($settings)
    	{
    	global $mp;
    
    	?>
        <script type="text/javascript">
          	  jQuery(document).ready(function ($) {
    
                $("#mp-weight-rate-rows").change(function() {
                  $("#mp-shipping-form").submit();
            		});
          		});
        </script>
        <div id="mp_weight_rate" class="postbox">
          <h3 class='hndle'><span><?php _e('Weight Rate Settings', 'mp'); ?></span></h3>
          <div class="inside">
            <span class="description"><?php _e('Be sure to enter a shipping price for every option or those customers may get free shipping.', 'mp') ?></span>
            <table class="form-table">
    			<tr>
          		<td scope="row"><?php _e('Number of Layers:', 'mp');?>
    
          			<select name="mp[shipping][weight-rate][rowcount]" id="mp-weight-rate-rows">
          				<?php
          				for($k = 1; $k<=20; $k++)
          				{
          				?>
                        	<option value="<?php echo $k; ?>" <?php selected($settings['shipping']['weight-rate']['rowcount'], $k); ?>><?php echo $k; ?>
                        	</option>
            			<?php
            			}
            			?>
                     </select>
             	</td>
         	</tr>
         	<tr>
         		<th>
         		<?php _e('Each layer must be a higher weight then the one above it.', 'mp') ?>
         		</th>
         	</tr>
            <?php
    		switch ($settings['base_country'])
            {
                case 'NZ':
    				?>
    					<?php
    
    			for ( $i = 0; $i < $settings['shipping']['weight-rate']['rowcount']; $i++ )
    					{
    
    					?>
    					<tr>
    						<td scope="row">
    							<?php _e('If weight is ', 'mp');
    							// show non-editable input box with a fixed weight to start off with ( for first entry )
    							if( $i == 0) { ?>
    								<input type="text" name="mp[shipping][weight-rate][0][minweight]" value="0.01" size="5" maxlength="10" disabled="disabled" /><?php _e(' and above.', 'mp'); ?>
    								<?php
    
    							}else{ // show editable input box that suer can put weight into
    							?>
    								<input type="text" name="mp[shipping][weight-rate][<?php echo $i; ?>][minweight]" value="<?php echo esc_attr($settings['shipping']['weight-rate'][$i]['minweight']); ?>" size="5" maxlength="10" />
    
    							<?php }
    								_e('Shipping Cost - In Region:', 'mp');
    							?>
    
    							<BR>
    
    							<?php
    								$cnt = 0;
    								$keyCnt = 0;
    								foreach ($this->nzRegions as $key => $value)
    							    {
    									$cnt++;
    									$keyCnt = $i; //++;
    
    									$keyValue = esc_attr($settings['shipping']['weight-rate'][$keyCnt][$key]);
    									//$keyValue = esc_attr($settings['shipping']['weight-rate']['0']['NZ-AUK']) ;
    
    									_e($key, 'mp');?>
    									<input on
    									title=" <?php echo $value?>"
    									type="text"
    									name="mp[shipping][weight-rate][<?php echo $keyCnt?>][<?php echo $key?>]"
    									value="<?php echo $keyValue; ?>"
    									size="5"
    									maxlength="10" />
    							  <?php
    									if($cnt >= 9 )
    									{
    										echo "<BR>";
    										$cnt = 0;
    									}
    								}
    							    ?>
    						</td>
    					</tr>
    					<?php
    					}
    					?>
    
    					<?php
    
    			break;
    			case 'US':
            ?>
                    <tr>
                        <td scope="row"><?php _e('If weight is ', 'mp'); ?><input type="text" name="mp[shipping][weight-rate][0][minweight]" value="0.01" size="5" maxlength="10" disabled="disabled" /><?php _e(' and above.', 'mp'); ?>
                                              <?php _e('Shipping Cost - Lower 48 States:', 'mp'); echo $mp->format_currency(); ?><input on type="text" name="mp[shipping][weight-rate][0][lower_48]" value="<?php echo esc_attr($settings['shipping']['weight-rate']['0']['lower_48']); ?>" size="5" maxlength="10" />
                                              <?php _e('Hawaii and Alaska:', 'mp'); echo $mp->format_currency(); ?><input on type="text" name="mp[shipping][weight-rate][0][hi_ak]" value="<?php echo esc_attr($settings['shipping']['weight-rate']['0']['hi_ak']); ?>" size="5" maxlength="10" />
                                              <?php _e('Canada:', 'mp'); echo $mp->format_currency(); ?><input on type="text" name="mp[shipping][weight-rate][0][canada]" value="<?php echo esc_attr($settings['shipping']['weight-rate']['0']['canada']); ?>" size="5" maxlength="10" />
                                              <?php _e('International:', 'mp'); echo $mp->format_currency(); ?><input on type="text" name="mp[shipping][weight-rate][0][international]" value="<?php echo esc_attr($settings['shipping']['weight-rate']['0']['international']); ?>" size="5" maxlength="10" />
                        </td>
                    </tr>
                        <?php
                        for ( $i = 1; $i < $settings['shipping']['weight-rate']['rowcount']; $i++ )
                        {
                        ?>
                            <tr>
                                <td scope="row">
    								<?php _e('If weight is ', 'mp'); ?><input type="text" name="mp[shipping][weight-rate][<?php echo $i; ?>][minweight]" value="<?php echo esc_attr($settings['shipping']['weight-rate'][$i]['minweight']); ?>" size="5" maxlength="10" /><?php _e(' and above.', 'mp'); ?>
                                    <?php _e('Shipping Cost - Lower 48 States:', 'mp'); echo $mp->format_currency(); ?><input on type="text" name="mp[shipping][weight-rate][<?php echo $i?>][lower_48]" value="<?php echo esc_attr($settings['shipping']['weight-rate'][$i]['lower_48']); ?>" size="5" maxlength="10" />
                                    <?php _e('Hawaii and Alaska:', 'mp'); echo $mp->format_currency(); ?><input on type="text" name="mp[shipping][weight-rate][<?php echo $i?>][hi_ak]" value="<?php echo esc_attr($settings['shipping']['weight-rate'][$i]['hi_ak']); ?>" size="5" maxlength="10" />
                                    <?php _e('Canada:', 'mp'); echo $mp->format_currency(); ?><input on type="text" name="mp[shipping][weight-rate][<?php echo $i?>][canada]" value="<?php echo esc_attr($settings['shipping']['weight-rate'][$i]['canada']); ?>" size="5" maxlength="10" />
                                    <?php _e('International:', 'mp'); echo $mp->format_currency(); ?><input on type="text" name="mp[shipping][weight-rate][<?php echo $i?>][international]" value="<?php echo esc_attr($settings['shipping']['weight-rate'][$i]['international']); ?>" size="5" maxlength="10" />
                                </td>
                            </tr>
                        <?php
                        }
    			break;
    			case 'CA':
    					?>
    				<tr>
    					<td scope="row">
    						<?php _e('If weight is ', 'mp'); ?><input type="text" name="mp[shipping][weight-rate][0][minweight]" value="0.01" size="5" maxlength="10" disabled="disabled" /><?php _e(' and above.', 'mp'); ?>
    						<?php _e('Shipping Cost - In Country:', 'mp'); echo $mp->format_currency(); ?><input on type="text" name="mp[shipping][weight-rate][0][in_country]" value="<?php echo esc_attr($settings['shipping']['weight-rate']['0']['in_country']); ?>" size="5" maxlength="10" />
    						<?php _e('United States:', 'mp'); echo $mp->format_currency(); ?><input on type="text" name="mp[shipping][weight-rate][0][usa]" value="<?php echo esc_attr($settings['shipping']['weight-rate']['0']['usa']); ?>" size="5" maxlength="10" />
    						<?php _e('International:', 'mp'); echo $mp->format_currency(); ?><input on type="text" name="mp[shipping][weight-rate][0][international]" value="<?php echo esc_attr($settings['shipping']['weight-rate']['0']['international']); ?>" size="5" maxlength="10" />
    					</td>
    				</tr>
    				<?php
    				for ( $i = 1; $i < $settings['shipping']['weight-rate']['rowcount']; $i++ )
    				{
    				?>
    					<tr>
    						<td scope="row">
    							<?php _e('If weight is ', 'mp'); ?><input type="text" name="mp[shipping][weight-rate][<?php echo $i; ?>][minweight]" value="<?php echo esc_attr($settings['shipping']['weight-rate'][$i]['minweight']); ?>" size="5" maxlength="10" /><?php _e(' and above.', 'mp'); ?>
    							<?php _e('Shipping Cost - In Country:', 'mp'); echo $mp->format_currency(); ?><input on type="text" name="mp[shipping][weight-rate][<?php echo $i?>][in_country]" value="<?php echo esc_attr($settings['shipping']['weight-rate'][$i]['in_country']); ?>" size="5" maxlength="10" />
    							<?php _e('United States:', 'mp'); echo $mp->format_currency(); ?><input on type="text" name="mp[shipping][weight-rate][<?php echo $i?>][usa]" value="<?php echo esc_attr($settings['shipping']['weight-rate'][$i]['usa']); ?>" size="5" maxlength="10" />
    							<?php _e('International:', 'mp'); echo $mp->format_currency(); ?><input on type="text" name="mp[shipping][weight-rate][<?php echo $i?>][international]" value="<?php echo esc_attr($settings['shipping']['weight-rate'][$i]['international']); ?>" size="5" maxlength="10" />
    						</td>
    					</tr>
    				<?php
    				}
    			break;
    			default:
    				if ( in_array($settings['base_country'], $mp->eu_countries) )
    				{
    				?>
    					<tr>
    
    						<td scope="row">
    							<?php _e('If weight is ', 'mp'); ?><input type="text" name="mp[shipping][weight-rate][0][minweight]" value="0.01" size="5" maxlength="10" disabled="disabled" /><?php _e(' and above.', 'mp'); ?>
    							<?php _e('Shipping Cost - In Country:', 'mp'); echo $mp->format_currency(); ?><input on type="text" name="mp[shipping][weight-rate][0][in_country]" value="<?php echo esc_attr($settings['shipping']['weight-rate']['0']['in_country']); ?>" size="5" maxlength="10" />
    							<?php _e('European Union:', 'mp'); echo $mp->format_currency(); ?><input on type="text" name="mp[shipping][weight-rate][0][eu]" value="<?php echo esc_attr($settings['shipping']['weight-rate']['0']['eu']); ?>" size="5" maxlength="10" />
    							<?php _e('International:', 'mp'); echo $mp->format_currency(); ?><input on type="text" name="mp[shipping][weight-rate][0][international]" value="<?php echo esc_attr($settings['shipping']['weight-rate']['0']['international']); ?>" size="5" maxlength="10" />
    						</td>
    					</tr>
    					<?php
    					for ( $i = 1; $i < $settings['shipping']['weight-rate']['rowcount']; $i++ )
    					{
    					?>
    						<tr>
    							<td scope="row">
    								<?php _e('If weight is ', 'mp'); ?><input type="text" name="mp[shipping][weight-rate][<?php echo $i; ?>][minweight]" value="<?php echo esc_attr($settings['shipping']['weight-rate'][$i]['minweight']); ?>" size="5" maxlength="10" /><?php _e(' and above.', 'mp'); ?>
    							  	<?php _e('Shipping Cost - In Country:', 'mp'); echo $mp->format_currency(); ?><input on type="text" name="mp[shipping][weight-rate][<?php echo $i?>][in_country]" value="<?php echo esc_attr($settings['shipping']['weight-rate'][$i]['in_country']); ?>" size="5" maxlength="10" />
    								<?php _e('European Union:', 'mp'); echo $mp->format_currency(); ?><input on type="text" name="mp[shipping][weight-rate][<?php echo $i?>][eu]" value="<?php echo esc_attr($settings['shipping']['weight-rate'][$i]['eu']); ?>" size="5" maxlength="10" />
    								<?php _e('International:', 'mp'); echo $mp->format_currency(); ?><input on type="text" name="mp[shipping][weight-rate][<?php echo $i?>][international]" value="<?php echo esc_attr($settings['shipping']['weight-rate'][$i]['international']); ?>" size="5" maxlength="10" />
    						  	</td>
    					  	</tr>
    					<?php
    					}
    				}
    				else
    				{
    					?>
    					<tr>
    						<td scope="row">
    							<?php _e('If weight is ', 'mp'); ?><input type="text" name="mp[shipping][weight-rate][0][minweight]" value="0.01" size="5" maxlength="10" disabled="disabled" /><?php _e(' and above.', 'mp'); ?>
    							<?php _e('Shipping Cost - In Country:', 'mp'); echo $mp->format_currency(); ?><input on type="text" name="mp[shipping][weight-rate][0][in_country]" value="<?php echo esc_attr($settings['shipping']['weight-rate']['0']['in_country']); ?>" size="5" maxlength="10" />
    							<?php _e('International:', 'mp'); echo $mp->format_currency(); ?><input on type="text" name="mp[shipping][weight-rate][0][international]" value="<?php echo esc_attr($settings['shipping']['weight-rate']['0']['international']); ?>" size="5" maxlength="10" />
    						</td>
    					</tr>
    					<?php
    					for ( $i = 1; $i < $settings['shipping']['weight-rate']['rowcount']; $i++ )
    					{
    					?>
    						<tr>
    							<td scope="row">
    								<?php _e('If weight is ', 'mp'); ?><input type="text" name="mp[shipping][weight-rate][<?php echo $i; ?>][minweight]" value="<?php echo esc_attr($settings['shipping']['weight-rate'][$i]['minweight']); ?>" size="5" maxlength="10" /><?php _e(' and above.', 'mp'); ?>
    							  	<?php _e('Shipping Cost - In Country:', 'mp'); echo $mp->format_currency(); ?><input on type="text" name="mp[shipping][weight-rate][<?php echo $i?>][in_country]" value="<?php echo esc_attr($settings['shipping']['weight-rate'][$i]['in_country']); ?>" size="5" maxlength="10" />
    								<?php _e('International:', 'mp'); echo $mp->format_currency(); ?><input on type="text" name="mp[shipping][weight-rate][<?php echo $i?>][international]" value="<?php echo esc_attr($settings['shipping']['weight-rate'][$i]['international']); ?>" size="5" maxlength="10" />
    						  	</td>
    					  	</tr>
    					<?php
    					}
    				}
    			}
    					?>
    
            </table>
          </div>
        </div>
        <?php
    
      }
    
      /**
       * Filters posted data from your form. Do anything you need to the $settings['shipping']['plugin_name']
       *  array. Don't forget to return!
       */
    	function process_shipping_settings($settings) {
    
    	return $settings;
      }
    
      /**
       * Echo any per-product shipping fields you need to add to the product edit screen shipping metabox
       *
       * @param array $shipping_meta, the contents of the post meta. Use to retrieve any previously saved product meta
       * @param array $settings, access saved settings via $settings array.
       */
    	function shipping_metabox($shipping_meta, $settings) {
    
      }
    
      /**
       * Save any per-product shipping fields from the shipping metabox using update_post_meta
       *
       * @param array $shipping_meta, save anything from the $_POST global
       * return array $shipping_meta
       */
    	function save_shipping_metabox($shipping_meta) {
    
        return $shipping_meta;
      }
    
      /**
    * Use this function to return your calculated price as an integer or float
    *
    * @param int $price, always 0. Modify this and return
    * @param float $total, cart total after any coupons and before tax
    * @param array $cart, the contents of the shopping cart for advanced calculations
    * @param string $address1
    * @param string $address2
    * @param string $city
    * @param string $state, state/province/region
    * @param string $zip, postal code
    * @param string $country, ISO 3166-1 alpha-2 country code
    * @param string $selected_option, if a calculated shipping module, passes the currently selected sub shipping option if set
    *
    * return float $price
    */
    function calculate_shipping($price, $total, $cart, $address1, $address2, $city, $state, $zip, $country, $selected_option) {
    			global $mp;
        $settings = get_option('mp_settings');
    
        //calculate extra shipping
        $weights = array();
        foreach ($cart as $product_id => $variations) {
    	    $shipping_meta = get_post_meta($product_id, 'mp_shipping', true);
    			foreach ($variations as $variation => $data) {
    			  if (!$data['download'])
    	      	$weights[] = $shipping_meta['weight'] * $data['quantity'];
    			}
        }
        $totalweight = array_sum($weights);
    
        switch ($settings['base_country'])
        {
    		case 'US':
    			for ($i = $settings['shipping']['weight-rate']['rowcount'] - 1; $i >= 0; $i--)
    		  	{
    			  	if ($totalweight >= $settings['shipping']['weight-rate'][$i]['minweight'])
    			  	{
    				  	if ($country == 'US')
    				  	{
    					  	if($state == 'HI' || $state == 'AK')
    						  	$price = $settings['shipping']['weight-rate'][$i]['hi_ak'];
    					  	else
    						  	$price = $settings['shipping']['weight-rate'][$i]['lower_48'];
    				  	}
    				  	else if ($country == 'CA')
    						$price = $settings['shipping']['weight-rate'][$i]['canada'];
    				  	else
    						$price = $settings['shipping']['weight-rate'][$i]['international'];
    						break;
    			  	}
    		  	}
    		break;
    		case 'CA':
    			for ($i = $settings['shipping']['weight-rate']['rowcount'] - 1; $i >= 0; $i--)
    		  	{
    				if ($totalweight >= $settings['shipping']['weight-rate'][$i]['minweight'])
    			  	{
    					if ($country == 'CA')
    						$price = $settings['shipping']['weight-rate'][$i]['in_country'];
    					else if ($country == 'US')
    						$price = $settings['shipping']['weight-rate'][$i]['usa'];
    					else
    						$price = $settings['shipping']['weight-rate'][$i]['international'];
    					break;
    				}
    		  }
    		break;
    		case 'NZ':
    				$this->nzRegion = $_POST["nzRegions"]; #$GLOBALS["nzRegion"];	
    
    				for ($i = $settings['shipping']['weight-rate']['rowcount'] - 1; $i >= 0; $i--)
    				{
    					#if ($totalweight >= $settings['shipping']['weight-rate'][$i]['minweight'])
    					#{
    						$price = $settings['shipping']['weight-rate'][$i][ $this->nzRegion ]; 
    
    						break;
    					#}
    				}
    				#$price = 666;
    
    		break;
    
    		default:
    			for ($i = $settings['shipping']['weight-rate']['rowcount'] - 1; $i >= 0; $i--)
    		  	{
    				if ($totalweight >= $settings['shipping']['weight-rate'][$i]['minweight'])
    			  	{
    					if ( in_array($settings['base_country'], $mp->eu_countries) )  //in european union
    				  	{
    						if ($country == $settings['base_country'])
    							$price = $settings['shipping']['weight-rate'][$i]['in_country'];
    					  	else if (in_array($country, $mp->eu_countries))
    						  	$price = $settings['shipping']['weight-rate'][$i]['eu'];
    					  	else
    							$price = $settings['shipping']['weight-rate'][$i]['international'];
    				  	}
    				  	else  //all other countries
    				  	{
    						if ($country == $settings['base_country'])
    							$price = $settings['shipping']['weight-rate'][$i]['in_country'];
    					  	else
    							$price = $settings['shipping']['weight-rate'][$i]['international'];
    					}
    				 	break;
    			  	}
    			}
         }
    
        return $price;
      }
    
    }
    
    //register plugin - uncomment to register
    mp_register_shipping_plugin( 'MP_Shipping_Weight_Rate', 'weight-rate', __('Weight Rate', 'mp') );
    ?>

    Please help so i can catchup on some sleep, i'm sure my customers are gonna love this plugin

    Thanks
    Nick

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.