Completed
Push — master ( 2d2a5e...fbb733 )
by Mike
08:09
created

WC_Shipping_Local_Pickup::init_form_fields()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 29
Code Lines 23

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 23
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 29
rs 8.8571
1
<?php
1 ignored issue
show
Coding Style Compatibility introduced by
For compatibility and reusability of your code, PSR1 recommends that a file should introduce either new symbols (like classes, functions, etc.) or have side-effects (like outputting something, or including other files), but not both at the same time. The first symbol is defined on line 16 and the first side effect is on line 3.

The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.

The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.

To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.

Loading history...
2
if ( ! defined( 'ABSPATH' ) ) {
3
	exit;
4
}
5
6
/**
7
 * Local Pickup Shipping Method.
8
 *
9
 * A simple shipping method allowing free pickup as a shipping method.
10
 *
11
 * @class 		WC_Shipping_Local_Pickup
12
 * @version		2.6.0
13
 * @package		WooCommerce/Classes/Shipping
14
 * @author 		WooThemes
15
 */
16
class WC_Shipping_Local_Pickup extends WC_Shipping_Method {
17
18
	/**
19
	 * Constructor.
20
	 */
21
	public function __construct( $instance_id = 0 ) {
22
		$this->id                    = 'local_pickup';
23
		$this->instance_id 			 = absint( $instance_id );
24
		$this->method_title          = __( 'Local Pickup', 'woocommerce' );
25
		$this->method_description    = __( 'Allow customers to pick up orders themselves. By default, when using local pickup store base taxes will apply regardless of customer address.', 'woocommerce' );
26
		$this->supports              = array(
27
			'shipping-zones',
28
			'instance-settings',
29
			'instance-settings-modal',
30
		);
31
		$this->init();
32
	}
33
34
	/**
35
	 * Initialize local pickup.
36
	 */
37
	public function init() {
38
39
		// Load the settings.
40
		$this->init_form_fields();
41
		$this->init_settings();
42
43
		// Define user set variables
44
		$this->title		     = $this->get_option( 'title' );
45
		$this->tax_status	     = $this->get_option( 'tax_status' );
46
		$this->cost	             = $this->get_option( 'cost' );
47
48
		// Actions
49
		add_action( 'woocommerce_update_options_shipping_' . $this->id, array( $this, 'process_admin_options' ) );
50
	}
51
52
	/**
53
	 * calculate_shipping function.
54
	 * Calculate local pickup shipping.
55
	 */
56
	public function calculate_shipping( $package = array() ) {
57
		$this->add_rate( array(
58
			'label' 	 => $this->title,
59
			'package'    => $package,
60
			'cost'       => $this->cost,
61
		) );
62
	}
63
64
	/**
65
	 * Init form fields.
66
	 */
67
	public function init_form_fields() {
68
		$this->instance_form_fields = array(
69
			'title' => array(
70
				'title'       => __( 'Title', 'woocommerce' ),
71
				'type'        => 'text',
72
				'description' => __( 'This controls the title which the user sees during checkout.', 'woocommerce' ),
73
				'default'     => __( 'Local Pickup', 'woocommerce' ),
74
				'desc_tip'    => true,
75
			),
76
			'tax_status' => array(
77
				'title' 		=> __( 'Tax Status', 'woocommerce' ),
78
				'type' 			=> 'select',
79
				'class'         => 'wc-enhanced-select',
80
				'default' 		=> 'taxable',
81
				'options'		=> array(
82
					'taxable' 	=> __( 'Taxable', 'woocommerce' ),
83
					'none' 		=> _x( 'None', 'Tax status', 'woocommerce' )
84
				)
85
			),
86
			'cost' => array(
87
				'title' 		=> __( 'Cost', 'woocommerce' ),
88
				'type' 			=> 'text',
89
				'placeholder'	=> '0',
90
				'description'	=> __( 'Optional cost for local pickup.', 'woocommerce' ),
91
				'default'		=> '',
92
				'desc_tip'		=> true
93
			)
94
		);
95
	}
96
}
97