|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Links GetPaid to WP All Import. |
|
4
|
|
|
* |
|
5
|
|
|
* @package GetPaid |
|
6
|
|
|
*/ |
|
7
|
|
|
|
|
8
|
|
|
defined( 'ABSPATH' ) || exit; |
|
9
|
|
|
|
|
10
|
|
|
include plugin_dir_path( __FILE__ ) . 'rapid-addon.php'; |
|
11
|
|
|
|
|
12
|
|
|
/** |
|
13
|
|
|
* WP All Import class. |
|
14
|
|
|
*/ |
|
15
|
|
|
class GetPaid_WP_All_Import { |
|
16
|
|
|
|
|
17
|
|
|
/** |
|
18
|
|
|
* @var RapidAddon |
|
19
|
|
|
*/ |
|
20
|
|
|
protected $add_on; |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* Class constructor. |
|
24
|
|
|
*/ |
|
25
|
|
|
public function __construct() { |
|
26
|
|
|
|
|
27
|
|
|
// Register the add-on. |
|
28
|
|
|
$this->add_on = new RapidAddon( 'GetPaid', 'GetPaid_WP_All_Import_Addon' ); |
|
29
|
|
|
$this->add_on->set_import_function( array( $this, 'import_items' ) ); |
|
30
|
|
|
$this->add_item_fields(); |
|
31
|
|
|
$this->add_on->run( array( 'post_types' => array( 'wpi_item' ) ) ); |
|
32
|
|
|
|
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* Retrieves item fields. |
|
37
|
|
|
*/ |
|
38
|
|
|
public function get_item_fields() { |
|
39
|
|
|
|
|
40
|
|
|
return array( |
|
41
|
|
|
'description' => __( 'Item Description', 'invoicing' ), |
|
42
|
|
|
'price' => __( 'Price', 'invoicing' ), |
|
43
|
|
|
'vat_rule' => __( 'VAT Rule', 'invoicing' ), |
|
44
|
|
|
'vat_class' => __( 'VAT Class', 'invoicing' ), |
|
45
|
|
|
'type' => __( 'Trial Interval', 'invoicing' ), |
|
46
|
|
|
'custom_id' => __( 'Custom ID', 'invoicing' ), |
|
47
|
|
|
'custom_name' => __( 'Custom Name', 'invoicing' ), |
|
48
|
|
|
'custom_singular_name' => __( 'Custom Singular Name', 'invoicing' ), |
|
49
|
|
|
'is_dynamic_pricing' => __( 'Users can name their own price', 'invoicing' ), |
|
50
|
|
|
'minimum_price' => __( 'Minimum price', 'invoicing' ), |
|
51
|
|
|
'is_recurring' => __( 'Is Recurring', 'invoicing' ), |
|
52
|
|
|
'recurring_period' => __( 'Recurring Period', 'invoicing' ), |
|
53
|
|
|
'recurring_interval' => __( 'Recurring Interval', 'invoicing' ), |
|
54
|
|
|
'recurring_limit' => __( 'Recurring Limit', 'invoicing' ), |
|
55
|
|
|
'is_free_trial' => __( 'Is free trial', 'invoicing' ), |
|
56
|
|
|
'trial_period' => __( 'Trial Period', 'invoicing' ), |
|
57
|
|
|
'trial_interval' => __( 'Trial Interval', 'invoicing' ), |
|
58
|
|
|
); |
|
59
|
|
|
|
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
/** |
|
63
|
|
|
* Registers item fields. |
|
64
|
|
|
*/ |
|
65
|
|
|
public function add_item_fields() { |
|
66
|
|
|
|
|
67
|
|
|
foreach ( $this->get_item_fields() as $key => $label ) { |
|
68
|
|
|
$this->add_on->add_field( $key, $label, 'text' ); |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
/** |
|
74
|
|
|
* Handles item imports. |
|
75
|
|
|
*/ |
|
76
|
|
|
public function import_items( $post_id, $data, $import_options, $_post ) { |
|
77
|
|
|
|
|
78
|
|
|
$item = wpinv_get_item( $post_id ); |
|
79
|
|
|
$prepared = array(); |
|
80
|
|
|
|
|
81
|
|
|
if ( empty( $item ) ) { |
|
82
|
|
|
return; |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
|
|
foreach ( array_keys( $this->get_item_fields() ) as $field ) { |
|
86
|
|
|
// Make sure the user has allowed this field to be updated. |
|
87
|
|
|
if ( empty( $_post['ID'] ) || $this->add_on->can_update_meta( $field, $import_options ) ) { |
|
88
|
|
|
|
|
89
|
|
|
// Update the custom field with the imported data. |
|
90
|
|
|
$prepared[ $field ] = $data[ $field ]; |
|
91
|
|
|
} |
|
92
|
|
|
} |
|
93
|
|
|
|
|
94
|
|
|
// Only update if we have something to update. |
|
95
|
|
|
if ( ! empty( $prepared ) ) { |
|
96
|
|
|
$item->set_props( $prepared ); |
|
97
|
|
|
$item->save(); |
|
98
|
|
|
} |
|
99
|
|
|
|
|
100
|
|
|
} |
|
101
|
|
|
|
|
102
|
|
|
} |
|
103
|
|
|
|
|
104
|
|
|
new GetPaid_WP_All_Import(); |
|
105
|
|
|
|