PluginProbe
MakeCommerce for WooCommerce / 4.0.8
MakeCommerce for WooCommerce v4.0.8
4.1.0 4.0.8 trunk 1.0 1.0.1 1.0.2 1.0.3 1.1.0 1.1.1 1.1.2 1.1.3 1.1.4 1.1.5 1.1.6 1.1.7 2.0.0 2.1.0 2.1.1 2.1.2 2.1.3 2.1.4 2.1.5 2.2.0 2.2.1 2.2.2 All 96 releases
makecommerce / shipping / method / common / smartpost.php

smartpost.php in MakeCommerce for WooCommerce 4.0.8, at shipping/method/common/smartpost.php

83 lines 2.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace MakeCommerce\Shipping\Method\Common;
4
5 /**
6 * Omniva specific functionality that is used by both courier and parcelmachine
7 *
8 * @since 3.0.4
9 */
10
11 trait Smartpost {
12
13 public $carrier = "Smartpost";
14 public $carrier_id = "smartpost";
15 public $carrier_title = "SmartPosti";
16 public $service_name = "eservice.smartpost.ee";
17 public $international_number_format = true;
18
19 /**
20 * https://api.posti.fi/api-shipments.html
21 *
22 * Telephone number (with country code e.g. +3580501234567)
23 *
24 * country code => array(
25 * starting number(s) => array( lenght1, lenght2 )
26 * )
27 */
28 //Smartpost does not define any restrictions on phone numbers. Leave $valid_phonenumber_country_codes undefined
29
30 /**
31 * Returns invalid phone number error
32 *
33 * @since 3.0.4
34 */
35 public function phone_number_validation_error() {
36 return '<strong>' . $this->carrier_title . ' ' . $this->identifierString . '</strong> ' . __(' can be used with an international phone number only. Please specify your phone number with international country code (e.g. +372xxxxxxx)', 'wc_makecommerce_domain' );
37 }
38
39 /**
40 * Loads API key field for SmartPost
41 *
42 * @since 3.2.1
43 */
44 public function initialize_smartpost_api_field() {
45
46 $this->form_fields['api_key'] = array(
47 'title' => __( 'SmartPosti API Key', 'wc_makecommerce_domain' ),
48 'type' => 'text',
49 'default' => ''
50 );
51 }
52
53 /**
54 * Updates API key field for SmartPost
55 * Only called when the plugin has been updated, while the mc_version is not yet updated and the old version is < 3.3.0
56 * Only runs once, not called after the client has a version 3.3.0 or older
57 *
58 * @since 3.3.0
59 */
60 public static function v3_2_2_api_key_migration() {
61 foreach( ['courier', 'parcelmachine'] as $method ) {
62
63 $optionName = 'woocommerce_' . $method . '_smartpost_settings';
64
65 $options = get_option( $optionName );
66
67 // If api key is not already set or the value of it is empty
68 if ( empty( $options['api_key'] ) ) {
69 // If the service password is set and it is not empty
70 if ( ! empty( $options['service_password'] ) ) {
71 $options['api_key'] = $options['service_password'];
72 }
73 }
74 // Regardless of the api_key, delete the user and password
75 unset( $options['service_password'] );
76 unset( $options['service_user'] );
77
78 update_option( $optionName, $options );
79 }
80 }
81
82 }
83