Skip to content

symtal/shipping-rate

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 

Repository files navigation

/*
 * MarketPress Hitachi Shipping Plugin
*/

class MP_Hitachi_Shipping extends MP_Shipping_API {
	
	public $build		 = 2;
	
	//private shipping method name. Lowercase alpha (a-z) and dashes (-) only please!
	var $plugin_name	 = 'hitachi';
	
	//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	 = true;
	
	//set to true if you want to add per-product weight shipping field
	var $use_weight	 = true;

	/*
	 * Runs when your class is instantiated. Use to setup your plugin instead of __construct()
	*/

	function on_creation() {
		
		//declare here for translation
		$this->public_name = __( 'Delivery', '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;
		
	}
	
	/*
	 * Add additional shipping fields
	*/
	
	public function extra_shipping_field( $fields, $type ) {
		
		return $fields;
		
	}
	
	/*
	 * Initialize the settings metabox
	*/
	
	public function init_settings_metabox() {
		
		global $mp;
		
		$metabox = new WPMUDEV_Metabox( array(
		
			'id'			 => $this->generate_metabox_id(),

			'page_slugs'	 => array(

				'store-settings-shipping',

				'store-settings_page_store-settings-shipping',

				'store-setup-wizard'

			),

			'title'			 => sprintf( __( '%s Settings', 'mp' ), $this->public_name ),

			'desc'			 => __( 'This option allows your customers to indicate that they will HITACHI their order at your place of business.', 'mp' ),

			'option_name'	 => 'mp_settings',

			'conditional'	 => array(

				'operator'	 => 'AND',

				'action'	 => 'show',

				array(

					'name'	 => 'shipping[method]',

					'value'	 => 'calculated',

				),

				array(

					'name'	 => 'shipping[calc_methods][hitachi]',

					'value'	 => 'hitachi',

				),

			),

		) );

		$metabox->add_field( 'text', array(

			'name'			 => $this->get_field_name( 'next-day' ),

			'label'			 => array( 'text' => __( 'Next Day', 'mp' ) . ' (' . mp_format_currency() . ')' ),

			'validation'	 => array(

				'required'	 => true,

				'number'	 => true,

				'min'		 => 0,

			),

			'default_value'	 => 0

		) );

		$metabox->add_field( 'text', array(

			'name'			 => $this->get_field_name( 'next-day-noon' ),

			'label'			 => array( 'text' => __( 'Next Day Noon', 'mp' ) . ' (' . mp_format_currency() . ')' ),

			'validation'	 => array(

				'required'	 => true,

				'number'	 => true,

				'min'		 => 0,

			),

			'default_value'	 => 0

		) );

	}



	/**

	 * 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 ) {

		if ( $selected_option ) {
		
			print_r( $selected_option );
			
		}

		$settings = mp_get_setting('shipping');
		
		print_r( $settings );
		
		
		$fee	=	0;
		
		if ( isset( $_SESSION['mp_shipping_info']['shipping_sub_option'] ) ) {
			
			$fee = $_SESSION['mp_shipping_info']['shipping_sub_option'];
			
		}
		

		//$fee		 = isset( $settings[ 'hitachi' ][ 'next-day' ] ) ? esc_attr( $settings[ 'hitachi' ][ 'next-day' ] ) : 0;

		return floatval( $fee );

	}



	/**

	 * For calculated shipping modules, use this method to return an associative array of the sub-options. The key will be what's saved as selected

	 *  in the session. Note the shipping parameters won't always be set. If they are, add the prices to the labels for each option.

	 *

	 * @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

	 *

	 * return array $shipping_options

	 */

	function shipping_options( $cart, $address1, $address2, $city, $state, $zip, $country ) {

		$shipping_options	=	array(
									'10.95'		=>	'Next Day',
									'13.00'		=>	'Next Day Noon',
									'24.99'		=>	'Next day 9:30am',
									'21.00'		=>	'Saturday AM',
									'35.00'		=>	'Saturday 9:30am',
									'39.99'		=>	'Scottish Isles / Channel Isles (3 day)',
								);

		return $shipping_options;

//		$shipping_options	=	array(
//									'next-day'		=> $this->get_setting( "next-day", __( 'Next Day', 'mp' ) ),
//									'next-day-noon'	=> $this->get_setting( "next-day-noon", __( 'Next Day Noon', 'mp' ) )
//								);

	}



}



//register plugin - uncomment to register

MP_Shipping_API::register_plugin( 'MP_Hitachi_Shipping', 'hitachi', __( 'Delivery', 'mp' ), true );

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published