@@ -1,6 +1,6 @@ discard block |
||
| 1 | 1 | <?php return array ( |
| 2 | - 'root' => |
|
| 3 | - array ( |
|
| 2 | + 'root' => |
|
| 3 | + array ( |
|
| 4 | 4 | 'pretty_version' => 'dev-master', |
| 5 | 5 | 'version' => 'dev-master', |
| 6 | 6 | 'aliases' => |
@@ -8,76 +8,76 @@ discard block |
||
| 8 | 8 | ), |
| 9 | 9 | 'reference' => '5bb76a7b209229589b146996e14f6d6ee9eb39d8', |
| 10 | 10 | 'name' => 'ayecode/invoicing', |
| 11 | - ), |
|
| 12 | - 'versions' => |
|
| 13 | - array ( |
|
| 11 | + ), |
|
| 12 | + 'versions' => |
|
| 13 | + array ( |
|
| 14 | 14 | 'ayecode/ayecode-connect-helper' => |
| 15 | 15 | array ( |
| 16 | - 'pretty_version' => '1.0.3', |
|
| 17 | - 'version' => '1.0.3.0', |
|
| 18 | - 'aliases' => |
|
| 19 | - array ( |
|
| 20 | - ), |
|
| 21 | - 'reference' => '1af7cdefdbd20d4443a3ab4834e4c1cd8fe57fb4', |
|
| 16 | + 'pretty_version' => '1.0.3', |
|
| 17 | + 'version' => '1.0.3.0', |
|
| 18 | + 'aliases' => |
|
| 19 | + array ( |
|
| 20 | + ), |
|
| 21 | + 'reference' => '1af7cdefdbd20d4443a3ab4834e4c1cd8fe57fb4', |
|
| 22 | 22 | ), |
| 23 | 23 | 'ayecode/invoicing' => |
| 24 | 24 | array ( |
| 25 | - 'pretty_version' => 'dev-master', |
|
| 26 | - 'version' => 'dev-master', |
|
| 27 | - 'aliases' => |
|
| 28 | - array ( |
|
| 29 | - ), |
|
| 30 | - 'reference' => '5bb76a7b209229589b146996e14f6d6ee9eb39d8', |
|
| 25 | + 'pretty_version' => 'dev-master', |
|
| 26 | + 'version' => 'dev-master', |
|
| 27 | + 'aliases' => |
|
| 28 | + array ( |
|
| 29 | + ), |
|
| 30 | + 'reference' => '5bb76a7b209229589b146996e14f6d6ee9eb39d8', |
|
| 31 | 31 | ), |
| 32 | 32 | 'ayecode/wp-ayecode-ui' => |
| 33 | 33 | array ( |
| 34 | - 'pretty_version' => '0.1.35', |
|
| 35 | - 'version' => '0.1.35.0', |
|
| 36 | - 'aliases' => |
|
| 37 | - array ( |
|
| 38 | - ), |
|
| 39 | - 'reference' => 'e5d7955f648c6b350a8fe72e0110b8d78645c60f', |
|
| 34 | + 'pretty_version' => '0.1.35', |
|
| 35 | + 'version' => '0.1.35.0', |
|
| 36 | + 'aliases' => |
|
| 37 | + array ( |
|
| 38 | + ), |
|
| 39 | + 'reference' => 'e5d7955f648c6b350a8fe72e0110b8d78645c60f', |
|
| 40 | 40 | ), |
| 41 | 41 | 'ayecode/wp-font-awesome-settings' => |
| 42 | 42 | array ( |
| 43 | - 'pretty_version' => '1.0.12', |
|
| 44 | - 'version' => '1.0.12.0', |
|
| 45 | - 'aliases' => |
|
| 46 | - array ( |
|
| 47 | - ), |
|
| 48 | - 'reference' => '754cca6fda775f3e0b56b90a810dfcaea62ea288', |
|
| 43 | + 'pretty_version' => '1.0.12', |
|
| 44 | + 'version' => '1.0.12.0', |
|
| 45 | + 'aliases' => |
|
| 46 | + array ( |
|
| 47 | + ), |
|
| 48 | + 'reference' => '754cca6fda775f3e0b56b90a810dfcaea62ea288', |
|
| 49 | 49 | ), |
| 50 | 50 | 'ayecode/wp-super-duper' => |
| 51 | 51 | array ( |
| 52 | - 'pretty_version' => '1.0.22', |
|
| 53 | - 'version' => '1.0.22.0', |
|
| 54 | - 'aliases' => |
|
| 55 | - array ( |
|
| 56 | - ), |
|
| 57 | - 'reference' => '42b638502c9e4be0877f27903df7c7ed2080bdac', |
|
| 52 | + 'pretty_version' => '1.0.22', |
|
| 53 | + 'version' => '1.0.22.0', |
|
| 54 | + 'aliases' => |
|
| 55 | + array ( |
|
| 56 | + ), |
|
| 57 | + 'reference' => '42b638502c9e4be0877f27903df7c7ed2080bdac', |
|
| 58 | 58 | ), |
| 59 | 59 | 'composer/installers' => |
| 60 | 60 | array ( |
| 61 | - 'pretty_version' => 'v1.9.0', |
|
| 62 | - 'version' => '1.9.0.0', |
|
| 63 | - 'aliases' => |
|
| 64 | - array ( |
|
| 65 | - ), |
|
| 66 | - 'reference' => 'b93bcf0fa1fccb0b7d176b0967d969691cd74cca', |
|
| 61 | + 'pretty_version' => 'v1.9.0', |
|
| 62 | + 'version' => '1.9.0.0', |
|
| 63 | + 'aliases' => |
|
| 64 | + array ( |
|
| 65 | + ), |
|
| 66 | + 'reference' => 'b93bcf0fa1fccb0b7d176b0967d969691cd74cca', |
|
| 67 | 67 | ), |
| 68 | 68 | 'roundcube/plugin-installer' => |
| 69 | 69 | array ( |
| 70 | - 'replaced' => |
|
| 71 | - array ( |
|
| 70 | + 'replaced' => |
|
| 71 | + array ( |
|
| 72 | 72 | 0 => '*', |
| 73 | - ), |
|
| 73 | + ), |
|
| 74 | 74 | ), |
| 75 | 75 | 'shama/baton' => |
| 76 | 76 | array ( |
| 77 | - 'replaced' => |
|
| 78 | - array ( |
|
| 77 | + 'replaced' => |
|
| 78 | + array ( |
|
| 79 | 79 | 0 => '*', |
| 80 | - ), |
|
| 80 | + ), |
|
| 81 | + ), |
|
| 81 | 82 | ), |
| 82 | - ), |
|
| 83 | 83 | ); |
@@ -12,217 +12,217 @@ |
||
| 12 | 12 | */ |
| 13 | 13 | class GetPaid_Payment_Form_Submission_Refresh_Prices { |
| 14 | 14 | |
| 15 | - /** |
|
| 16 | - * Contains the response for refreshing prices. |
|
| 17 | - * @var array |
|
| 18 | - */ |
|
| 19 | - public $response = array(); |
|
| 15 | + /** |
|
| 16 | + * Contains the response for refreshing prices. |
|
| 17 | + * @var array |
|
| 18 | + */ |
|
| 19 | + public $response = array(); |
|
| 20 | 20 | |
| 21 | 21 | /** |
| 22 | - * Class constructor |
|
| 23 | - * |
|
| 24 | - * @param GetPaid_Payment_Form_Submission $submission |
|
| 25 | - */ |
|
| 26 | - public function __construct( $submission ) { |
|
| 27 | - |
|
| 28 | - $this->response = array( |
|
| 29 | - 'submission_id' => $submission->id, |
|
| 22 | + * Class constructor |
|
| 23 | + * |
|
| 24 | + * @param GetPaid_Payment_Form_Submission $submission |
|
| 25 | + */ |
|
| 26 | + public function __construct( $submission ) { |
|
| 27 | + |
|
| 28 | + $this->response = array( |
|
| 29 | + 'submission_id' => $submission->id, |
|
| 30 | 30 | 'has_recurring' => $submission->has_recurring, |
| 31 | 31 | 'is_free' => ! $submission->should_collect_payment_details(), |
| 32 | - ); |
|
| 33 | - |
|
| 34 | - $this->add_totals( $submission ); |
|
| 35 | - $this->add_texts( $submission ); |
|
| 36 | - $this->add_items( $submission ); |
|
| 37 | - $this->add_fees( $submission ); |
|
| 38 | - $this->add_discounts( $submission ); |
|
| 39 | - $this->add_taxes( $submission ); |
|
| 40 | - $this->add_gateways( $submission ); |
|
| 41 | - |
|
| 42 | - } |
|
| 43 | - |
|
| 44 | - /** |
|
| 45 | - * Adds totals to a response for submission refresh prices. |
|
| 46 | - * |
|
| 47 | - * @param GetPaid_Payment_Form_Submission $submission |
|
| 48 | - */ |
|
| 49 | - public function add_totals( $submission ) { |
|
| 50 | - |
|
| 51 | - $this->response = array_merge( |
|
| 52 | - $this->response, |
|
| 53 | - array( |
|
| 54 | - |
|
| 55 | - 'totals' => array( |
|
| 56 | - 'subtotal' => $submission->format_amount( $submission->get_subtotal() ), |
|
| 57 | - 'discount' => $submission->format_amount( $submission->get_discount() ), |
|
| 58 | - 'fees' => $submission->format_amount( $submission->get_fee() ), |
|
| 59 | - 'tax' => $submission->format_amount( $submission->get_tax() ), |
|
| 60 | - 'total' => $submission->format_amount( $submission->get_total() ), |
|
| 61 | - 'raw_total' => html_entity_decode( sanitize_text_field( $submission->format_amount( $submission->get_total() ) ), ENT_QUOTES ), |
|
| 62 | - ), |
|
| 63 | - |
|
| 64 | - 'recurring' => array( |
|
| 65 | - 'subtotal' => $submission->format_amount( $submission->get_recurring_subtotal() ), |
|
| 66 | - 'discount' => $submission->format_amount( $submission->get_recurring_discount() ), |
|
| 67 | - 'fees' => $submission->format_amount( $submission->get_recurring_fee() ), |
|
| 68 | - 'tax' => $submission->format_amount( $submission->get_recurring_tax() ), |
|
| 69 | - 'total' => $submission->format_amount( $submission->get_recurring_total() ), |
|
| 70 | - ), |
|
| 71 | - |
|
| 72 | - ) |
|
| 73 | - ); |
|
| 74 | - |
|
| 75 | - } |
|
| 76 | - |
|
| 77 | - /** |
|
| 78 | - * Adds texts to a response for submission refresh prices. |
|
| 79 | - * |
|
| 80 | - * @param GetPaid_Payment_Form_Submission $submission |
|
| 81 | - */ |
|
| 82 | - public function add_texts( $submission ) { |
|
| 83 | - |
|
| 84 | - $payable = $submission->format_amount( $submission->get_total() ); |
|
| 85 | - |
|
| 86 | - if ( $submission->has_recurring != 0 ) { |
|
| 87 | - |
|
| 88 | - $recurring = new WPInv_Item( $submission->has_recurring ); |
|
| 89 | - $period = getpaid_get_subscription_period_label( $recurring->get_recurring_period( true ), $recurring->get_recurring_interval(), '' ); |
|
| 90 | - |
|
| 91 | - if ( $submission->get_total() == $submission->get_recurring_total() ) { |
|
| 92 | - $payable = "$payable / $period"; |
|
| 93 | - } else { |
|
| 94 | - $payable = sprintf( |
|
| 95 | - __( '%1$s (renews at %2$s / %3$s)'), |
|
| 96 | - $submission->format_amount( $submission->get_total() ), |
|
| 97 | - $submission->format_amount( $submission->get_recurring_total() ), |
|
| 98 | - $period |
|
| 99 | - ); |
|
| 100 | - } |
|
| 101 | - |
|
| 102 | - } |
|
| 103 | - |
|
| 104 | - $texts = array( |
|
| 105 | - '.getpaid-checkout-total-payable' => $payable, |
|
| 106 | - ); |
|
| 107 | - |
|
| 108 | - foreach ( $submission->get_items() as $item_id => $item ) { |
|
| 109 | - $texts[".item-$item_id .getpaid-item-initial-price"] = $submission->format_amount( $item->get_sub_total() ); |
|
| 110 | - $texts[".item-$item_id .getpaid-item-recurring-price"] = $submission->format_amount( $item->get_recurring_sub_total() ); |
|
| 111 | - } |
|
| 112 | - |
|
| 113 | - $this->response = array_merge( $this->response, array( 'texts' => $texts ) ); |
|
| 114 | - |
|
| 115 | - } |
|
| 116 | - |
|
| 117 | - /** |
|
| 118 | - * Adds items to a response for submission refresh prices. |
|
| 119 | - * |
|
| 120 | - * @param GetPaid_Payment_Form_Submission $submission |
|
| 121 | - */ |
|
| 122 | - public function add_items( $submission ) { |
|
| 123 | - |
|
| 124 | - // Add items. |
|
| 125 | - $items = array(); |
|
| 32 | + ); |
|
| 33 | + |
|
| 34 | + $this->add_totals( $submission ); |
|
| 35 | + $this->add_texts( $submission ); |
|
| 36 | + $this->add_items( $submission ); |
|
| 37 | + $this->add_fees( $submission ); |
|
| 38 | + $this->add_discounts( $submission ); |
|
| 39 | + $this->add_taxes( $submission ); |
|
| 40 | + $this->add_gateways( $submission ); |
|
| 41 | + |
|
| 42 | + } |
|
| 43 | + |
|
| 44 | + /** |
|
| 45 | + * Adds totals to a response for submission refresh prices. |
|
| 46 | + * |
|
| 47 | + * @param GetPaid_Payment_Form_Submission $submission |
|
| 48 | + */ |
|
| 49 | + public function add_totals( $submission ) { |
|
| 50 | + |
|
| 51 | + $this->response = array_merge( |
|
| 52 | + $this->response, |
|
| 53 | + array( |
|
| 54 | + |
|
| 55 | + 'totals' => array( |
|
| 56 | + 'subtotal' => $submission->format_amount( $submission->get_subtotal() ), |
|
| 57 | + 'discount' => $submission->format_amount( $submission->get_discount() ), |
|
| 58 | + 'fees' => $submission->format_amount( $submission->get_fee() ), |
|
| 59 | + 'tax' => $submission->format_amount( $submission->get_tax() ), |
|
| 60 | + 'total' => $submission->format_amount( $submission->get_total() ), |
|
| 61 | + 'raw_total' => html_entity_decode( sanitize_text_field( $submission->format_amount( $submission->get_total() ) ), ENT_QUOTES ), |
|
| 62 | + ), |
|
| 63 | + |
|
| 64 | + 'recurring' => array( |
|
| 65 | + 'subtotal' => $submission->format_amount( $submission->get_recurring_subtotal() ), |
|
| 66 | + 'discount' => $submission->format_amount( $submission->get_recurring_discount() ), |
|
| 67 | + 'fees' => $submission->format_amount( $submission->get_recurring_fee() ), |
|
| 68 | + 'tax' => $submission->format_amount( $submission->get_recurring_tax() ), |
|
| 69 | + 'total' => $submission->format_amount( $submission->get_recurring_total() ), |
|
| 70 | + ), |
|
| 71 | + |
|
| 72 | + ) |
|
| 73 | + ); |
|
| 74 | + |
|
| 75 | + } |
|
| 76 | + |
|
| 77 | + /** |
|
| 78 | + * Adds texts to a response for submission refresh prices. |
|
| 79 | + * |
|
| 80 | + * @param GetPaid_Payment_Form_Submission $submission |
|
| 81 | + */ |
|
| 82 | + public function add_texts( $submission ) { |
|
| 83 | + |
|
| 84 | + $payable = $submission->format_amount( $submission->get_total() ); |
|
| 85 | + |
|
| 86 | + if ( $submission->has_recurring != 0 ) { |
|
| 87 | + |
|
| 88 | + $recurring = new WPInv_Item( $submission->has_recurring ); |
|
| 89 | + $period = getpaid_get_subscription_period_label( $recurring->get_recurring_period( true ), $recurring->get_recurring_interval(), '' ); |
|
| 90 | + |
|
| 91 | + if ( $submission->get_total() == $submission->get_recurring_total() ) { |
|
| 92 | + $payable = "$payable / $period"; |
|
| 93 | + } else { |
|
| 94 | + $payable = sprintf( |
|
| 95 | + __( '%1$s (renews at %2$s / %3$s)'), |
|
| 96 | + $submission->format_amount( $submission->get_total() ), |
|
| 97 | + $submission->format_amount( $submission->get_recurring_total() ), |
|
| 98 | + $period |
|
| 99 | + ); |
|
| 100 | + } |
|
| 101 | + |
|
| 102 | + } |
|
| 103 | + |
|
| 104 | + $texts = array( |
|
| 105 | + '.getpaid-checkout-total-payable' => $payable, |
|
| 106 | + ); |
|
| 107 | + |
|
| 108 | + foreach ( $submission->get_items() as $item_id => $item ) { |
|
| 109 | + $texts[".item-$item_id .getpaid-item-initial-price"] = $submission->format_amount( $item->get_sub_total() ); |
|
| 110 | + $texts[".item-$item_id .getpaid-item-recurring-price"] = $submission->format_amount( $item->get_recurring_sub_total() ); |
|
| 111 | + } |
|
| 112 | + |
|
| 113 | + $this->response = array_merge( $this->response, array( 'texts' => $texts ) ); |
|
| 114 | + |
|
| 115 | + } |
|
| 116 | + |
|
| 117 | + /** |
|
| 118 | + * Adds items to a response for submission refresh prices. |
|
| 119 | + * |
|
| 120 | + * @param GetPaid_Payment_Form_Submission $submission |
|
| 121 | + */ |
|
| 122 | + public function add_items( $submission ) { |
|
| 123 | + |
|
| 124 | + // Add items. |
|
| 125 | + $items = array(); |
|
| 126 | 126 | |
| 127 | 127 | foreach ( $submission->get_items() as $item_id => $item ) { |
| 128 | - $items["$item_id"] = $submission->format_amount( $item->get_sub_total() ); |
|
| 129 | - } |
|
| 128 | + $items["$item_id"] = $submission->format_amount( $item->get_sub_total() ); |
|
| 129 | + } |
|
| 130 | 130 | |
| 131 | - $this->response = array_merge( |
|
| 132 | - $this->response, |
|
| 133 | - array( 'items' => $items ) |
|
| 134 | - ); |
|
| 131 | + $this->response = array_merge( |
|
| 132 | + $this->response, |
|
| 133 | + array( 'items' => $items ) |
|
| 134 | + ); |
|
| 135 | 135 | |
| 136 | - } |
|
| 136 | + } |
|
| 137 | 137 | |
| 138 | - /** |
|
| 139 | - * Adds fees to a response for submission refresh prices. |
|
| 140 | - * |
|
| 141 | - * @param GetPaid_Payment_Form_Submission $submission |
|
| 142 | - */ |
|
| 143 | - public function add_fees( $submission ) { |
|
| 138 | + /** |
|
| 139 | + * Adds fees to a response for submission refresh prices. |
|
| 140 | + * |
|
| 141 | + * @param GetPaid_Payment_Form_Submission $submission |
|
| 142 | + */ |
|
| 143 | + public function add_fees( $submission ) { |
|
| 144 | 144 | |
| 145 | - $fees = array(); |
|
| 145 | + $fees = array(); |
|
| 146 | 146 | |
| 147 | 147 | foreach ( $submission->get_fees() as $name => $data ) { |
| 148 | - $fees[$name] = $submission->format_amount( $data['initial_fee'] ); |
|
| 149 | - } |
|
| 148 | + $fees[$name] = $submission->format_amount( $data['initial_fee'] ); |
|
| 149 | + } |
|
| 150 | 150 | |
| 151 | - $this->response = array_merge( |
|
| 152 | - $this->response, |
|
| 153 | - array( 'fees' => $fees ) |
|
| 154 | - ); |
|
| 151 | + $this->response = array_merge( |
|
| 152 | + $this->response, |
|
| 153 | + array( 'fees' => $fees ) |
|
| 154 | + ); |
|
| 155 | 155 | |
| 156 | - } |
|
| 156 | + } |
|
| 157 | 157 | |
| 158 | - /** |
|
| 159 | - * Adds discounts to a response for submission refresh prices. |
|
| 160 | - * |
|
| 161 | - * @param GetPaid_Payment_Form_Submission $submission |
|
| 162 | - */ |
|
| 163 | - public function add_discounts( $submission ) { |
|
| 158 | + /** |
|
| 159 | + * Adds discounts to a response for submission refresh prices. |
|
| 160 | + * |
|
| 161 | + * @param GetPaid_Payment_Form_Submission $submission |
|
| 162 | + */ |
|
| 163 | + public function add_discounts( $submission ) { |
|
| 164 | 164 | |
| 165 | - $discounts = array(); |
|
| 165 | + $discounts = array(); |
|
| 166 | 166 | |
| 167 | 167 | foreach ( $submission->get_discounts() as $name => $data ) { |
| 168 | - $discounts[$name] = $submission->format_amount( $data['initial_discount'] ); |
|
| 169 | - } |
|
| 168 | + $discounts[$name] = $submission->format_amount( $data['initial_discount'] ); |
|
| 169 | + } |
|
| 170 | 170 | |
| 171 | - $this->response = array_merge( |
|
| 172 | - $this->response, |
|
| 173 | - array( 'discounts' => $discounts ) |
|
| 174 | - ); |
|
| 171 | + $this->response = array_merge( |
|
| 172 | + $this->response, |
|
| 173 | + array( 'discounts' => $discounts ) |
|
| 174 | + ); |
|
| 175 | 175 | |
| 176 | - } |
|
| 176 | + } |
|
| 177 | 177 | |
| 178 | - /** |
|
| 179 | - * Adds taxes to a response for submission refresh prices. |
|
| 180 | - * |
|
| 181 | - * @param GetPaid_Payment_Form_Submission $submission |
|
| 182 | - */ |
|
| 183 | - public function add_taxes( $submission ) { |
|
| 178 | + /** |
|
| 179 | + * Adds taxes to a response for submission refresh prices. |
|
| 180 | + * |
|
| 181 | + * @param GetPaid_Payment_Form_Submission $submission |
|
| 182 | + */ |
|
| 183 | + public function add_taxes( $submission ) { |
|
| 184 | 184 | |
| 185 | - $taxes = array(); |
|
| 185 | + $taxes = array(); |
|
| 186 | 186 | |
| 187 | 187 | foreach ( $submission->get_taxes() as $name => $data ) { |
| 188 | - $taxes[$name] = $submission->format_amount( $data['initial_tax'] ); |
|
| 189 | - } |
|
| 188 | + $taxes[$name] = $submission->format_amount( $data['initial_tax'] ); |
|
| 189 | + } |
|
| 190 | 190 | |
| 191 | - $this->response = array_merge( |
|
| 192 | - $this->response, |
|
| 193 | - array( 'taxes' => $taxes ) |
|
| 194 | - ); |
|
| 191 | + $this->response = array_merge( |
|
| 192 | + $this->response, |
|
| 193 | + array( 'taxes' => $taxes ) |
|
| 194 | + ); |
|
| 195 | 195 | |
| 196 | - } |
|
| 196 | + } |
|
| 197 | 197 | |
| 198 | - /** |
|
| 199 | - * Adds gateways to a response for submission refresh prices. |
|
| 200 | - * |
|
| 201 | - * @param GetPaid_Payment_Form_Submission $submission |
|
| 202 | - */ |
|
| 203 | - public function add_gateways( $submission ) { |
|
| 198 | + /** |
|
| 199 | + * Adds gateways to a response for submission refresh prices. |
|
| 200 | + * |
|
| 201 | + * @param GetPaid_Payment_Form_Submission $submission |
|
| 202 | + */ |
|
| 203 | + public function add_gateways( $submission ) { |
|
| 204 | 204 | |
| 205 | - $gateways = array_keys( wpinv_get_enabled_payment_gateways() ); |
|
| 205 | + $gateways = array_keys( wpinv_get_enabled_payment_gateways() ); |
|
| 206 | 206 | |
| 207 | - if ( $this->response['has_recurring'] ) { |
|
| 207 | + if ( $this->response['has_recurring'] ) { |
|
| 208 | 208 | |
| 209 | - foreach ( $gateways as $i => $gateway ) { |
|
| 209 | + foreach ( $gateways as $i => $gateway ) { |
|
| 210 | 210 | |
| 211 | - if ( ! wpinv_gateway_support_subscription( $gateway ) ) { |
|
| 212 | - unset( $gateways[ $i ] ); |
|
| 213 | - } |
|
| 211 | + if ( ! wpinv_gateway_support_subscription( $gateway ) ) { |
|
| 212 | + unset( $gateways[ $i ] ); |
|
| 213 | + } |
|
| 214 | 214 | |
| 215 | - } |
|
| 215 | + } |
|
| 216 | 216 | |
| 217 | - } |
|
| 217 | + } |
|
| 218 | 218 | |
| 219 | 219 | |
| 220 | - $gateways = apply_filters( 'getpaid_submission_gateways', $gateways, $submission ); |
|
| 221 | - $this->response = array_merge( |
|
| 222 | - $this->response, |
|
| 223 | - array( 'gateways' => $gateways ) |
|
| 224 | - ); |
|
| 220 | + $gateways = apply_filters( 'getpaid_submission_gateways', $gateways, $submission ); |
|
| 221 | + $this->response = array_merge( |
|
| 222 | + $this->response, |
|
| 223 | + array( 'gateways' => $gateways ) |
|
| 224 | + ); |
|
| 225 | 225 | |
| 226 | - } |
|
| 226 | + } |
|
| 227 | 227 | |
| 228 | 228 | } |
@@ -13,9 +13,9 @@ discard block |
||
| 13 | 13 | |
| 14 | 14 | |
| 15 | 15 | function wpinv_get_default_country() { |
| 16 | - $country = wpinv_get_option( 'default_country', 'UK' ); |
|
| 16 | + $country = wpinv_get_option( 'default_country', 'UK' ); |
|
| 17 | 17 | |
| 18 | - return apply_filters( 'wpinv_default_country', $country ); |
|
| 18 | + return apply_filters( 'wpinv_default_country', $country ); |
|
| 19 | 19 | } |
| 20 | 20 | |
| 21 | 21 | /** |
@@ -26,7 +26,7 @@ discard block |
||
| 26 | 26 | */ |
| 27 | 27 | function wpinv_sanitize_country( $country ) { |
| 28 | 28 | |
| 29 | - // Enure the country is specified |
|
| 29 | + // Enure the country is specified |
|
| 30 | 30 | if ( empty( $country ) ) { |
| 31 | 31 | $country = wpinv_get_default_country(); |
| 32 | 32 | } |
@@ -56,9 +56,9 @@ discard block |
||
| 56 | 56 | } |
| 57 | 57 | |
| 58 | 58 | function wpinv_get_default_state() { |
| 59 | - $state = wpinv_get_option( 'default_state', '' ); |
|
| 59 | + $state = wpinv_get_option( 'default_state', '' ); |
|
| 60 | 60 | |
| 61 | - return apply_filters( 'wpinv_default_state', $state ); |
|
| 61 | + return apply_filters( 'wpinv_default_state', $state ); |
|
| 62 | 62 | } |
| 63 | 63 | |
| 64 | 64 | function wpinv_state_name( $state_code = '', $country_code = '' ) { |
@@ -288,11 +288,11 @@ discard block |
||
| 288 | 288 | |
| 289 | 289 | $country = wpinv_sanitize_country( $country ); |
| 290 | 290 | |
| 291 | - foreach ( wpinv_get_continents( 'countries' ) as $continent_code => $countries ) { |
|
| 292 | - if ( false !== array_search( $country, $countries, true ) ) { |
|
| 293 | - return $continent_code; |
|
| 294 | - } |
|
| 295 | - } |
|
| 291 | + foreach ( wpinv_get_continents( 'countries' ) as $continent_code => $countries ) { |
|
| 292 | + if ( false !== array_search( $country, $countries, true ) ) { |
|
| 293 | + return $continent_code; |
|
| 294 | + } |
|
| 295 | + } |
|
| 296 | 296 | |
| 297 | 297 | return ''; |
| 298 | 298 | |
@@ -584,30 +584,30 @@ discard block |
||
| 584 | 584 | } |
| 585 | 585 | |
| 586 | 586 | function wpinv_get_states_field() { |
| 587 | - if( empty( $_POST['country'] ) ) { |
|
| 588 | - $_POST['country'] = wpinv_get_default_country(); |
|
| 589 | - } |
|
| 590 | - $states = wpinv_get_country_states( sanitize_text_field( $_POST['country'] ) ); |
|
| 587 | + if( empty( $_POST['country'] ) ) { |
|
| 588 | + $_POST['country'] = wpinv_get_default_country(); |
|
| 589 | + } |
|
| 590 | + $states = wpinv_get_country_states( sanitize_text_field( $_POST['country'] ) ); |
|
| 591 | 591 | |
| 592 | - if( !empty( $states ) ) { |
|
| 593 | - $sanitized_field_name = sanitize_text_field( $_POST['field_name'] ); |
|
| 592 | + if( !empty( $states ) ) { |
|
| 593 | + $sanitized_field_name = sanitize_text_field( $_POST['field_name'] ); |
|
| 594 | 594 | |
| 595 | 595 | $args = array( |
| 596 | - 'name' => $sanitized_field_name, |
|
| 597 | - 'id' => $sanitized_field_name, |
|
| 598 | - 'class' => $sanitized_field_name . 'custom-select wpinv-select wpi_select2', |
|
| 599 | - 'options' => array_merge( array( '' => '' ), $states ), |
|
| 600 | - 'show_option_all' => false, |
|
| 601 | - 'show_option_none' => false |
|
| 602 | - ); |
|
| 603 | - |
|
| 604 | - $response = wpinv_html_select( $args ); |
|
| 605 | - |
|
| 606 | - } else { |
|
| 607 | - $response = 'nostates'; |
|
| 608 | - } |
|
| 596 | + 'name' => $sanitized_field_name, |
|
| 597 | + 'id' => $sanitized_field_name, |
|
| 598 | + 'class' => $sanitized_field_name . 'custom-select wpinv-select wpi_select2', |
|
| 599 | + 'options' => array_merge( array( '' => '' ), $states ), |
|
| 600 | + 'show_option_all' => false, |
|
| 601 | + 'show_option_none' => false |
|
| 602 | + ); |
|
| 603 | + |
|
| 604 | + $response = wpinv_html_select( $args ); |
|
| 605 | + |
|
| 606 | + } else { |
|
| 607 | + $response = 'nostates'; |
|
| 608 | + } |
|
| 609 | 609 | |
| 610 | - return $response; |
|
| 610 | + return $response; |
|
| 611 | 611 | } |
| 612 | 612 | |
| 613 | 613 | function wpinv_default_billing_country( $country = '', $user_id = 0 ) { |
@@ -625,46 +625,46 @@ discard block |
||
| 625 | 625 | */ |
| 626 | 626 | function wpinv_get_address_formats() { |
| 627 | 627 | |
| 628 | - return apply_filters( 'wpinv_localisation_address_formats', |
|
| 629 | - array( |
|
| 630 | - 'default' => "{{name}}\n{{company}}\n{{address}}\n{{city}}\n{{state}}\n{{zip}}\n{{country}}", |
|
| 631 | - 'AU' => "{{name}}\n{{company}}\n{{address}}\n{{city}}\n{{state}} {{zip}}\n{{country}}", |
|
| 632 | - 'AT' => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}", |
|
| 633 | - 'BE' => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}", |
|
| 634 | - 'CA' => "{{company}}\n{{name}}\n{{address}}\n{{city}} {{state_code}} {{zip}}\n{{country}}", |
|
| 635 | - 'CH' => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}", |
|
| 636 | - 'CL' => "{{company}}\n{{name}}\n{{address}}\n{{state}}\n{{zip}} {{city}}\n{{country}}", |
|
| 637 | - 'CN' => "{{country}} {{zip}}\n{{state}}, {{city}}, {{address}}\n{{company}}\n{{name}}", |
|
| 638 | - 'CZ' => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}", |
|
| 639 | - 'DE' => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}", |
|
| 640 | - 'EE' => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}", |
|
| 641 | - 'FI' => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}", |
|
| 642 | - 'DK' => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}", |
|
| 643 | - 'FR' => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city_upper}}\n{{country}}", |
|
| 644 | - 'HK' => "{{company}}\n{{first_name}} {{last_name_upper}}\n{{address}}\n{{city_upper}}\n{{state_upper}}\n{{country}}", |
|
| 645 | - 'HU' => "{{name}}\n{{company}}\n{{city}}\n{{address}}\n{{zip}}\n{{country}}", |
|
| 646 | - 'IN' => "{{company}}\n{{name}}\n{{address}}\n{{city}} {{zip}}\n{{state}}, {{country}}", |
|
| 647 | - 'IS' => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}", |
|
| 648 | - 'IT' => "{{company}}\n{{name}}\n{{address}}\n{{zip}}\n{{city}}\n{{state_upper}}\n{{country}}", |
|
| 649 | - 'JP' => "{{zip}}\n{{state}} {{city}} {{address}}\n{{company}}\n{{last_name}} {{first_name}}\n{{country}}", |
|
| 650 | - 'TW' => "{{company}}\n{{last_name}} {{first_name}}\n{{address}}\n{{state}}, {{city}} {{zip}}\n{{country}}", |
|
| 651 | - 'LI' => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}", |
|
| 652 | - 'NL' => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}", |
|
| 653 | - 'NZ' => "{{name}}\n{{company}}\n{{address}}\n{{city}} {{zip}}\n{{country}}", |
|
| 654 | - 'NO' => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}", |
|
| 655 | - 'PL' => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}", |
|
| 656 | - 'PT' => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}", |
|
| 657 | - 'SK' => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}", |
|
| 658 | - 'RS' => "{{name}}\n{{company}}\n{{address}}\n{{zip}} {{city}}\n{{country}}", |
|
| 659 | - 'SI' => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}", |
|
| 660 | - 'ES' => "{{name}}\n{{company}}\n{{address}}\n{{zip}} {{city}}\n{{state}}\n{{country}}", |
|
| 661 | - 'SE' => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}", |
|
| 662 | - 'TR' => "{{name}}\n{{company}}\n{{address}}\n{{zip}} {{city}} {{state}}\n{{country}}", |
|
| 663 | - 'UG' => "{{name}}\n{{company}}\n{{address}}\n{{city}}\n{{state}}, {{country}}", |
|
| 664 | - 'US' => "{{name}}\n{{company}}\n{{address}}\n{{city}}, {{state_code}} {{zip}}\n{{country}}", |
|
| 665 | - 'VN' => "{{name}}\n{{company}}\n{{address}}\n{{city}}\n{{country}}", |
|
| 666 | - ) |
|
| 667 | - ); |
|
| 628 | + return apply_filters( 'wpinv_localisation_address_formats', |
|
| 629 | + array( |
|
| 630 | + 'default' => "{{name}}\n{{company}}\n{{address}}\n{{city}}\n{{state}}\n{{zip}}\n{{country}}", |
|
| 631 | + 'AU' => "{{name}}\n{{company}}\n{{address}}\n{{city}}\n{{state}} {{zip}}\n{{country}}", |
|
| 632 | + 'AT' => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}", |
|
| 633 | + 'BE' => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}", |
|
| 634 | + 'CA' => "{{company}}\n{{name}}\n{{address}}\n{{city}} {{state_code}} {{zip}}\n{{country}}", |
|
| 635 | + 'CH' => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}", |
|
| 636 | + 'CL' => "{{company}}\n{{name}}\n{{address}}\n{{state}}\n{{zip}} {{city}}\n{{country}}", |
|
| 637 | + 'CN' => "{{country}} {{zip}}\n{{state}}, {{city}}, {{address}}\n{{company}}\n{{name}}", |
|
| 638 | + 'CZ' => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}", |
|
| 639 | + 'DE' => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}", |
|
| 640 | + 'EE' => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}", |
|
| 641 | + 'FI' => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}", |
|
| 642 | + 'DK' => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}", |
|
| 643 | + 'FR' => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city_upper}}\n{{country}}", |
|
| 644 | + 'HK' => "{{company}}\n{{first_name}} {{last_name_upper}}\n{{address}}\n{{city_upper}}\n{{state_upper}}\n{{country}}", |
|
| 645 | + 'HU' => "{{name}}\n{{company}}\n{{city}}\n{{address}}\n{{zip}}\n{{country}}", |
|
| 646 | + 'IN' => "{{company}}\n{{name}}\n{{address}}\n{{city}} {{zip}}\n{{state}}, {{country}}", |
|
| 647 | + 'IS' => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}", |
|
| 648 | + 'IT' => "{{company}}\n{{name}}\n{{address}}\n{{zip}}\n{{city}}\n{{state_upper}}\n{{country}}", |
|
| 649 | + 'JP' => "{{zip}}\n{{state}} {{city}} {{address}}\n{{company}}\n{{last_name}} {{first_name}}\n{{country}}", |
|
| 650 | + 'TW' => "{{company}}\n{{last_name}} {{first_name}}\n{{address}}\n{{state}}, {{city}} {{zip}}\n{{country}}", |
|
| 651 | + 'LI' => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}", |
|
| 652 | + 'NL' => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}", |
|
| 653 | + 'NZ' => "{{name}}\n{{company}}\n{{address}}\n{{city}} {{zip}}\n{{country}}", |
|
| 654 | + 'NO' => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}", |
|
| 655 | + 'PL' => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}", |
|
| 656 | + 'PT' => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}", |
|
| 657 | + 'SK' => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}", |
|
| 658 | + 'RS' => "{{name}}\n{{company}}\n{{address}}\n{{zip}} {{city}}\n{{country}}", |
|
| 659 | + 'SI' => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}", |
|
| 660 | + 'ES' => "{{name}}\n{{company}}\n{{address}}\n{{zip}} {{city}}\n{{state}}\n{{country}}", |
|
| 661 | + 'SE' => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}", |
|
| 662 | + 'TR' => "{{name}}\n{{company}}\n{{address}}\n{{zip}} {{city}} {{state}}\n{{country}}", |
|
| 663 | + 'UG' => "{{name}}\n{{company}}\n{{address}}\n{{city}}\n{{state}}, {{country}}", |
|
| 664 | + 'US' => "{{name}}\n{{company}}\n{{address}}\n{{city}}, {{state_code}} {{zip}}\n{{country}}", |
|
| 665 | + 'VN' => "{{name}}\n{{company}}\n{{address}}\n{{city}}\n{{country}}", |
|
| 666 | + ) |
|
| 667 | + ); |
|
| 668 | 668 | } |
| 669 | 669 | |
| 670 | 670 | /** |
@@ -681,21 +681,21 @@ discard block |
||
| 681 | 681 | } |
| 682 | 682 | |
| 683 | 683 | // Get all formats. |
| 684 | - $formats = wpinv_get_address_formats(); |
|
| 684 | + $formats = wpinv_get_address_formats(); |
|
| 685 | 685 | |
| 686 | - // Get format for the specified country. |
|
| 687 | - $format = ( $country && isset( $formats[ $country ] ) ) ? $formats[ $country ] : $formats['default']; |
|
| 686 | + // Get format for the specified country. |
|
| 687 | + $format = ( $country && isset( $formats[ $country ] ) ) ? $formats[ $country ] : $formats['default']; |
|
| 688 | 688 | |
| 689 | 689 | /** |
| 690 | - * Filters the address format to use on Invoices. |
|
| 690 | + * Filters the address format to use on Invoices. |
|
| 691 | 691 | * |
| 692 | 692 | * New lines will be replaced by a `br` element. Double new lines will be replaced by a paragraph. HTML tags are allowed. |
| 693 | - * |
|
| 694 | - * @since 1.0.13 |
|
| 695 | - * |
|
| 696 | - * @param string $format The address format to use. |
|
| 693 | + * |
|
| 694 | + * @since 1.0.13 |
|
| 695 | + * |
|
| 696 | + * @param string $format The address format to use. |
|
| 697 | 697 | * @param string $country The country who's address format is being retrieved. |
| 698 | - */ |
|
| 698 | + */ |
|
| 699 | 699 | return apply_filters( 'wpinv_get_full_address_format', $format, $country ); |
| 700 | 700 | } |
| 701 | 701 | |
@@ -716,8 +716,8 @@ discard block |
||
| 716 | 716 | 'country' => '', |
| 717 | 717 | 'zip' => '', |
| 718 | 718 | 'first_name' => '', |
| 719 | - 'last_name' => '', |
|
| 720 | - 'company' => '', |
|
| 719 | + 'last_name' => '', |
|
| 720 | + 'company' => '', |
|
| 721 | 721 | ); |
| 722 | 722 | |
| 723 | 723 | $args = map_deep( wp_parse_args( $billing_details, $default_args ), 'trim' ); |
@@ -738,14 +738,14 @@ discard block |
||
| 738 | 738 | $args['country_code']= $country; |
| 739 | 739 | |
| 740 | 740 | /** |
| 741 | - * Filters the address format replacements to use on Invoices. |
|
| 741 | + * Filters the address format replacements to use on Invoices. |
|
| 742 | 742 | * |
| 743 | - * |
|
| 744 | - * @since 1.0.13 |
|
| 745 | - * |
|
| 746 | - * @param array $replacements The address replacements to use. |
|
| 743 | + * |
|
| 744 | + * @since 1.0.13 |
|
| 745 | + * |
|
| 746 | + * @param array $replacements The address replacements to use. |
|
| 747 | 747 | * @param array $billing_details The billing details to use. |
| 748 | - */ |
|
| 748 | + */ |
|
| 749 | 749 | $replacements = apply_filters( 'wpinv_get_invoice_address_replacements', $args, $billing_details ); |
| 750 | 750 | |
| 751 | 751 | $return = array(); |
@@ -768,5 +768,5 @@ discard block |
||
| 768 | 768 | * @return string |
| 769 | 769 | */ |
| 770 | 770 | function wpinv_trim_formatted_address_line( $line ) { |
| 771 | - return trim( $line, ', ' ); |
|
| 771 | + return trim( $line, ', ' ); |
|
| 772 | 772 | } |
| 773 | 773 | \ No newline at end of file |
@@ -9,7 +9,7 @@ discard block |
||
| 9 | 9 | */ |
| 10 | 10 | |
| 11 | 11 | if ( ! defined( 'ABSPATH' ) ) { |
| 12 | - exit; |
|
| 12 | + exit; |
|
| 13 | 13 | } |
| 14 | 14 | |
| 15 | 15 | /** |
@@ -21,356 +21,356 @@ discard block |
||
| 21 | 21 | */ |
| 22 | 22 | abstract class GetPaid_Data { |
| 23 | 23 | |
| 24 | - /** |
|
| 25 | - * ID for this object. |
|
| 26 | - * |
|
| 27 | - * @since 1.0.19 |
|
| 28 | - * @var int |
|
| 29 | - */ |
|
| 30 | - protected $id = 0; |
|
| 31 | - |
|
| 32 | - /** |
|
| 33 | - * Core data for this object. Name value pairs (name + default value). |
|
| 34 | - * |
|
| 35 | - * @since 1.0.19 |
|
| 36 | - * @var array |
|
| 37 | - */ |
|
| 38 | - protected $data = array(); |
|
| 39 | - |
|
| 40 | - /** |
|
| 41 | - * Core data changes for this object. |
|
| 42 | - * |
|
| 43 | - * @since 1.0.19 |
|
| 44 | - * @var array |
|
| 45 | - */ |
|
| 46 | - protected $changes = array(); |
|
| 47 | - |
|
| 48 | - /** |
|
| 49 | - * This is false until the object is read from the DB. |
|
| 50 | - * |
|
| 51 | - * @since 1.0.19 |
|
| 52 | - * @var bool |
|
| 53 | - */ |
|
| 54 | - protected $object_read = false; |
|
| 55 | - |
|
| 56 | - /** |
|
| 57 | - * This is the name of this object type. |
|
| 58 | - * |
|
| 59 | - * @since 1.0.19 |
|
| 60 | - * @var string |
|
| 61 | - */ |
|
| 62 | - protected $object_type = 'data'; |
|
| 63 | - |
|
| 64 | - /** |
|
| 65 | - * Extra data for this object. Name value pairs (name + default value). |
|
| 66 | - * Used as a standard way for sub classes (like item types) to add |
|
| 67 | - * additional information to an inherited class. |
|
| 68 | - * |
|
| 69 | - * @since 1.0.19 |
|
| 70 | - * @var array |
|
| 71 | - */ |
|
| 72 | - protected $extra_data = array(); |
|
| 73 | - |
|
| 74 | - /** |
|
| 75 | - * Set to _data on construct so we can track and reset data if needed. |
|
| 76 | - * |
|
| 77 | - * @since 1.0.19 |
|
| 78 | - * @var array |
|
| 79 | - */ |
|
| 80 | - protected $default_data = array(); |
|
| 81 | - |
|
| 82 | - /** |
|
| 83 | - * Contains a reference to the data store for this class. |
|
| 84 | - * |
|
| 85 | - * @since 1.0.19 |
|
| 86 | - * @var GetPaid_Data_Store |
|
| 87 | - */ |
|
| 88 | - protected $data_store; |
|
| 89 | - |
|
| 90 | - /** |
|
| 91 | - * Stores meta in cache for future reads. |
|
| 92 | - * A group must be set to to enable caching. |
|
| 93 | - * |
|
| 94 | - * @since 1.0.19 |
|
| 95 | - * @var string |
|
| 96 | - */ |
|
| 97 | - protected $cache_group = ''; |
|
| 98 | - |
|
| 99 | - /** |
|
| 100 | - * Stores the last error. |
|
| 101 | - * |
|
| 102 | - * @since 1.0.19 |
|
| 103 | - * @var string |
|
| 104 | - */ |
|
| 105 | - public $last_error = ''; |
|
| 106 | - |
|
| 107 | - /** |
|
| 108 | - * Stores additional meta data. |
|
| 109 | - * |
|
| 110 | - * @since 1.0.19 |
|
| 111 | - * @var array |
|
| 112 | - */ |
|
| 113 | - protected $meta_data = null; |
|
| 114 | - |
|
| 115 | - /** |
|
| 116 | - * Default constructor. |
|
| 117 | - * |
|
| 118 | - * @param int|object|array|string $read ID to load from the DB (optional) or already queried data. |
|
| 119 | - */ |
|
| 120 | - public function __construct( $read = 0 ) { |
|
| 121 | - $this->data = array_merge( $this->data, $this->extra_data ); |
|
| 122 | - $this->default_data = $this->data; |
|
| 123 | - } |
|
| 124 | - |
|
| 125 | - /** |
|
| 126 | - * Only store the object ID to avoid serializing the data object instance. |
|
| 127 | - * |
|
| 128 | - * @return array |
|
| 129 | - */ |
|
| 130 | - public function __sleep() { |
|
| 131 | - return array( 'id' ); |
|
| 132 | - } |
|
| 133 | - |
|
| 134 | - /** |
|
| 135 | - * Re-run the constructor with the object ID. |
|
| 136 | - * |
|
| 137 | - * If the object no longer exists, remove the ID. |
|
| 138 | - */ |
|
| 139 | - public function __wakeup() { |
|
| 140 | - $this->__construct( absint( $this->id ) ); |
|
| 141 | - |
|
| 142 | - if ( ! empty( $this->last_error ) ) { |
|
| 143 | - $this->set_id( 0 ); |
|
| 144 | - } |
|
| 145 | - |
|
| 146 | - } |
|
| 147 | - |
|
| 148 | - /** |
|
| 149 | - * When the object is cloned, make sure meta is duplicated correctly. |
|
| 150 | - * |
|
| 151 | - * @since 1.0.19 |
|
| 152 | - */ |
|
| 153 | - public function __clone() { |
|
| 154 | - $this->maybe_read_meta_data(); |
|
| 155 | - if ( ! empty( $this->meta_data ) ) { |
|
| 156 | - foreach ( $this->meta_data as $array_key => $meta ) { |
|
| 157 | - $this->meta_data[ $array_key ] = clone $meta; |
|
| 158 | - if ( ! empty( $meta->id ) ) { |
|
| 159 | - $this->meta_data[ $array_key ]->id = null; |
|
| 160 | - } |
|
| 161 | - } |
|
| 162 | - } |
|
| 163 | - } |
|
| 164 | - |
|
| 165 | - /** |
|
| 166 | - * Get the data store. |
|
| 167 | - * |
|
| 168 | - * @since 1.0.19 |
|
| 169 | - * @return object |
|
| 170 | - */ |
|
| 171 | - public function get_data_store() { |
|
| 172 | - return $this->data_store; |
|
| 173 | - } |
|
| 174 | - |
|
| 175 | - /** |
|
| 176 | - * Get the object type. |
|
| 177 | - * |
|
| 178 | - * @since 1.0.19 |
|
| 179 | - * @return string |
|
| 180 | - */ |
|
| 181 | - public function get_object_type() { |
|
| 182 | - return $this->object_type; |
|
| 183 | - } |
|
| 184 | - |
|
| 185 | - /** |
|
| 186 | - * Returns the unique ID for this object. |
|
| 187 | - * |
|
| 188 | - * @since 1.0.19 |
|
| 189 | - * @return int |
|
| 190 | - */ |
|
| 191 | - public function get_id() { |
|
| 192 | - return $this->id; |
|
| 193 | - } |
|
| 194 | - |
|
| 195 | - /** |
|
| 196 | - * Get form status. |
|
| 197 | - * |
|
| 198 | - * @since 1.0.19 |
|
| 199 | - * @param string $context View or edit context. |
|
| 200 | - * @return string |
|
| 201 | - */ |
|
| 202 | - public function get_status( $context = 'view' ) { |
|
| 203 | - return $this->get_prop( 'status', $context ); |
|
| 204 | - } |
|
| 205 | - |
|
| 206 | - /** |
|
| 207 | - * Delete an object, set the ID to 0, and return result. |
|
| 208 | - * |
|
| 209 | - * @since 1.0.19 |
|
| 210 | - * @param bool $force_delete Should the data be deleted permanently. |
|
| 211 | - * @return bool result |
|
| 212 | - */ |
|
| 213 | - public function delete( $force_delete = false ) { |
|
| 214 | - if ( $this->data_store && $this->get_id() ) { |
|
| 215 | - $this->data_store->delete( $this, array( 'force_delete' => $force_delete ) ); |
|
| 216 | - $this->set_id( 0 ); |
|
| 217 | - return true; |
|
| 218 | - } |
|
| 219 | - return false; |
|
| 220 | - } |
|
| 221 | - |
|
| 222 | - /** |
|
| 223 | - * Save should create or update based on object existence. |
|
| 224 | - * |
|
| 225 | - * @since 1.0.19 |
|
| 226 | - * @return int |
|
| 227 | - */ |
|
| 228 | - public function save() { |
|
| 229 | - if ( ! $this->data_store ) { |
|
| 230 | - return $this->get_id(); |
|
| 231 | - } |
|
| 232 | - |
|
| 233 | - /** |
|
| 234 | - * Trigger action before saving to the DB. Allows you to adjust object props before save. |
|
| 235 | - * |
|
| 236 | - * @param GetPaid_Data $this The object being saved. |
|
| 237 | - * @param GetPaid_Data_Store_WP $data_store The data store persisting the data. |
|
| 238 | - */ |
|
| 239 | - do_action( 'getpaid_before_' . $this->object_type . '_object_save', $this, $this->data_store ); |
|
| 240 | - |
|
| 241 | - if ( $this->get_id() ) { |
|
| 242 | - $this->data_store->update( $this ); |
|
| 243 | - } else { |
|
| 244 | - $this->data_store->create( $this ); |
|
| 245 | - } |
|
| 246 | - |
|
| 247 | - /** |
|
| 248 | - * Trigger action after saving to the DB. |
|
| 249 | - * |
|
| 250 | - * @param GetPaid_Data $this The object being saved. |
|
| 251 | - * @param GetPaid_Data_Store_WP $data_store The data store persisting the data. |
|
| 252 | - */ |
|
| 253 | - do_action( 'getpaid_after_' . $this->object_type . '_object_save', $this, $this->data_store ); |
|
| 254 | - |
|
| 255 | - return $this->get_id(); |
|
| 256 | - } |
|
| 257 | - |
|
| 258 | - /** |
|
| 259 | - * Change data to JSON format. |
|
| 260 | - * |
|
| 261 | - * @since 1.0.19 |
|
| 262 | - * @return string Data in JSON format. |
|
| 263 | - */ |
|
| 264 | - public function __toString() { |
|
| 265 | - return wp_json_encode( $this->get_data() ); |
|
| 266 | - } |
|
| 267 | - |
|
| 268 | - /** |
|
| 269 | - * Returns all data for this object. |
|
| 270 | - * |
|
| 271 | - * @since 1.0.19 |
|
| 272 | - * @return array |
|
| 273 | - */ |
|
| 274 | - public function get_data() { |
|
| 275 | - return array_merge( array( 'id' => $this->get_id() ), $this->data, array( 'meta_data' => $this->get_meta_data() ) ); |
|
| 276 | - } |
|
| 277 | - |
|
| 278 | - /** |
|
| 279 | - * Returns array of expected data keys for this object. |
|
| 280 | - * |
|
| 281 | - * @since 1.0.19 |
|
| 282 | - * @return array |
|
| 283 | - */ |
|
| 284 | - public function get_data_keys() { |
|
| 285 | - return array_keys( $this->data ); |
|
| 286 | - } |
|
| 287 | - |
|
| 288 | - /** |
|
| 289 | - * Returns all "extra" data keys for an object (for sub objects like item types). |
|
| 290 | - * |
|
| 291 | - * @since 1.0.19 |
|
| 292 | - * @return array |
|
| 293 | - */ |
|
| 294 | - public function get_extra_data_keys() { |
|
| 295 | - return array_keys( $this->extra_data ); |
|
| 296 | - } |
|
| 297 | - |
|
| 298 | - /** |
|
| 299 | - * Filter null meta values from array. |
|
| 300 | - * |
|
| 301 | - * @since 1.0.19 |
|
| 302 | - * @param mixed $meta Meta value to check. |
|
| 303 | - * @return bool |
|
| 304 | - */ |
|
| 305 | - protected function filter_null_meta( $meta ) { |
|
| 306 | - return ! is_null( $meta->value ); |
|
| 307 | - } |
|
| 308 | - |
|
| 309 | - /** |
|
| 310 | - * Get All Meta Data. |
|
| 311 | - * |
|
| 312 | - * @since 1.0.19 |
|
| 313 | - * @return array of objects. |
|
| 314 | - */ |
|
| 315 | - public function get_meta_data() { |
|
| 316 | - $this->maybe_read_meta_data(); |
|
| 317 | - return array_values( array_filter( $this->meta_data, array( $this, 'filter_null_meta' ) ) ); |
|
| 318 | - } |
|
| 319 | - |
|
| 320 | - /** |
|
| 321 | - * Check if the key is an internal one. |
|
| 322 | - * |
|
| 323 | - * @since 1.0.19 |
|
| 324 | - * @param string $key Key to check. |
|
| 325 | - * @return bool true if it's an internal key, false otherwise |
|
| 326 | - */ |
|
| 327 | - protected function is_internal_meta_key( $key ) { |
|
| 328 | - $internal_meta_key = ! empty( $key ) && $this->data_store && in_array( $key, $this->data_store->get_internal_meta_keys(), true ); |
|
| 329 | - |
|
| 330 | - if ( ! $internal_meta_key ) { |
|
| 331 | - return false; |
|
| 332 | - } |
|
| 333 | - |
|
| 334 | - $has_setter_or_getter = is_callable( array( $this, 'set_' . $key ) ) || is_callable( array( $this, 'get_' . $key ) ); |
|
| 335 | - |
|
| 336 | - if ( ! $has_setter_or_getter ) { |
|
| 337 | - return false; |
|
| 338 | - } |
|
| 339 | - |
|
| 340 | - /* translators: %s: $key Key to check */ |
|
| 341 | - getpaid_doing_it_wrong( __FUNCTION__, sprintf( __( 'Generic add/update/get meta methods should not be used for internal meta data, including "%s". Use getters and setters.', 'getpaid' ), $key ), '1.0.19' ); |
|
| 342 | - |
|
| 343 | - return true; |
|
| 344 | - } |
|
| 345 | - |
|
| 346 | - /** |
|
| 347 | - * Magic method for setting data fields. |
|
| 348 | - * |
|
| 349 | - * This method does not update custom fields in the database. |
|
| 350 | - * |
|
| 351 | - * @since 1.0.19 |
|
| 352 | - * @access public |
|
| 353 | - * |
|
| 354 | - */ |
|
| 355 | - public function __set( $key, $value ) { |
|
| 356 | - |
|
| 357 | - if ( 'id' == strtolower( $key ) ) { |
|
| 358 | - return $this->set_id( $value ); |
|
| 359 | - } |
|
| 360 | - |
|
| 361 | - if ( method_exists( $this, "set_$key") ) { |
|
| 362 | - |
|
| 363 | - /* translators: %s: $key Key to set */ |
|
| 364 | - getpaid_doing_it_wrong( __FUNCTION__, sprintf( __( 'Object data such as "%s" should not be accessed directly. Use getters and setters.', 'getpaid' ), $key ), '1.0.19' ); |
|
| 365 | - |
|
| 366 | - call_user_func( array( $this, "set_$key" ), $value ); |
|
| 367 | - } else { |
|
| 368 | - $this->set_prop( $key, $value ); |
|
| 369 | - } |
|
| 370 | - |
|
| 371 | - } |
|
| 372 | - |
|
| 373 | - /** |
|
| 24 | + /** |
|
| 25 | + * ID for this object. |
|
| 26 | + * |
|
| 27 | + * @since 1.0.19 |
|
| 28 | + * @var int |
|
| 29 | + */ |
|
| 30 | + protected $id = 0; |
|
| 31 | + |
|
| 32 | + /** |
|
| 33 | + * Core data for this object. Name value pairs (name + default value). |
|
| 34 | + * |
|
| 35 | + * @since 1.0.19 |
|
| 36 | + * @var array |
|
| 37 | + */ |
|
| 38 | + protected $data = array(); |
|
| 39 | + |
|
| 40 | + /** |
|
| 41 | + * Core data changes for this object. |
|
| 42 | + * |
|
| 43 | + * @since 1.0.19 |
|
| 44 | + * @var array |
|
| 45 | + */ |
|
| 46 | + protected $changes = array(); |
|
| 47 | + |
|
| 48 | + /** |
|
| 49 | + * This is false until the object is read from the DB. |
|
| 50 | + * |
|
| 51 | + * @since 1.0.19 |
|
| 52 | + * @var bool |
|
| 53 | + */ |
|
| 54 | + protected $object_read = false; |
|
| 55 | + |
|
| 56 | + /** |
|
| 57 | + * This is the name of this object type. |
|
| 58 | + * |
|
| 59 | + * @since 1.0.19 |
|
| 60 | + * @var string |
|
| 61 | + */ |
|
| 62 | + protected $object_type = 'data'; |
|
| 63 | + |
|
| 64 | + /** |
|
| 65 | + * Extra data for this object. Name value pairs (name + default value). |
|
| 66 | + * Used as a standard way for sub classes (like item types) to add |
|
| 67 | + * additional information to an inherited class. |
|
| 68 | + * |
|
| 69 | + * @since 1.0.19 |
|
| 70 | + * @var array |
|
| 71 | + */ |
|
| 72 | + protected $extra_data = array(); |
|
| 73 | + |
|
| 74 | + /** |
|
| 75 | + * Set to _data on construct so we can track and reset data if needed. |
|
| 76 | + * |
|
| 77 | + * @since 1.0.19 |
|
| 78 | + * @var array |
|
| 79 | + */ |
|
| 80 | + protected $default_data = array(); |
|
| 81 | + |
|
| 82 | + /** |
|
| 83 | + * Contains a reference to the data store for this class. |
|
| 84 | + * |
|
| 85 | + * @since 1.0.19 |
|
| 86 | + * @var GetPaid_Data_Store |
|
| 87 | + */ |
|
| 88 | + protected $data_store; |
|
| 89 | + |
|
| 90 | + /** |
|
| 91 | + * Stores meta in cache for future reads. |
|
| 92 | + * A group must be set to to enable caching. |
|
| 93 | + * |
|
| 94 | + * @since 1.0.19 |
|
| 95 | + * @var string |
|
| 96 | + */ |
|
| 97 | + protected $cache_group = ''; |
|
| 98 | + |
|
| 99 | + /** |
|
| 100 | + * Stores the last error. |
|
| 101 | + * |
|
| 102 | + * @since 1.0.19 |
|
| 103 | + * @var string |
|
| 104 | + */ |
|
| 105 | + public $last_error = ''; |
|
| 106 | + |
|
| 107 | + /** |
|
| 108 | + * Stores additional meta data. |
|
| 109 | + * |
|
| 110 | + * @since 1.0.19 |
|
| 111 | + * @var array |
|
| 112 | + */ |
|
| 113 | + protected $meta_data = null; |
|
| 114 | + |
|
| 115 | + /** |
|
| 116 | + * Default constructor. |
|
| 117 | + * |
|
| 118 | + * @param int|object|array|string $read ID to load from the DB (optional) or already queried data. |
|
| 119 | + */ |
|
| 120 | + public function __construct( $read = 0 ) { |
|
| 121 | + $this->data = array_merge( $this->data, $this->extra_data ); |
|
| 122 | + $this->default_data = $this->data; |
|
| 123 | + } |
|
| 124 | + |
|
| 125 | + /** |
|
| 126 | + * Only store the object ID to avoid serializing the data object instance. |
|
| 127 | + * |
|
| 128 | + * @return array |
|
| 129 | + */ |
|
| 130 | + public function __sleep() { |
|
| 131 | + return array( 'id' ); |
|
| 132 | + } |
|
| 133 | + |
|
| 134 | + /** |
|
| 135 | + * Re-run the constructor with the object ID. |
|
| 136 | + * |
|
| 137 | + * If the object no longer exists, remove the ID. |
|
| 138 | + */ |
|
| 139 | + public function __wakeup() { |
|
| 140 | + $this->__construct( absint( $this->id ) ); |
|
| 141 | + |
|
| 142 | + if ( ! empty( $this->last_error ) ) { |
|
| 143 | + $this->set_id( 0 ); |
|
| 144 | + } |
|
| 145 | + |
|
| 146 | + } |
|
| 147 | + |
|
| 148 | + /** |
|
| 149 | + * When the object is cloned, make sure meta is duplicated correctly. |
|
| 150 | + * |
|
| 151 | + * @since 1.0.19 |
|
| 152 | + */ |
|
| 153 | + public function __clone() { |
|
| 154 | + $this->maybe_read_meta_data(); |
|
| 155 | + if ( ! empty( $this->meta_data ) ) { |
|
| 156 | + foreach ( $this->meta_data as $array_key => $meta ) { |
|
| 157 | + $this->meta_data[ $array_key ] = clone $meta; |
|
| 158 | + if ( ! empty( $meta->id ) ) { |
|
| 159 | + $this->meta_data[ $array_key ]->id = null; |
|
| 160 | + } |
|
| 161 | + } |
|
| 162 | + } |
|
| 163 | + } |
|
| 164 | + |
|
| 165 | + /** |
|
| 166 | + * Get the data store. |
|
| 167 | + * |
|
| 168 | + * @since 1.0.19 |
|
| 169 | + * @return object |
|
| 170 | + */ |
|
| 171 | + public function get_data_store() { |
|
| 172 | + return $this->data_store; |
|
| 173 | + } |
|
| 174 | + |
|
| 175 | + /** |
|
| 176 | + * Get the object type. |
|
| 177 | + * |
|
| 178 | + * @since 1.0.19 |
|
| 179 | + * @return string |
|
| 180 | + */ |
|
| 181 | + public function get_object_type() { |
|
| 182 | + return $this->object_type; |
|
| 183 | + } |
|
| 184 | + |
|
| 185 | + /** |
|
| 186 | + * Returns the unique ID for this object. |
|
| 187 | + * |
|
| 188 | + * @since 1.0.19 |
|
| 189 | + * @return int |
|
| 190 | + */ |
|
| 191 | + public function get_id() { |
|
| 192 | + return $this->id; |
|
| 193 | + } |
|
| 194 | + |
|
| 195 | + /** |
|
| 196 | + * Get form status. |
|
| 197 | + * |
|
| 198 | + * @since 1.0.19 |
|
| 199 | + * @param string $context View or edit context. |
|
| 200 | + * @return string |
|
| 201 | + */ |
|
| 202 | + public function get_status( $context = 'view' ) { |
|
| 203 | + return $this->get_prop( 'status', $context ); |
|
| 204 | + } |
|
| 205 | + |
|
| 206 | + /** |
|
| 207 | + * Delete an object, set the ID to 0, and return result. |
|
| 208 | + * |
|
| 209 | + * @since 1.0.19 |
|
| 210 | + * @param bool $force_delete Should the data be deleted permanently. |
|
| 211 | + * @return bool result |
|
| 212 | + */ |
|
| 213 | + public function delete( $force_delete = false ) { |
|
| 214 | + if ( $this->data_store && $this->get_id() ) { |
|
| 215 | + $this->data_store->delete( $this, array( 'force_delete' => $force_delete ) ); |
|
| 216 | + $this->set_id( 0 ); |
|
| 217 | + return true; |
|
| 218 | + } |
|
| 219 | + return false; |
|
| 220 | + } |
|
| 221 | + |
|
| 222 | + /** |
|
| 223 | + * Save should create or update based on object existence. |
|
| 224 | + * |
|
| 225 | + * @since 1.0.19 |
|
| 226 | + * @return int |
|
| 227 | + */ |
|
| 228 | + public function save() { |
|
| 229 | + if ( ! $this->data_store ) { |
|
| 230 | + return $this->get_id(); |
|
| 231 | + } |
|
| 232 | + |
|
| 233 | + /** |
|
| 234 | + * Trigger action before saving to the DB. Allows you to adjust object props before save. |
|
| 235 | + * |
|
| 236 | + * @param GetPaid_Data $this The object being saved. |
|
| 237 | + * @param GetPaid_Data_Store_WP $data_store The data store persisting the data. |
|
| 238 | + */ |
|
| 239 | + do_action( 'getpaid_before_' . $this->object_type . '_object_save', $this, $this->data_store ); |
|
| 240 | + |
|
| 241 | + if ( $this->get_id() ) { |
|
| 242 | + $this->data_store->update( $this ); |
|
| 243 | + } else { |
|
| 244 | + $this->data_store->create( $this ); |
|
| 245 | + } |
|
| 246 | + |
|
| 247 | + /** |
|
| 248 | + * Trigger action after saving to the DB. |
|
| 249 | + * |
|
| 250 | + * @param GetPaid_Data $this The object being saved. |
|
| 251 | + * @param GetPaid_Data_Store_WP $data_store The data store persisting the data. |
|
| 252 | + */ |
|
| 253 | + do_action( 'getpaid_after_' . $this->object_type . '_object_save', $this, $this->data_store ); |
|
| 254 | + |
|
| 255 | + return $this->get_id(); |
|
| 256 | + } |
|
| 257 | + |
|
| 258 | + /** |
|
| 259 | + * Change data to JSON format. |
|
| 260 | + * |
|
| 261 | + * @since 1.0.19 |
|
| 262 | + * @return string Data in JSON format. |
|
| 263 | + */ |
|
| 264 | + public function __toString() { |
|
| 265 | + return wp_json_encode( $this->get_data() ); |
|
| 266 | + } |
|
| 267 | + |
|
| 268 | + /** |
|
| 269 | + * Returns all data for this object. |
|
| 270 | + * |
|
| 271 | + * @since 1.0.19 |
|
| 272 | + * @return array |
|
| 273 | + */ |
|
| 274 | + public function get_data() { |
|
| 275 | + return array_merge( array( 'id' => $this->get_id() ), $this->data, array( 'meta_data' => $this->get_meta_data() ) ); |
|
| 276 | + } |
|
| 277 | + |
|
| 278 | + /** |
|
| 279 | + * Returns array of expected data keys for this object. |
|
| 280 | + * |
|
| 281 | + * @since 1.0.19 |
|
| 282 | + * @return array |
|
| 283 | + */ |
|
| 284 | + public function get_data_keys() { |
|
| 285 | + return array_keys( $this->data ); |
|
| 286 | + } |
|
| 287 | + |
|
| 288 | + /** |
|
| 289 | + * Returns all "extra" data keys for an object (for sub objects like item types). |
|
| 290 | + * |
|
| 291 | + * @since 1.0.19 |
|
| 292 | + * @return array |
|
| 293 | + */ |
|
| 294 | + public function get_extra_data_keys() { |
|
| 295 | + return array_keys( $this->extra_data ); |
|
| 296 | + } |
|
| 297 | + |
|
| 298 | + /** |
|
| 299 | + * Filter null meta values from array. |
|
| 300 | + * |
|
| 301 | + * @since 1.0.19 |
|
| 302 | + * @param mixed $meta Meta value to check. |
|
| 303 | + * @return bool |
|
| 304 | + */ |
|
| 305 | + protected function filter_null_meta( $meta ) { |
|
| 306 | + return ! is_null( $meta->value ); |
|
| 307 | + } |
|
| 308 | + |
|
| 309 | + /** |
|
| 310 | + * Get All Meta Data. |
|
| 311 | + * |
|
| 312 | + * @since 1.0.19 |
|
| 313 | + * @return array of objects. |
|
| 314 | + */ |
|
| 315 | + public function get_meta_data() { |
|
| 316 | + $this->maybe_read_meta_data(); |
|
| 317 | + return array_values( array_filter( $this->meta_data, array( $this, 'filter_null_meta' ) ) ); |
|
| 318 | + } |
|
| 319 | + |
|
| 320 | + /** |
|
| 321 | + * Check if the key is an internal one. |
|
| 322 | + * |
|
| 323 | + * @since 1.0.19 |
|
| 324 | + * @param string $key Key to check. |
|
| 325 | + * @return bool true if it's an internal key, false otherwise |
|
| 326 | + */ |
|
| 327 | + protected function is_internal_meta_key( $key ) { |
|
| 328 | + $internal_meta_key = ! empty( $key ) && $this->data_store && in_array( $key, $this->data_store->get_internal_meta_keys(), true ); |
|
| 329 | + |
|
| 330 | + if ( ! $internal_meta_key ) { |
|
| 331 | + return false; |
|
| 332 | + } |
|
| 333 | + |
|
| 334 | + $has_setter_or_getter = is_callable( array( $this, 'set_' . $key ) ) || is_callable( array( $this, 'get_' . $key ) ); |
|
| 335 | + |
|
| 336 | + if ( ! $has_setter_or_getter ) { |
|
| 337 | + return false; |
|
| 338 | + } |
|
| 339 | + |
|
| 340 | + /* translators: %s: $key Key to check */ |
|
| 341 | + getpaid_doing_it_wrong( __FUNCTION__, sprintf( __( 'Generic add/update/get meta methods should not be used for internal meta data, including "%s". Use getters and setters.', 'getpaid' ), $key ), '1.0.19' ); |
|
| 342 | + |
|
| 343 | + return true; |
|
| 344 | + } |
|
| 345 | + |
|
| 346 | + /** |
|
| 347 | + * Magic method for setting data fields. |
|
| 348 | + * |
|
| 349 | + * This method does not update custom fields in the database. |
|
| 350 | + * |
|
| 351 | + * @since 1.0.19 |
|
| 352 | + * @access public |
|
| 353 | + * |
|
| 354 | + */ |
|
| 355 | + public function __set( $key, $value ) { |
|
| 356 | + |
|
| 357 | + if ( 'id' == strtolower( $key ) ) { |
|
| 358 | + return $this->set_id( $value ); |
|
| 359 | + } |
|
| 360 | + |
|
| 361 | + if ( method_exists( $this, "set_$key") ) { |
|
| 362 | + |
|
| 363 | + /* translators: %s: $key Key to set */ |
|
| 364 | + getpaid_doing_it_wrong( __FUNCTION__, sprintf( __( 'Object data such as "%s" should not be accessed directly. Use getters and setters.', 'getpaid' ), $key ), '1.0.19' ); |
|
| 365 | + |
|
| 366 | + call_user_func( array( $this, "set_$key" ), $value ); |
|
| 367 | + } else { |
|
| 368 | + $this->set_prop( $key, $value ); |
|
| 369 | + } |
|
| 370 | + |
|
| 371 | + } |
|
| 372 | + |
|
| 373 | + /** |
|
| 374 | 374 | * Margic method for retrieving a property. |
| 375 | 375 | */ |
| 376 | 376 | public function __get( $key ) { |
@@ -378,10 +378,10 @@ discard block |
||
| 378 | 378 | // Check if we have a helper method for that. |
| 379 | 379 | if ( method_exists( $this, 'get_' . $key ) ) { |
| 380 | 380 | |
| 381 | - if ( 'post_type' != $key ) { |
|
| 382 | - /* translators: %s: $key Key to set */ |
|
| 383 | - getpaid_doing_it_wrong( __FUNCTION__, sprintf( __( 'Object data such as "%s" should not be accessed directly. Use getters and setters.', 'getpaid' ), $key ), '1.0.19' ); |
|
| 384 | - } |
|
| 381 | + if ( 'post_type' != $key ) { |
|
| 382 | + /* translators: %s: $key Key to set */ |
|
| 383 | + getpaid_doing_it_wrong( __FUNCTION__, sprintf( __( 'Object data such as "%s" should not be accessed directly. Use getters and setters.', 'getpaid' ), $key ), '1.0.19' ); |
|
| 384 | + } |
|
| 385 | 385 | |
| 386 | 386 | return call_user_func( array( $this, 'get_' . $key ) ); |
| 387 | 387 | } |
@@ -391,512 +391,512 @@ discard block |
||
| 391 | 391 | return $this->post->$key; |
| 392 | 392 | } |
| 393 | 393 | |
| 394 | - return $this->get_prop( $key ); |
|
| 395 | - |
|
| 396 | - } |
|
| 397 | - |
|
| 398 | - /** |
|
| 399 | - * Get Meta Data by Key. |
|
| 400 | - * |
|
| 401 | - * @since 1.0.19 |
|
| 402 | - * @param string $key Meta Key. |
|
| 403 | - * @param bool $single return first found meta with key, or all with $key. |
|
| 404 | - * @param string $context What the value is for. Valid values are view and edit. |
|
| 405 | - * @return mixed |
|
| 406 | - */ |
|
| 407 | - public function get_meta( $key = '', $single = true, $context = 'view' ) { |
|
| 408 | - |
|
| 409 | - // Check if this is an internal meta key. |
|
| 410 | - $_key = str_replace( '_wpinv', '', $key ); |
|
| 411 | - $_key = str_replace( 'wpinv', '', $_key ); |
|
| 412 | - if ( $this->is_internal_meta_key( $_key ) ) { |
|
| 413 | - $function = 'get_' . $_key; |
|
| 414 | - |
|
| 415 | - if ( is_callable( array( $this, $function ) ) ) { |
|
| 416 | - return $this->{$function}(); |
|
| 417 | - } |
|
| 418 | - } |
|
| 419 | - |
|
| 420 | - // Read the meta data if not yet read. |
|
| 421 | - $this->maybe_read_meta_data(); |
|
| 422 | - $meta_data = $this->get_meta_data(); |
|
| 423 | - $array_keys = array_keys( wp_list_pluck( $meta_data, 'key' ), $key, true ); |
|
| 424 | - $value = $single ? '' : array(); |
|
| 425 | - |
|
| 426 | - if ( ! empty( $array_keys ) ) { |
|
| 427 | - // We don't use the $this->meta_data property directly here because we don't want meta with a null value (i.e. meta which has been deleted via $this->delete_meta_data()). |
|
| 428 | - if ( $single ) { |
|
| 429 | - $value = $meta_data[ current( $array_keys ) ]->value; |
|
| 430 | - } else { |
|
| 431 | - $value = array_intersect_key( $meta_data, array_flip( $array_keys ) ); |
|
| 432 | - } |
|
| 433 | - } |
|
| 434 | - |
|
| 435 | - if ( 'view' === $context ) { |
|
| 436 | - $value = apply_filters( $this->get_hook_prefix() . $key, $value, $this ); |
|
| 437 | - } |
|
| 438 | - |
|
| 439 | - return $value; |
|
| 440 | - } |
|
| 441 | - |
|
| 442 | - /** |
|
| 443 | - * See if meta data exists, since get_meta always returns a '' or array(). |
|
| 444 | - * |
|
| 445 | - * @since 1.0.19 |
|
| 446 | - * @param string $key Meta Key. |
|
| 447 | - * @return boolean |
|
| 448 | - */ |
|
| 449 | - public function meta_exists( $key = '' ) { |
|
| 450 | - $this->maybe_read_meta_data(); |
|
| 451 | - $array_keys = wp_list_pluck( $this->get_meta_data(), 'key' ); |
|
| 452 | - return in_array( $key, $array_keys, true ); |
|
| 453 | - } |
|
| 454 | - |
|
| 455 | - /** |
|
| 456 | - * Set all meta data from array. |
|
| 457 | - * |
|
| 458 | - * @since 1.0.19 |
|
| 459 | - * @param array $data Key/Value pairs. |
|
| 460 | - */ |
|
| 461 | - public function set_meta_data( $data ) { |
|
| 462 | - if ( ! empty( $data ) && is_array( $data ) ) { |
|
| 463 | - $this->maybe_read_meta_data(); |
|
| 464 | - foreach ( $data as $meta ) { |
|
| 465 | - $meta = (array) $meta; |
|
| 466 | - if ( isset( $meta['key'], $meta['value'], $meta['id'] ) ) { |
|
| 467 | - $this->meta_data[] = new GetPaid_Meta_Data( |
|
| 468 | - array( |
|
| 469 | - 'id' => $meta['id'], |
|
| 470 | - 'key' => $meta['key'], |
|
| 471 | - 'value' => $meta['value'], |
|
| 472 | - ) |
|
| 473 | - ); |
|
| 474 | - } |
|
| 475 | - } |
|
| 476 | - } |
|
| 477 | - } |
|
| 478 | - |
|
| 479 | - /** |
|
| 480 | - * Add meta data. |
|
| 481 | - * |
|
| 482 | - * @since 1.0.19 |
|
| 483 | - * |
|
| 484 | - * @param string $key Meta key. |
|
| 485 | - * @param string|array $value Meta value. |
|
| 486 | - * @param bool $unique Should this be a unique key?. |
|
| 487 | - */ |
|
| 488 | - public function add_meta_data( $key, $value, $unique = false ) { |
|
| 489 | - if ( $this->is_internal_meta_key( $key ) ) { |
|
| 490 | - $function = 'set_' . $key; |
|
| 491 | - |
|
| 492 | - if ( is_callable( array( $this, $function ) ) ) { |
|
| 493 | - return $this->{$function}( $value ); |
|
| 494 | - } |
|
| 495 | - } |
|
| 496 | - |
|
| 497 | - $this->maybe_read_meta_data(); |
|
| 498 | - if ( $unique ) { |
|
| 499 | - $this->delete_meta_data( $key ); |
|
| 500 | - } |
|
| 501 | - $this->meta_data[] = new GetPaid_Meta_Data( |
|
| 502 | - array( |
|
| 503 | - 'key' => $key, |
|
| 504 | - 'value' => $value, |
|
| 505 | - ) |
|
| 506 | - ); |
|
| 507 | - } |
|
| 508 | - |
|
| 509 | - /** |
|
| 510 | - * Update meta data by key or ID, if provided. |
|
| 511 | - * |
|
| 512 | - * @since 1.0.19 |
|
| 513 | - * |
|
| 514 | - * @param string $key Meta key. |
|
| 515 | - * @param string|array $value Meta value. |
|
| 516 | - * @param int $meta_id Meta ID. |
|
| 517 | - */ |
|
| 518 | - public function update_meta_data( $key, $value, $meta_id = 0 ) { |
|
| 519 | - if ( $this->is_internal_meta_key( $key ) ) { |
|
| 520 | - $function = 'set_' . $key; |
|
| 521 | - |
|
| 522 | - if ( is_callable( array( $this, $function ) ) ) { |
|
| 523 | - return $this->{$function}( $value ); |
|
| 524 | - } |
|
| 525 | - } |
|
| 526 | - |
|
| 527 | - $this->maybe_read_meta_data(); |
|
| 528 | - |
|
| 529 | - $array_key = false; |
|
| 530 | - |
|
| 531 | - if ( $meta_id ) { |
|
| 532 | - $array_keys = array_keys( wp_list_pluck( $this->meta_data, 'id' ), $meta_id, true ); |
|
| 533 | - $array_key = $array_keys ? current( $array_keys ) : false; |
|
| 534 | - } else { |
|
| 535 | - // Find matches by key. |
|
| 536 | - $matches = array(); |
|
| 537 | - foreach ( $this->meta_data as $meta_data_array_key => $meta ) { |
|
| 538 | - if ( $meta->key === $key ) { |
|
| 539 | - $matches[] = $meta_data_array_key; |
|
| 540 | - } |
|
| 541 | - } |
|
| 542 | - |
|
| 543 | - if ( ! empty( $matches ) ) { |
|
| 544 | - // Set matches to null so only one key gets the new value. |
|
| 545 | - foreach ( $matches as $meta_data_array_key ) { |
|
| 546 | - $this->meta_data[ $meta_data_array_key ]->value = null; |
|
| 547 | - } |
|
| 548 | - $array_key = current( $matches ); |
|
| 549 | - } |
|
| 550 | - } |
|
| 551 | - |
|
| 552 | - if ( false !== $array_key ) { |
|
| 553 | - $meta = $this->meta_data[ $array_key ]; |
|
| 554 | - $meta->key = $key; |
|
| 555 | - $meta->value = $value; |
|
| 556 | - } else { |
|
| 557 | - $this->add_meta_data( $key, $value, true ); |
|
| 558 | - } |
|
| 559 | - } |
|
| 560 | - |
|
| 561 | - /** |
|
| 562 | - * Delete meta data. |
|
| 563 | - * |
|
| 564 | - * @since 1.0.19 |
|
| 565 | - * @param string $key Meta key. |
|
| 566 | - */ |
|
| 567 | - public function delete_meta_data( $key ) { |
|
| 568 | - $this->maybe_read_meta_data(); |
|
| 569 | - $array_keys = array_keys( wp_list_pluck( $this->meta_data, 'key' ), $key, true ); |
|
| 570 | - |
|
| 571 | - if ( $array_keys ) { |
|
| 572 | - foreach ( $array_keys as $array_key ) { |
|
| 573 | - $this->meta_data[ $array_key ]->value = null; |
|
| 574 | - } |
|
| 575 | - } |
|
| 576 | - } |
|
| 577 | - |
|
| 578 | - /** |
|
| 579 | - * Delete meta data. |
|
| 580 | - * |
|
| 581 | - * @since 1.0.19 |
|
| 582 | - * @param int $mid Meta ID. |
|
| 583 | - */ |
|
| 584 | - public function delete_meta_data_by_mid( $mid ) { |
|
| 585 | - $this->maybe_read_meta_data(); |
|
| 586 | - $array_keys = array_keys( wp_list_pluck( $this->meta_data, 'id' ), (int) $mid, true ); |
|
| 587 | - |
|
| 588 | - if ( $array_keys ) { |
|
| 589 | - foreach ( $array_keys as $array_key ) { |
|
| 590 | - $this->meta_data[ $array_key ]->value = null; |
|
| 591 | - } |
|
| 592 | - } |
|
| 593 | - } |
|
| 594 | - |
|
| 595 | - /** |
|
| 596 | - * Read meta data if null. |
|
| 597 | - * |
|
| 598 | - * @since 1.0.19 |
|
| 599 | - */ |
|
| 600 | - protected function maybe_read_meta_data() { |
|
| 601 | - if ( is_null( $this->meta_data ) ) { |
|
| 602 | - $this->read_meta_data(); |
|
| 603 | - } |
|
| 604 | - } |
|
| 605 | - |
|
| 606 | - /** |
|
| 607 | - * Read Meta Data from the database. Ignore any internal properties. |
|
| 608 | - * Uses it's own caches because get_metadata does not provide meta_ids. |
|
| 609 | - * |
|
| 610 | - * @since 1.0.19 |
|
| 611 | - * @param bool $force_read True to force a new DB read (and update cache). |
|
| 612 | - */ |
|
| 613 | - public function read_meta_data( $force_read = false ) { |
|
| 614 | - |
|
| 615 | - // Reset meta data. |
|
| 616 | - $this->meta_data = array(); |
|
| 617 | - |
|
| 618 | - // Maybe abort early. |
|
| 619 | - if ( ! $this->get_id() || ! $this->data_store ) { |
|
| 620 | - return; |
|
| 621 | - } |
|
| 622 | - |
|
| 623 | - // Only read from cache if the cache key is set. |
|
| 624 | - $cache_key = null; |
|
| 625 | - if ( ! $force_read && ! empty( $this->cache_group ) ) { |
|
| 626 | - $cache_key = GetPaid_Cache_Helper::get_cache_prefix( $this->cache_group ) . GetPaid_Cache_Helper::get_cache_prefix( 'object_' . $this->get_id() ) . 'object_meta_' . $this->get_id(); |
|
| 627 | - $raw_meta_data = wp_cache_get( $cache_key, $this->cache_group ); |
|
| 628 | - } |
|
| 629 | - |
|
| 630 | - // Should we force read? |
|
| 631 | - if ( empty( $raw_meta_data ) ) { |
|
| 632 | - $raw_meta_data = $this->data_store->read_meta( $this ); |
|
| 633 | - |
|
| 634 | - if ( ! empty( $cache_key ) ) { |
|
| 635 | - wp_cache_set( $cache_key, $raw_meta_data, $this->cache_group ); |
|
| 636 | - } |
|
| 637 | - |
|
| 638 | - } |
|
| 639 | - |
|
| 640 | - // Set meta data. |
|
| 641 | - if ( is_array( $raw_meta_data ) ) { |
|
| 642 | - |
|
| 643 | - foreach ( $raw_meta_data as $meta ) { |
|
| 644 | - $this->meta_data[] = new GetPaid_Meta_Data( |
|
| 645 | - array( |
|
| 646 | - 'id' => (int) $meta->meta_id, |
|
| 647 | - 'key' => $meta->meta_key, |
|
| 648 | - 'value' => maybe_unserialize( $meta->meta_value ), |
|
| 649 | - ) |
|
| 650 | - ); |
|
| 651 | - } |
|
| 652 | - |
|
| 653 | - } |
|
| 654 | - |
|
| 655 | - } |
|
| 656 | - |
|
| 657 | - /** |
|
| 658 | - * Update Meta Data in the database. |
|
| 659 | - * |
|
| 660 | - * @since 1.0.19 |
|
| 661 | - */ |
|
| 662 | - public function save_meta_data() { |
|
| 663 | - if ( ! $this->data_store || is_null( $this->meta_data ) ) { |
|
| 664 | - return; |
|
| 665 | - } |
|
| 666 | - foreach ( $this->meta_data as $array_key => $meta ) { |
|
| 667 | - if ( is_null( $meta->value ) ) { |
|
| 668 | - if ( ! empty( $meta->id ) ) { |
|
| 669 | - $this->data_store->delete_meta( $this, $meta ); |
|
| 670 | - unset( $this->meta_data[ $array_key ] ); |
|
| 671 | - } |
|
| 672 | - } elseif ( empty( $meta->id ) ) { |
|
| 673 | - $meta->id = $this->data_store->add_meta( $this, $meta ); |
|
| 674 | - $meta->apply_changes(); |
|
| 675 | - } else { |
|
| 676 | - if ( $meta->get_changes() ) { |
|
| 677 | - $this->data_store->update_meta( $this, $meta ); |
|
| 678 | - $meta->apply_changes(); |
|
| 679 | - } |
|
| 680 | - } |
|
| 681 | - } |
|
| 682 | - if ( ! empty( $this->cache_group ) ) { |
|
| 683 | - $cache_key = GetPaid_Cache_Helper::get_cache_prefix( $this->cache_group ) . GetPaid_Cache_Helper::get_cache_prefix( 'object_' . $this->get_id() ) . 'object_meta_' . $this->get_id(); |
|
| 684 | - wp_cache_delete( $cache_key, $this->cache_group ); |
|
| 685 | - } |
|
| 686 | - } |
|
| 687 | - |
|
| 688 | - /** |
|
| 689 | - * Set ID. |
|
| 690 | - * |
|
| 691 | - * @since 1.0.19 |
|
| 692 | - * @param int $id ID. |
|
| 693 | - */ |
|
| 694 | - public function set_id( $id ) { |
|
| 695 | - $this->id = absint( $id ); |
|
| 696 | - } |
|
| 697 | - |
|
| 698 | - /** |
|
| 699 | - * Sets item status. |
|
| 700 | - * |
|
| 701 | - * @since 1.0.19 |
|
| 702 | - * @param string $status New status. |
|
| 703 | - * @return array details of change. |
|
| 704 | - */ |
|
| 705 | - public function set_status( $status ) { |
|
| 394 | + return $this->get_prop( $key ); |
|
| 395 | + |
|
| 396 | + } |
|
| 397 | + |
|
| 398 | + /** |
|
| 399 | + * Get Meta Data by Key. |
|
| 400 | + * |
|
| 401 | + * @since 1.0.19 |
|
| 402 | + * @param string $key Meta Key. |
|
| 403 | + * @param bool $single return first found meta with key, or all with $key. |
|
| 404 | + * @param string $context What the value is for. Valid values are view and edit. |
|
| 405 | + * @return mixed |
|
| 406 | + */ |
|
| 407 | + public function get_meta( $key = '', $single = true, $context = 'view' ) { |
|
| 408 | + |
|
| 409 | + // Check if this is an internal meta key. |
|
| 410 | + $_key = str_replace( '_wpinv', '', $key ); |
|
| 411 | + $_key = str_replace( 'wpinv', '', $_key ); |
|
| 412 | + if ( $this->is_internal_meta_key( $_key ) ) { |
|
| 413 | + $function = 'get_' . $_key; |
|
| 414 | + |
|
| 415 | + if ( is_callable( array( $this, $function ) ) ) { |
|
| 416 | + return $this->{$function}(); |
|
| 417 | + } |
|
| 418 | + } |
|
| 419 | + |
|
| 420 | + // Read the meta data if not yet read. |
|
| 421 | + $this->maybe_read_meta_data(); |
|
| 422 | + $meta_data = $this->get_meta_data(); |
|
| 423 | + $array_keys = array_keys( wp_list_pluck( $meta_data, 'key' ), $key, true ); |
|
| 424 | + $value = $single ? '' : array(); |
|
| 425 | + |
|
| 426 | + if ( ! empty( $array_keys ) ) { |
|
| 427 | + // We don't use the $this->meta_data property directly here because we don't want meta with a null value (i.e. meta which has been deleted via $this->delete_meta_data()). |
|
| 428 | + if ( $single ) { |
|
| 429 | + $value = $meta_data[ current( $array_keys ) ]->value; |
|
| 430 | + } else { |
|
| 431 | + $value = array_intersect_key( $meta_data, array_flip( $array_keys ) ); |
|
| 432 | + } |
|
| 433 | + } |
|
| 434 | + |
|
| 435 | + if ( 'view' === $context ) { |
|
| 436 | + $value = apply_filters( $this->get_hook_prefix() . $key, $value, $this ); |
|
| 437 | + } |
|
| 438 | + |
|
| 439 | + return $value; |
|
| 440 | + } |
|
| 441 | + |
|
| 442 | + /** |
|
| 443 | + * See if meta data exists, since get_meta always returns a '' or array(). |
|
| 444 | + * |
|
| 445 | + * @since 1.0.19 |
|
| 446 | + * @param string $key Meta Key. |
|
| 447 | + * @return boolean |
|
| 448 | + */ |
|
| 449 | + public function meta_exists( $key = '' ) { |
|
| 450 | + $this->maybe_read_meta_data(); |
|
| 451 | + $array_keys = wp_list_pluck( $this->get_meta_data(), 'key' ); |
|
| 452 | + return in_array( $key, $array_keys, true ); |
|
| 453 | + } |
|
| 454 | + |
|
| 455 | + /** |
|
| 456 | + * Set all meta data from array. |
|
| 457 | + * |
|
| 458 | + * @since 1.0.19 |
|
| 459 | + * @param array $data Key/Value pairs. |
|
| 460 | + */ |
|
| 461 | + public function set_meta_data( $data ) { |
|
| 462 | + if ( ! empty( $data ) && is_array( $data ) ) { |
|
| 463 | + $this->maybe_read_meta_data(); |
|
| 464 | + foreach ( $data as $meta ) { |
|
| 465 | + $meta = (array) $meta; |
|
| 466 | + if ( isset( $meta['key'], $meta['value'], $meta['id'] ) ) { |
|
| 467 | + $this->meta_data[] = new GetPaid_Meta_Data( |
|
| 468 | + array( |
|
| 469 | + 'id' => $meta['id'], |
|
| 470 | + 'key' => $meta['key'], |
|
| 471 | + 'value' => $meta['value'], |
|
| 472 | + ) |
|
| 473 | + ); |
|
| 474 | + } |
|
| 475 | + } |
|
| 476 | + } |
|
| 477 | + } |
|
| 478 | + |
|
| 479 | + /** |
|
| 480 | + * Add meta data. |
|
| 481 | + * |
|
| 482 | + * @since 1.0.19 |
|
| 483 | + * |
|
| 484 | + * @param string $key Meta key. |
|
| 485 | + * @param string|array $value Meta value. |
|
| 486 | + * @param bool $unique Should this be a unique key?. |
|
| 487 | + */ |
|
| 488 | + public function add_meta_data( $key, $value, $unique = false ) { |
|
| 489 | + if ( $this->is_internal_meta_key( $key ) ) { |
|
| 490 | + $function = 'set_' . $key; |
|
| 491 | + |
|
| 492 | + if ( is_callable( array( $this, $function ) ) ) { |
|
| 493 | + return $this->{$function}( $value ); |
|
| 494 | + } |
|
| 495 | + } |
|
| 496 | + |
|
| 497 | + $this->maybe_read_meta_data(); |
|
| 498 | + if ( $unique ) { |
|
| 499 | + $this->delete_meta_data( $key ); |
|
| 500 | + } |
|
| 501 | + $this->meta_data[] = new GetPaid_Meta_Data( |
|
| 502 | + array( |
|
| 503 | + 'key' => $key, |
|
| 504 | + 'value' => $value, |
|
| 505 | + ) |
|
| 506 | + ); |
|
| 507 | + } |
|
| 508 | + |
|
| 509 | + /** |
|
| 510 | + * Update meta data by key or ID, if provided. |
|
| 511 | + * |
|
| 512 | + * @since 1.0.19 |
|
| 513 | + * |
|
| 514 | + * @param string $key Meta key. |
|
| 515 | + * @param string|array $value Meta value. |
|
| 516 | + * @param int $meta_id Meta ID. |
|
| 517 | + */ |
|
| 518 | + public function update_meta_data( $key, $value, $meta_id = 0 ) { |
|
| 519 | + if ( $this->is_internal_meta_key( $key ) ) { |
|
| 520 | + $function = 'set_' . $key; |
|
| 521 | + |
|
| 522 | + if ( is_callable( array( $this, $function ) ) ) { |
|
| 523 | + return $this->{$function}( $value ); |
|
| 524 | + } |
|
| 525 | + } |
|
| 526 | + |
|
| 527 | + $this->maybe_read_meta_data(); |
|
| 528 | + |
|
| 529 | + $array_key = false; |
|
| 530 | + |
|
| 531 | + if ( $meta_id ) { |
|
| 532 | + $array_keys = array_keys( wp_list_pluck( $this->meta_data, 'id' ), $meta_id, true ); |
|
| 533 | + $array_key = $array_keys ? current( $array_keys ) : false; |
|
| 534 | + } else { |
|
| 535 | + // Find matches by key. |
|
| 536 | + $matches = array(); |
|
| 537 | + foreach ( $this->meta_data as $meta_data_array_key => $meta ) { |
|
| 538 | + if ( $meta->key === $key ) { |
|
| 539 | + $matches[] = $meta_data_array_key; |
|
| 540 | + } |
|
| 541 | + } |
|
| 542 | + |
|
| 543 | + if ( ! empty( $matches ) ) { |
|
| 544 | + // Set matches to null so only one key gets the new value. |
|
| 545 | + foreach ( $matches as $meta_data_array_key ) { |
|
| 546 | + $this->meta_data[ $meta_data_array_key ]->value = null; |
|
| 547 | + } |
|
| 548 | + $array_key = current( $matches ); |
|
| 549 | + } |
|
| 550 | + } |
|
| 551 | + |
|
| 552 | + if ( false !== $array_key ) { |
|
| 553 | + $meta = $this->meta_data[ $array_key ]; |
|
| 554 | + $meta->key = $key; |
|
| 555 | + $meta->value = $value; |
|
| 556 | + } else { |
|
| 557 | + $this->add_meta_data( $key, $value, true ); |
|
| 558 | + } |
|
| 559 | + } |
|
| 560 | + |
|
| 561 | + /** |
|
| 562 | + * Delete meta data. |
|
| 563 | + * |
|
| 564 | + * @since 1.0.19 |
|
| 565 | + * @param string $key Meta key. |
|
| 566 | + */ |
|
| 567 | + public function delete_meta_data( $key ) { |
|
| 568 | + $this->maybe_read_meta_data(); |
|
| 569 | + $array_keys = array_keys( wp_list_pluck( $this->meta_data, 'key' ), $key, true ); |
|
| 570 | + |
|
| 571 | + if ( $array_keys ) { |
|
| 572 | + foreach ( $array_keys as $array_key ) { |
|
| 573 | + $this->meta_data[ $array_key ]->value = null; |
|
| 574 | + } |
|
| 575 | + } |
|
| 576 | + } |
|
| 577 | + |
|
| 578 | + /** |
|
| 579 | + * Delete meta data. |
|
| 580 | + * |
|
| 581 | + * @since 1.0.19 |
|
| 582 | + * @param int $mid Meta ID. |
|
| 583 | + */ |
|
| 584 | + public function delete_meta_data_by_mid( $mid ) { |
|
| 585 | + $this->maybe_read_meta_data(); |
|
| 586 | + $array_keys = array_keys( wp_list_pluck( $this->meta_data, 'id' ), (int) $mid, true ); |
|
| 587 | + |
|
| 588 | + if ( $array_keys ) { |
|
| 589 | + foreach ( $array_keys as $array_key ) { |
|
| 590 | + $this->meta_data[ $array_key ]->value = null; |
|
| 591 | + } |
|
| 592 | + } |
|
| 593 | + } |
|
| 594 | + |
|
| 595 | + /** |
|
| 596 | + * Read meta data if null. |
|
| 597 | + * |
|
| 598 | + * @since 1.0.19 |
|
| 599 | + */ |
|
| 600 | + protected function maybe_read_meta_data() { |
|
| 601 | + if ( is_null( $this->meta_data ) ) { |
|
| 602 | + $this->read_meta_data(); |
|
| 603 | + } |
|
| 604 | + } |
|
| 605 | + |
|
| 606 | + /** |
|
| 607 | + * Read Meta Data from the database. Ignore any internal properties. |
|
| 608 | + * Uses it's own caches because get_metadata does not provide meta_ids. |
|
| 609 | + * |
|
| 610 | + * @since 1.0.19 |
|
| 611 | + * @param bool $force_read True to force a new DB read (and update cache). |
|
| 612 | + */ |
|
| 613 | + public function read_meta_data( $force_read = false ) { |
|
| 614 | + |
|
| 615 | + // Reset meta data. |
|
| 616 | + $this->meta_data = array(); |
|
| 617 | + |
|
| 618 | + // Maybe abort early. |
|
| 619 | + if ( ! $this->get_id() || ! $this->data_store ) { |
|
| 620 | + return; |
|
| 621 | + } |
|
| 622 | + |
|
| 623 | + // Only read from cache if the cache key is set. |
|
| 624 | + $cache_key = null; |
|
| 625 | + if ( ! $force_read && ! empty( $this->cache_group ) ) { |
|
| 626 | + $cache_key = GetPaid_Cache_Helper::get_cache_prefix( $this->cache_group ) . GetPaid_Cache_Helper::get_cache_prefix( 'object_' . $this->get_id() ) . 'object_meta_' . $this->get_id(); |
|
| 627 | + $raw_meta_data = wp_cache_get( $cache_key, $this->cache_group ); |
|
| 628 | + } |
|
| 629 | + |
|
| 630 | + // Should we force read? |
|
| 631 | + if ( empty( $raw_meta_data ) ) { |
|
| 632 | + $raw_meta_data = $this->data_store->read_meta( $this ); |
|
| 633 | + |
|
| 634 | + if ( ! empty( $cache_key ) ) { |
|
| 635 | + wp_cache_set( $cache_key, $raw_meta_data, $this->cache_group ); |
|
| 636 | + } |
|
| 637 | + |
|
| 638 | + } |
|
| 639 | + |
|
| 640 | + // Set meta data. |
|
| 641 | + if ( is_array( $raw_meta_data ) ) { |
|
| 642 | + |
|
| 643 | + foreach ( $raw_meta_data as $meta ) { |
|
| 644 | + $this->meta_data[] = new GetPaid_Meta_Data( |
|
| 645 | + array( |
|
| 646 | + 'id' => (int) $meta->meta_id, |
|
| 647 | + 'key' => $meta->meta_key, |
|
| 648 | + 'value' => maybe_unserialize( $meta->meta_value ), |
|
| 649 | + ) |
|
| 650 | + ); |
|
| 651 | + } |
|
| 652 | + |
|
| 653 | + } |
|
| 654 | + |
|
| 655 | + } |
|
| 656 | + |
|
| 657 | + /** |
|
| 658 | + * Update Meta Data in the database. |
|
| 659 | + * |
|
| 660 | + * @since 1.0.19 |
|
| 661 | + */ |
|
| 662 | + public function save_meta_data() { |
|
| 663 | + if ( ! $this->data_store || is_null( $this->meta_data ) ) { |
|
| 664 | + return; |
|
| 665 | + } |
|
| 666 | + foreach ( $this->meta_data as $array_key => $meta ) { |
|
| 667 | + if ( is_null( $meta->value ) ) { |
|
| 668 | + if ( ! empty( $meta->id ) ) { |
|
| 669 | + $this->data_store->delete_meta( $this, $meta ); |
|
| 670 | + unset( $this->meta_data[ $array_key ] ); |
|
| 671 | + } |
|
| 672 | + } elseif ( empty( $meta->id ) ) { |
|
| 673 | + $meta->id = $this->data_store->add_meta( $this, $meta ); |
|
| 674 | + $meta->apply_changes(); |
|
| 675 | + } else { |
|
| 676 | + if ( $meta->get_changes() ) { |
|
| 677 | + $this->data_store->update_meta( $this, $meta ); |
|
| 678 | + $meta->apply_changes(); |
|
| 679 | + } |
|
| 680 | + } |
|
| 681 | + } |
|
| 682 | + if ( ! empty( $this->cache_group ) ) { |
|
| 683 | + $cache_key = GetPaid_Cache_Helper::get_cache_prefix( $this->cache_group ) . GetPaid_Cache_Helper::get_cache_prefix( 'object_' . $this->get_id() ) . 'object_meta_' . $this->get_id(); |
|
| 684 | + wp_cache_delete( $cache_key, $this->cache_group ); |
|
| 685 | + } |
|
| 686 | + } |
|
| 687 | + |
|
| 688 | + /** |
|
| 689 | + * Set ID. |
|
| 690 | + * |
|
| 691 | + * @since 1.0.19 |
|
| 692 | + * @param int $id ID. |
|
| 693 | + */ |
|
| 694 | + public function set_id( $id ) { |
|
| 695 | + $this->id = absint( $id ); |
|
| 696 | + } |
|
| 697 | + |
|
| 698 | + /** |
|
| 699 | + * Sets item status. |
|
| 700 | + * |
|
| 701 | + * @since 1.0.19 |
|
| 702 | + * @param string $status New status. |
|
| 703 | + * @return array details of change. |
|
| 704 | + */ |
|
| 705 | + public function set_status( $status ) { |
|
| 706 | 706 | $old_status = $this->get_status(); |
| 707 | 707 | |
| 708 | - $this->set_prop( 'status', $status ); |
|
| 709 | - |
|
| 710 | - return array( |
|
| 711 | - 'from' => $old_status, |
|
| 712 | - 'to' => $status, |
|
| 713 | - ); |
|
| 714 | - } |
|
| 715 | - |
|
| 716 | - /** |
|
| 717 | - * Set all props to default values. |
|
| 718 | - * |
|
| 719 | - * @since 1.0.19 |
|
| 720 | - */ |
|
| 721 | - public function set_defaults() { |
|
| 722 | - $this->data = $this->default_data; |
|
| 723 | - $this->changes = array(); |
|
| 724 | - $this->set_object_read( false ); |
|
| 725 | - } |
|
| 726 | - |
|
| 727 | - /** |
|
| 728 | - * Set object read property. |
|
| 729 | - * |
|
| 730 | - * @since 1.0.19 |
|
| 731 | - * @param boolean $read Should read?. |
|
| 732 | - */ |
|
| 733 | - public function set_object_read( $read = true ) { |
|
| 734 | - $this->object_read = (bool) $read; |
|
| 735 | - } |
|
| 736 | - |
|
| 737 | - /** |
|
| 738 | - * Get object read property. |
|
| 739 | - * |
|
| 740 | - * @since 1.0.19 |
|
| 741 | - * @return boolean |
|
| 742 | - */ |
|
| 743 | - public function get_object_read() { |
|
| 744 | - return (bool) $this->object_read; |
|
| 745 | - } |
|
| 746 | - |
|
| 747 | - /** |
|
| 748 | - * Set a collection of props in one go, collect any errors, and return the result. |
|
| 749 | - * Only sets using public methods. |
|
| 750 | - * |
|
| 751 | - * @since 1.0.19 |
|
| 752 | - * |
|
| 753 | - * @param array $props Key value pairs to set. Key is the prop and should map to a setter function name. |
|
| 754 | - * @param string $context In what context to run this. |
|
| 755 | - * |
|
| 756 | - * @return bool|WP_Error |
|
| 757 | - */ |
|
| 758 | - public function set_props( $props, $context = 'set' ) { |
|
| 759 | - $errors = false; |
|
| 760 | - |
|
| 761 | - foreach ( $props as $prop => $value ) { |
|
| 762 | - try { |
|
| 763 | - /** |
|
| 764 | - * Checks if the prop being set is allowed, and the value is not null. |
|
| 765 | - */ |
|
| 766 | - if ( is_null( $value ) || in_array( $prop, array( 'prop', 'date_prop', 'meta_data' ), true ) ) { |
|
| 767 | - continue; |
|
| 768 | - } |
|
| 769 | - $setter = "set_$prop"; |
|
| 770 | - |
|
| 771 | - if ( is_callable( array( $this, $setter ) ) ) { |
|
| 772 | - $this->{$setter}( $value ); |
|
| 773 | - } |
|
| 774 | - } catch ( Exception $e ) { |
|
| 775 | - if ( ! $errors ) { |
|
| 776 | - $errors = new WP_Error(); |
|
| 777 | - } |
|
| 778 | - $errors->add( $e->getCode(), $e->getMessage() ); |
|
| 779 | - $this->last_error = $e->getMessage(); |
|
| 780 | - } |
|
| 781 | - } |
|
| 782 | - |
|
| 783 | - return $errors && count( $errors->get_error_codes() ) ? $errors : true; |
|
| 784 | - } |
|
| 785 | - |
|
| 786 | - /** |
|
| 787 | - * Sets a prop for a setter method. |
|
| 788 | - * |
|
| 789 | - * This stores changes in a special array so we can track what needs saving |
|
| 790 | - * the the DB later. |
|
| 791 | - * |
|
| 792 | - * @since 1.0.19 |
|
| 793 | - * @param string $prop Name of prop to set. |
|
| 794 | - * @param mixed $value Value of the prop. |
|
| 795 | - */ |
|
| 796 | - protected function set_prop( $prop, $value ) { |
|
| 797 | - if ( array_key_exists( $prop, $this->data ) ) { |
|
| 798 | - if ( true === $this->object_read ) { |
|
| 799 | - if ( $value !== $this->data[ $prop ] || array_key_exists( $prop, $this->changes ) ) { |
|
| 800 | - $this->changes[ $prop ] = $value; |
|
| 801 | - } |
|
| 802 | - } else { |
|
| 803 | - $this->data[ $prop ] = $value; |
|
| 804 | - } |
|
| 805 | - } |
|
| 806 | - } |
|
| 807 | - |
|
| 808 | - /** |
|
| 809 | - * Return data changes only. |
|
| 810 | - * |
|
| 811 | - * @since 1.0.19 |
|
| 812 | - * @return array |
|
| 813 | - */ |
|
| 814 | - public function get_changes() { |
|
| 815 | - return $this->changes; |
|
| 816 | - } |
|
| 817 | - |
|
| 818 | - /** |
|
| 819 | - * Merge changes with data and clear. |
|
| 820 | - * |
|
| 821 | - * @since 1.0.19 |
|
| 822 | - */ |
|
| 823 | - public function apply_changes() { |
|
| 824 | - $this->data = array_replace_recursive( $this->data, $this->changes ); |
|
| 825 | - $this->changes = array(); |
|
| 826 | - } |
|
| 827 | - |
|
| 828 | - /** |
|
| 829 | - * Prefix for action and filter hooks on data. |
|
| 830 | - * |
|
| 831 | - * @since 1.0.19 |
|
| 832 | - * @return string |
|
| 833 | - */ |
|
| 834 | - protected function get_hook_prefix() { |
|
| 835 | - return 'wpinv_get_' . $this->object_type . '_'; |
|
| 836 | - } |
|
| 837 | - |
|
| 838 | - /** |
|
| 839 | - * Gets a prop for a getter method. |
|
| 840 | - * |
|
| 841 | - * Gets the value from either current pending changes, or the data itself. |
|
| 842 | - * Context controls what happens to the value before it's returned. |
|
| 843 | - * |
|
| 844 | - * @since 1.0.19 |
|
| 845 | - * @param string $prop Name of prop to get. |
|
| 846 | - * @param string $context What the value is for. Valid values are view and edit. |
|
| 847 | - * @return mixed |
|
| 848 | - */ |
|
| 849 | - protected function get_prop( $prop, $context = 'view' ) { |
|
| 850 | - $value = null; |
|
| 851 | - |
|
| 852 | - if ( array_key_exists( $prop, $this->data ) ) { |
|
| 853 | - $value = array_key_exists( $prop, $this->changes ) ? $this->changes[ $prop ] : $this->data[ $prop ]; |
|
| 854 | - |
|
| 855 | - if ( 'view' === $context ) { |
|
| 856 | - $value = apply_filters( $this->get_hook_prefix() . $prop, $value, $this ); |
|
| 857 | - } |
|
| 858 | - } |
|
| 859 | - |
|
| 860 | - return $value; |
|
| 861 | - } |
|
| 862 | - |
|
| 863 | - /** |
|
| 864 | - * Sets a date prop whilst handling formatting and datetime objects. |
|
| 865 | - * |
|
| 866 | - * @since 1.0.19 |
|
| 867 | - * @param string $prop Name of prop to set. |
|
| 868 | - * @param string|integer $value Value of the prop. |
|
| 869 | - */ |
|
| 870 | - protected function set_date_prop( $prop, $value ) { |
|
| 871 | - |
|
| 872 | - if ( empty( $value ) ) { |
|
| 873 | - $this->set_prop( $prop, null ); |
|
| 874 | - return; |
|
| 875 | - } |
|
| 876 | - $this->set_prop( $prop, $value ); |
|
| 877 | - |
|
| 878 | - } |
|
| 879 | - |
|
| 880 | - /** |
|
| 881 | - * When invalid data is found, throw an exception unless reading from the DB. |
|
| 882 | - * |
|
| 883 | - * @since 1.0.19 |
|
| 884 | - * @param string $code Error code. |
|
| 885 | - * @param string $message Error message. |
|
| 886 | - */ |
|
| 887 | - protected function error( $code, $message ) { |
|
| 888 | - $this->last_error = $message; |
|
| 889 | - } |
|
| 890 | - |
|
| 891 | - /** |
|
| 892 | - * Checks if the object is saved in the database |
|
| 893 | - * |
|
| 894 | - * @since 1.0.19 |
|
| 895 | - * @return bool |
|
| 896 | - */ |
|
| 897 | - public function exists() { |
|
| 898 | - $id = $this->get_id(); |
|
| 899 | - return ! empty( $id ); |
|
| 900 | - } |
|
| 708 | + $this->set_prop( 'status', $status ); |
|
| 709 | + |
|
| 710 | + return array( |
|
| 711 | + 'from' => $old_status, |
|
| 712 | + 'to' => $status, |
|
| 713 | + ); |
|
| 714 | + } |
|
| 715 | + |
|
| 716 | + /** |
|
| 717 | + * Set all props to default values. |
|
| 718 | + * |
|
| 719 | + * @since 1.0.19 |
|
| 720 | + */ |
|
| 721 | + public function set_defaults() { |
|
| 722 | + $this->data = $this->default_data; |
|
| 723 | + $this->changes = array(); |
|
| 724 | + $this->set_object_read( false ); |
|
| 725 | + } |
|
| 726 | + |
|
| 727 | + /** |
|
| 728 | + * Set object read property. |
|
| 729 | + * |
|
| 730 | + * @since 1.0.19 |
|
| 731 | + * @param boolean $read Should read?. |
|
| 732 | + */ |
|
| 733 | + public function set_object_read( $read = true ) { |
|
| 734 | + $this->object_read = (bool) $read; |
|
| 735 | + } |
|
| 736 | + |
|
| 737 | + /** |
|
| 738 | + * Get object read property. |
|
| 739 | + * |
|
| 740 | + * @since 1.0.19 |
|
| 741 | + * @return boolean |
|
| 742 | + */ |
|
| 743 | + public function get_object_read() { |
|
| 744 | + return (bool) $this->object_read; |
|
| 745 | + } |
|
| 746 | + |
|
| 747 | + /** |
|
| 748 | + * Set a collection of props in one go, collect any errors, and return the result. |
|
| 749 | + * Only sets using public methods. |
|
| 750 | + * |
|
| 751 | + * @since 1.0.19 |
|
| 752 | + * |
|
| 753 | + * @param array $props Key value pairs to set. Key is the prop and should map to a setter function name. |
|
| 754 | + * @param string $context In what context to run this. |
|
| 755 | + * |
|
| 756 | + * @return bool|WP_Error |
|
| 757 | + */ |
|
| 758 | + public function set_props( $props, $context = 'set' ) { |
|
| 759 | + $errors = false; |
|
| 760 | + |
|
| 761 | + foreach ( $props as $prop => $value ) { |
|
| 762 | + try { |
|
| 763 | + /** |
|
| 764 | + * Checks if the prop being set is allowed, and the value is not null. |
|
| 765 | + */ |
|
| 766 | + if ( is_null( $value ) || in_array( $prop, array( 'prop', 'date_prop', 'meta_data' ), true ) ) { |
|
| 767 | + continue; |
|
| 768 | + } |
|
| 769 | + $setter = "set_$prop"; |
|
| 770 | + |
|
| 771 | + if ( is_callable( array( $this, $setter ) ) ) { |
|
| 772 | + $this->{$setter}( $value ); |
|
| 773 | + } |
|
| 774 | + } catch ( Exception $e ) { |
|
| 775 | + if ( ! $errors ) { |
|
| 776 | + $errors = new WP_Error(); |
|
| 777 | + } |
|
| 778 | + $errors->add( $e->getCode(), $e->getMessage() ); |
|
| 779 | + $this->last_error = $e->getMessage(); |
|
| 780 | + } |
|
| 781 | + } |
|
| 782 | + |
|
| 783 | + return $errors && count( $errors->get_error_codes() ) ? $errors : true; |
|
| 784 | + } |
|
| 785 | + |
|
| 786 | + /** |
|
| 787 | + * Sets a prop for a setter method. |
|
| 788 | + * |
|
| 789 | + * This stores changes in a special array so we can track what needs saving |
|
| 790 | + * the the DB later. |
|
| 791 | + * |
|
| 792 | + * @since 1.0.19 |
|
| 793 | + * @param string $prop Name of prop to set. |
|
| 794 | + * @param mixed $value Value of the prop. |
|
| 795 | + */ |
|
| 796 | + protected function set_prop( $prop, $value ) { |
|
| 797 | + if ( array_key_exists( $prop, $this->data ) ) { |
|
| 798 | + if ( true === $this->object_read ) { |
|
| 799 | + if ( $value !== $this->data[ $prop ] || array_key_exists( $prop, $this->changes ) ) { |
|
| 800 | + $this->changes[ $prop ] = $value; |
|
| 801 | + } |
|
| 802 | + } else { |
|
| 803 | + $this->data[ $prop ] = $value; |
|
| 804 | + } |
|
| 805 | + } |
|
| 806 | + } |
|
| 807 | + |
|
| 808 | + /** |
|
| 809 | + * Return data changes only. |
|
| 810 | + * |
|
| 811 | + * @since 1.0.19 |
|
| 812 | + * @return array |
|
| 813 | + */ |
|
| 814 | + public function get_changes() { |
|
| 815 | + return $this->changes; |
|
| 816 | + } |
|
| 817 | + |
|
| 818 | + /** |
|
| 819 | + * Merge changes with data and clear. |
|
| 820 | + * |
|
| 821 | + * @since 1.0.19 |
|
| 822 | + */ |
|
| 823 | + public function apply_changes() { |
|
| 824 | + $this->data = array_replace_recursive( $this->data, $this->changes ); |
|
| 825 | + $this->changes = array(); |
|
| 826 | + } |
|
| 827 | + |
|
| 828 | + /** |
|
| 829 | + * Prefix for action and filter hooks on data. |
|
| 830 | + * |
|
| 831 | + * @since 1.0.19 |
|
| 832 | + * @return string |
|
| 833 | + */ |
|
| 834 | + protected function get_hook_prefix() { |
|
| 835 | + return 'wpinv_get_' . $this->object_type . '_'; |
|
| 836 | + } |
|
| 837 | + |
|
| 838 | + /** |
|
| 839 | + * Gets a prop for a getter method. |
|
| 840 | + * |
|
| 841 | + * Gets the value from either current pending changes, or the data itself. |
|
| 842 | + * Context controls what happens to the value before it's returned. |
|
| 843 | + * |
|
| 844 | + * @since 1.0.19 |
|
| 845 | + * @param string $prop Name of prop to get. |
|
| 846 | + * @param string $context What the value is for. Valid values are view and edit. |
|
| 847 | + * @return mixed |
|
| 848 | + */ |
|
| 849 | + protected function get_prop( $prop, $context = 'view' ) { |
|
| 850 | + $value = null; |
|
| 851 | + |
|
| 852 | + if ( array_key_exists( $prop, $this->data ) ) { |
|
| 853 | + $value = array_key_exists( $prop, $this->changes ) ? $this->changes[ $prop ] : $this->data[ $prop ]; |
|
| 854 | + |
|
| 855 | + if ( 'view' === $context ) { |
|
| 856 | + $value = apply_filters( $this->get_hook_prefix() . $prop, $value, $this ); |
|
| 857 | + } |
|
| 858 | + } |
|
| 859 | + |
|
| 860 | + return $value; |
|
| 861 | + } |
|
| 862 | + |
|
| 863 | + /** |
|
| 864 | + * Sets a date prop whilst handling formatting and datetime objects. |
|
| 865 | + * |
|
| 866 | + * @since 1.0.19 |
|
| 867 | + * @param string $prop Name of prop to set. |
|
| 868 | + * @param string|integer $value Value of the prop. |
|
| 869 | + */ |
|
| 870 | + protected function set_date_prop( $prop, $value ) { |
|
| 871 | + |
|
| 872 | + if ( empty( $value ) ) { |
|
| 873 | + $this->set_prop( $prop, null ); |
|
| 874 | + return; |
|
| 875 | + } |
|
| 876 | + $this->set_prop( $prop, $value ); |
|
| 877 | + |
|
| 878 | + } |
|
| 879 | + |
|
| 880 | + /** |
|
| 881 | + * When invalid data is found, throw an exception unless reading from the DB. |
|
| 882 | + * |
|
| 883 | + * @since 1.0.19 |
|
| 884 | + * @param string $code Error code. |
|
| 885 | + * @param string $message Error message. |
|
| 886 | + */ |
|
| 887 | + protected function error( $code, $message ) { |
|
| 888 | + $this->last_error = $message; |
|
| 889 | + } |
|
| 890 | + |
|
| 891 | + /** |
|
| 892 | + * Checks if the object is saved in the database |
|
| 893 | + * |
|
| 894 | + * @since 1.0.19 |
|
| 895 | + * @return bool |
|
| 896 | + */ |
|
| 897 | + public function exists() { |
|
| 898 | + $id = $this->get_id(); |
|
| 899 | + return ! empty( $id ); |
|
| 900 | + } |
|
| 901 | 901 | |
| 902 | 902 | } |
@@ -14,30 +14,30 @@ discard block |
||
| 14 | 14 | class WPInv_Invoice extends GetPaid_Data { |
| 15 | 15 | |
| 16 | 16 | /** |
| 17 | - * Which data store to load. |
|
| 18 | - * |
|
| 19 | - * @var string |
|
| 20 | - */ |
|
| 17 | + * Which data store to load. |
|
| 18 | + * |
|
| 19 | + * @var string |
|
| 20 | + */ |
|
| 21 | 21 | protected $data_store_name = 'invoice'; |
| 22 | 22 | |
| 23 | 23 | /** |
| 24 | - * This is the name of this object type. |
|
| 25 | - * |
|
| 26 | - * @var string |
|
| 27 | - */ |
|
| 24 | + * This is the name of this object type. |
|
| 25 | + * |
|
| 26 | + * @var string |
|
| 27 | + */ |
|
| 28 | 28 | protected $object_type = 'invoice'; |
| 29 | 29 | |
| 30 | 30 | /** |
| 31 | - * Item Data array. This is the core item data exposed in APIs. |
|
| 32 | - * |
|
| 33 | - * @since 1.0.19 |
|
| 34 | - * @var array |
|
| 35 | - */ |
|
| 36 | - protected $data = array( |
|
| 37 | - 'parent_id' => 0, |
|
| 38 | - 'status' => 'wpi-pending', |
|
| 39 | - 'version' => '', |
|
| 40 | - 'date_created' => null, |
|
| 31 | + * Item Data array. This is the core item data exposed in APIs. |
|
| 32 | + * |
|
| 33 | + * @since 1.0.19 |
|
| 34 | + * @var array |
|
| 35 | + */ |
|
| 36 | + protected $data = array( |
|
| 37 | + 'parent_id' => 0, |
|
| 38 | + 'status' => 'wpi-pending', |
|
| 39 | + 'version' => '', |
|
| 40 | + 'date_created' => null, |
|
| 41 | 41 | 'date_modified' => null, |
| 42 | 42 | 'due_date' => null, |
| 43 | 43 | 'completed_date' => null, |
@@ -79,22 +79,22 @@ discard block |
||
| 79 | 79 | 'transaction_id' => '', |
| 80 | 80 | 'currency' => '', |
| 81 | 81 | 'disable_taxes' => false, |
| 82 | - 'subscription_id' => null, |
|
| 83 | - 'remote_subscription_id' => null, |
|
| 84 | - 'is_viewed' => false, |
|
| 85 | - 'email_cc' => '', |
|
| 86 | - 'template' => 'quantity', // hours, amount only |
|
| 87 | - 'created_via' => null, |
|
| 82 | + 'subscription_id' => null, |
|
| 83 | + 'remote_subscription_id' => null, |
|
| 84 | + 'is_viewed' => false, |
|
| 85 | + 'email_cc' => '', |
|
| 86 | + 'template' => 'quantity', // hours, amount only |
|
| 87 | + 'created_via' => null, |
|
| 88 | 88 | ); |
| 89 | 89 | |
| 90 | 90 | /** |
| 91 | - * Stores meta in cache for future reads. |
|
| 92 | - * |
|
| 93 | - * A group must be set to to enable caching. |
|
| 94 | - * |
|
| 95 | - * @var string |
|
| 96 | - */ |
|
| 97 | - protected $cache_group = 'getpaid_invoices'; |
|
| 91 | + * Stores meta in cache for future reads. |
|
| 92 | + * |
|
| 93 | + * A group must be set to to enable caching. |
|
| 94 | + * |
|
| 95 | + * @var string |
|
| 96 | + */ |
|
| 97 | + protected $cache_group = 'getpaid_invoices'; |
|
| 98 | 98 | |
| 99 | 99 | /** |
| 100 | 100 | * Stores a reference to the original WP_Post object |
@@ -108,104 +108,104 @@ discard block |
||
| 108 | 108 | * |
| 109 | 109 | * @var int |
| 110 | 110 | */ |
| 111 | - protected $recurring_item = null; |
|
| 111 | + protected $recurring_item = null; |
|
| 112 | 112 | |
| 113 | - /** |
|
| 113 | + /** |
|
| 114 | 114 | * Stores an array of item totals. |
| 115 | - * |
|
| 116 | - * e.g $totals['discount'] = array( |
|
| 117 | - * 'initial' => 10, |
|
| 118 | - * 'recurring' => 10, |
|
| 119 | - * ) |
|
| 115 | + * |
|
| 116 | + * e.g $totals['discount'] = array( |
|
| 117 | + * 'initial' => 10, |
|
| 118 | + * 'recurring' => 10, |
|
| 119 | + * ) |
|
| 120 | 120 | * |
| 121 | 121 | * @var array |
| 122 | 122 | */ |
| 123 | - protected $totals = array(); |
|
| 123 | + protected $totals = array(); |
|
| 124 | 124 | |
| 125 | - /** |
|
| 126 | - * Stores the status transition information. |
|
| 127 | - * |
|
| 128 | - * @since 1.0.19 |
|
| 129 | - * @var bool|array |
|
| 130 | - */ |
|
| 131 | - protected $status_transition = false; |
|
| 125 | + /** |
|
| 126 | + * Stores the status transition information. |
|
| 127 | + * |
|
| 128 | + * @since 1.0.19 |
|
| 129 | + * @var bool|array |
|
| 130 | + */ |
|
| 131 | + protected $status_transition = false; |
|
| 132 | 132 | |
| 133 | 133 | /** |
| 134 | - * Get the invoice if ID is passed, otherwise the invoice is new and empty. |
|
| 135 | - * |
|
| 136 | - * @param int|string|object|WPInv_Invoice|WPInv_Legacy_Invoice|WP_Post $invoice Invoice id, key, transaction id, number or object to read. |
|
| 137 | - */ |
|
| 134 | + * Get the invoice if ID is passed, otherwise the invoice is new and empty. |
|
| 135 | + * |
|
| 136 | + * @param int|string|object|WPInv_Invoice|WPInv_Legacy_Invoice|WP_Post $invoice Invoice id, key, transaction id, number or object to read. |
|
| 137 | + */ |
|
| 138 | 138 | public function __construct( $invoice = 0 ) { |
| 139 | 139 | |
| 140 | 140 | parent::__construct( $invoice ); |
| 141 | 141 | |
| 142 | - if ( ! empty( $invoice ) && is_numeric( $invoice ) && getpaid_is_invoice_post_type( get_post_type( (int) $invoice ) ) ) { |
|
| 143 | - $this->set_id( (int) $invoice ); |
|
| 144 | - } elseif ( $invoice instanceof self ) { |
|
| 145 | - $this->set_id( $invoice->get_id() ); |
|
| 146 | - } elseif ( ! empty( $invoice->ID ) ) { |
|
| 147 | - $this->set_id( $invoice->ID ); |
|
| 148 | - } elseif ( is_array( $invoice ) ) { |
|
| 149 | - $this->set_props( $invoice ); |
|
| 150 | - |
|
| 151 | - if ( isset( $invoice['ID'] ) ) { |
|
| 152 | - $this->set_id( $invoice['ID'] ); |
|
| 153 | - } |
|
| 154 | - |
|
| 155 | - } elseif ( is_string( $invoice ) && $invoice_id = self::get_invoice_id_by_field( $invoice, 'key' ) ) { |
|
| 156 | - $this->set_id( $invoice_id ); |
|
| 157 | - } elseif ( is_string( $invoice ) && $invoice_id = self::get_invoice_id_by_field( $invoice, 'number' ) ) { |
|
| 158 | - $this->set_id( $invoice_id ); |
|
| 159 | - } elseif ( is_string( $invoice ) && $invoice_id = self::get_invoice_id_by_field( $invoice, 'transaction_id' ) ) { |
|
| 160 | - $this->set_id( $invoice_id ); |
|
| 161 | - }else { |
|
| 162 | - $this->set_object_read( true ); |
|
| 163 | - } |
|
| 142 | + if ( ! empty( $invoice ) && is_numeric( $invoice ) && getpaid_is_invoice_post_type( get_post_type( (int) $invoice ) ) ) { |
|
| 143 | + $this->set_id( (int) $invoice ); |
|
| 144 | + } elseif ( $invoice instanceof self ) { |
|
| 145 | + $this->set_id( $invoice->get_id() ); |
|
| 146 | + } elseif ( ! empty( $invoice->ID ) ) { |
|
| 147 | + $this->set_id( $invoice->ID ); |
|
| 148 | + } elseif ( is_array( $invoice ) ) { |
|
| 149 | + $this->set_props( $invoice ); |
|
| 150 | + |
|
| 151 | + if ( isset( $invoice['ID'] ) ) { |
|
| 152 | + $this->set_id( $invoice['ID'] ); |
|
| 153 | + } |
|
| 154 | + |
|
| 155 | + } elseif ( is_string( $invoice ) && $invoice_id = self::get_invoice_id_by_field( $invoice, 'key' ) ) { |
|
| 156 | + $this->set_id( $invoice_id ); |
|
| 157 | + } elseif ( is_string( $invoice ) && $invoice_id = self::get_invoice_id_by_field( $invoice, 'number' ) ) { |
|
| 158 | + $this->set_id( $invoice_id ); |
|
| 159 | + } elseif ( is_string( $invoice ) && $invoice_id = self::get_invoice_id_by_field( $invoice, 'transaction_id' ) ) { |
|
| 160 | + $this->set_id( $invoice_id ); |
|
| 161 | + }else { |
|
| 162 | + $this->set_object_read( true ); |
|
| 163 | + } |
|
| 164 | 164 | |
| 165 | 165 | // Load the datastore. |
| 166 | - $this->data_store = GetPaid_Data_Store::load( $this->data_store_name ); |
|
| 166 | + $this->data_store = GetPaid_Data_Store::load( $this->data_store_name ); |
|
| 167 | 167 | |
| 168 | - if ( $this->get_id() > 0 ) { |
|
| 168 | + if ( $this->get_id() > 0 ) { |
|
| 169 | 169 | $this->post = get_post( $this->get_id() ); |
| 170 | 170 | $this->ID = $this->get_id(); |
| 171 | - $this->data_store->read( $this ); |
|
| 171 | + $this->data_store->read( $this ); |
|
| 172 | 172 | } |
| 173 | 173 | |
| 174 | 174 | } |
| 175 | 175 | |
| 176 | 176 | /** |
| 177 | - * Given an invoice key/number, it returns its id. |
|
| 178 | - * |
|
| 179 | - * |
|
| 180 | - * @static |
|
| 181 | - * @param string $value The invoice key or number |
|
| 182 | - * @param string $field Either key, transaction_id or number. |
|
| 183 | - * @since 1.0.15 |
|
| 184 | - * @return int |
|
| 185 | - */ |
|
| 186 | - public static function get_invoice_id_by_field( $value, $field = 'key' ) { |
|
| 177 | + * Given an invoice key/number, it returns its id. |
|
| 178 | + * |
|
| 179 | + * |
|
| 180 | + * @static |
|
| 181 | + * @param string $value The invoice key or number |
|
| 182 | + * @param string $field Either key, transaction_id or number. |
|
| 183 | + * @since 1.0.15 |
|
| 184 | + * @return int |
|
| 185 | + */ |
|
| 186 | + public static function get_invoice_id_by_field( $value, $field = 'key' ) { |
|
| 187 | 187 | global $wpdb; |
| 188 | 188 | |
| 189 | - // Trim the value. |
|
| 190 | - $value = trim( $value ); |
|
| 189 | + // Trim the value. |
|
| 190 | + $value = trim( $value ); |
|
| 191 | 191 | |
| 192 | - if ( empty( $value ) ) { |
|
| 193 | - return 0; |
|
| 194 | - } |
|
| 192 | + if ( empty( $value ) ) { |
|
| 193 | + return 0; |
|
| 194 | + } |
|
| 195 | 195 | |
| 196 | 196 | // Valid fields. |
| 197 | 197 | $fields = array( 'key', 'number', 'transaction_id' ); |
| 198 | 198 | |
| 199 | - // Ensure a field has been passed. |
|
| 200 | - if ( empty( $field ) || ! in_array( $field, $fields ) ) { |
|
| 201 | - return 0; |
|
| 202 | - } |
|
| 199 | + // Ensure a field has been passed. |
|
| 200 | + if ( empty( $field ) || ! in_array( $field, $fields ) ) { |
|
| 201 | + return 0; |
|
| 202 | + } |
|
| 203 | 203 | |
| 204 | - // Maybe retrieve from the cache. |
|
| 205 | - $invoice_id = wp_cache_get( $value, "getpaid_invoice_{$field}s_to_invoice_ids" ); |
|
| 206 | - if ( false !== $invoice_id ) { |
|
| 207 | - return $invoice_id; |
|
| 208 | - } |
|
| 204 | + // Maybe retrieve from the cache. |
|
| 205 | + $invoice_id = wp_cache_get( $value, "getpaid_invoice_{$field}s_to_invoice_ids" ); |
|
| 206 | + if ( false !== $invoice_id ) { |
|
| 207 | + return $invoice_id; |
|
| 208 | + } |
|
| 209 | 209 | |
| 210 | 210 | // Fetch from the db. |
| 211 | 211 | $table = $wpdb->prefix . 'getpaid_invoices'; |
@@ -213,10 +213,10 @@ discard block |
||
| 213 | 213 | $wpdb->prepare( "SELECT `post_id` FROM $table WHERE `$field`=%s LIMIT 1", $value ) |
| 214 | 214 | ); |
| 215 | 215 | |
| 216 | - // Update the cache with our data |
|
| 217 | - wp_cache_set( $value, $invoice_id, "getpaid_invoice_{$field}s_to_invoice_ids" ); |
|
| 216 | + // Update the cache with our data |
|
| 217 | + wp_cache_set( $value, $invoice_id, "getpaid_invoice_{$field}s_to_invoice_ids" ); |
|
| 218 | 218 | |
| 219 | - return $invoice_id; |
|
| 219 | + return $invoice_id; |
|
| 220 | 220 | } |
| 221 | 221 | |
| 222 | 222 | /** |
@@ -242,72 +242,72 @@ discard block |
||
| 242 | 242 | */ |
| 243 | 243 | |
| 244 | 244 | /** |
| 245 | - * Get parent invoice ID. |
|
| 246 | - * |
|
| 247 | - * @since 1.0.19 |
|
| 248 | - * @param string $context View or edit context. |
|
| 249 | - * @return int |
|
| 250 | - */ |
|
| 251 | - public function get_parent_id( $context = 'view' ) { |
|
| 252 | - return (int) $this->get_prop( 'parent_id', $context ); |
|
| 245 | + * Get parent invoice ID. |
|
| 246 | + * |
|
| 247 | + * @since 1.0.19 |
|
| 248 | + * @param string $context View or edit context. |
|
| 249 | + * @return int |
|
| 250 | + */ |
|
| 251 | + public function get_parent_id( $context = 'view' ) { |
|
| 252 | + return (int) $this->get_prop( 'parent_id', $context ); |
|
| 253 | 253 | } |
| 254 | 254 | |
| 255 | 255 | /** |
| 256 | - * Get parent invoice. |
|
| 257 | - * |
|
| 258 | - * @since 1.0.19 |
|
| 259 | - * @return WPInv_Invoice |
|
| 260 | - */ |
|
| 256 | + * Get parent invoice. |
|
| 257 | + * |
|
| 258 | + * @since 1.0.19 |
|
| 259 | + * @return WPInv_Invoice |
|
| 260 | + */ |
|
| 261 | 261 | public function get_parent_payment() { |
| 262 | 262 | return new WPInv_Invoice( $this->get_parent_id() ); |
| 263 | 263 | } |
| 264 | 264 | |
| 265 | 265 | /** |
| 266 | - * Alias for self::get_parent_payment(). |
|
| 267 | - * |
|
| 268 | - * @since 1.0.19 |
|
| 269 | - * @return WPInv_Invoice |
|
| 270 | - */ |
|
| 266 | + * Alias for self::get_parent_payment(). |
|
| 267 | + * |
|
| 268 | + * @since 1.0.19 |
|
| 269 | + * @return WPInv_Invoice |
|
| 270 | + */ |
|
| 271 | 271 | public function get_parent() { |
| 272 | 272 | return $this->get_parent_payment(); |
| 273 | 273 | } |
| 274 | 274 | |
| 275 | 275 | /** |
| 276 | - * Get invoice status. |
|
| 277 | - * |
|
| 278 | - * @since 1.0.19 |
|
| 279 | - * @param string $context View or edit context. |
|
| 280 | - * @return string |
|
| 281 | - */ |
|
| 282 | - public function get_status( $context = 'view' ) { |
|
| 283 | - return $this->get_prop( 'status', $context ); |
|
| 284 | - } |
|
| 276 | + * Get invoice status. |
|
| 277 | + * |
|
| 278 | + * @since 1.0.19 |
|
| 279 | + * @param string $context View or edit context. |
|
| 280 | + * @return string |
|
| 281 | + */ |
|
| 282 | + public function get_status( $context = 'view' ) { |
|
| 283 | + return $this->get_prop( 'status', $context ); |
|
| 284 | + } |
|
| 285 | 285 | |
| 286 | - /** |
|
| 287 | - * Retrieves an array of possible invoice statuses. |
|
| 288 | - * |
|
| 289 | - * @since 1.0.19 |
|
| 290 | - * @return array |
|
| 291 | - */ |
|
| 292 | - public function get_all_statuses() { |
|
| 293 | - return wpinv_get_invoice_statuses( true, true, $this ); |
|
| 294 | - } |
|
| 295 | - |
|
| 296 | - /** |
|
| 297 | - * Get invoice status nice name. |
|
| 298 | - * |
|
| 299 | - * @since 1.0.19 |
|
| 300 | - * @return string |
|
| 301 | - */ |
|
| 286 | + /** |
|
| 287 | + * Retrieves an array of possible invoice statuses. |
|
| 288 | + * |
|
| 289 | + * @since 1.0.19 |
|
| 290 | + * @return array |
|
| 291 | + */ |
|
| 292 | + public function get_all_statuses() { |
|
| 293 | + return wpinv_get_invoice_statuses( true, true, $this ); |
|
| 294 | + } |
|
| 295 | + |
|
| 296 | + /** |
|
| 297 | + * Get invoice status nice name. |
|
| 298 | + * |
|
| 299 | + * @since 1.0.19 |
|
| 300 | + * @return string |
|
| 301 | + */ |
|
| 302 | 302 | public function get_status_nicename() { |
| 303 | - $statuses = $this->get_all_statuses(); |
|
| 303 | + $statuses = $this->get_all_statuses(); |
|
| 304 | 304 | |
| 305 | 305 | $status = isset( $statuses[ $this->get_status() ] ) ? $statuses[ $this->get_status() ] : $this->get_status(); |
| 306 | 306 | |
| 307 | 307 | return apply_filters( 'wpinv_get_invoice_status_nicename', $status, $this ); |
| 308 | 308 | } |
| 309 | 309 | |
| 310 | - /** |
|
| 310 | + /** |
|
| 311 | 311 | * Retrieves the invoice status label html |
| 312 | 312 | * |
| 313 | 313 | * @since 1.0.0 |
@@ -315,262 +315,262 @@ discard block |
||
| 315 | 315 | */ |
| 316 | 316 | public function get_status_label_html() { |
| 317 | 317 | |
| 318 | - $status_label = sanitize_text_field( $this->get_status_nicename() ); |
|
| 319 | - $status = sanitize_html_class( $this->get_status() ); |
|
| 318 | + $status_label = sanitize_text_field( $this->get_status_nicename() ); |
|
| 319 | + $status = sanitize_html_class( $this->get_status() ); |
|
| 320 | 320 | |
| 321 | - return "<span class='bsui'><span class='d-inline-block py-2 px-3 rounded getpaid-invoice-status-$status'>$status_label</span></span>"; |
|
| 322 | - } |
|
| 321 | + return "<span class='bsui'><span class='d-inline-block py-2 px-3 rounded getpaid-invoice-status-$status'>$status_label</span></span>"; |
|
| 322 | + } |
|
| 323 | 323 | |
| 324 | 324 | /** |
| 325 | - * Get plugin version when the invoice was created. |
|
| 326 | - * |
|
| 327 | - * @since 1.0.19 |
|
| 328 | - * @param string $context View or edit context. |
|
| 329 | - * @return string |
|
| 330 | - */ |
|
| 331 | - public function get_version( $context = 'view' ) { |
|
| 332 | - return $this->get_prop( 'version', $context ); |
|
| 333 | - } |
|
| 325 | + * Get plugin version when the invoice was created. |
|
| 326 | + * |
|
| 327 | + * @since 1.0.19 |
|
| 328 | + * @param string $context View or edit context. |
|
| 329 | + * @return string |
|
| 330 | + */ |
|
| 331 | + public function get_version( $context = 'view' ) { |
|
| 332 | + return $this->get_prop( 'version', $context ); |
|
| 333 | + } |
|
| 334 | 334 | |
| 335 | - /** |
|
| 336 | - * @deprecated |
|
| 337 | - */ |
|
| 338 | - public function get_invoice_date( $format = true ) { |
|
| 339 | - $date = getpaid_format_date( $this->get_date_completed() ); |
|
| 340 | - $date = empty( $date ) ? $this->get_date_created() : $this->get_date_completed(); |
|
| 341 | - $formatted = getpaid_format_date( $date ); |
|
| 335 | + /** |
|
| 336 | + * @deprecated |
|
| 337 | + */ |
|
| 338 | + public function get_invoice_date( $format = true ) { |
|
| 339 | + $date = getpaid_format_date( $this->get_date_completed() ); |
|
| 340 | + $date = empty( $date ) ? $this->get_date_created() : $this->get_date_completed(); |
|
| 341 | + $formatted = getpaid_format_date( $date ); |
|
| 342 | 342 | |
| 343 | - if ( $format ) { |
|
| 344 | - return $formatted; |
|
| 345 | - } |
|
| 343 | + if ( $format ) { |
|
| 344 | + return $formatted; |
|
| 345 | + } |
|
| 346 | 346 | |
| 347 | - return empty( $formatted ) ? '' : $date; |
|
| 347 | + return empty( $formatted ) ? '' : $date; |
|
| 348 | 348 | |
| 349 | 349 | } |
| 350 | 350 | |
| 351 | 351 | /** |
| 352 | - * Get date when the invoice was created. |
|
| 353 | - * |
|
| 354 | - * @since 1.0.19 |
|
| 355 | - * @param string $context View or edit context. |
|
| 356 | - * @return string |
|
| 357 | - */ |
|
| 358 | - public function get_date_created( $context = 'view' ) { |
|
| 359 | - return $this->get_prop( 'date_created', $context ); |
|
| 360 | - } |
|
| 352 | + * Get date when the invoice was created. |
|
| 353 | + * |
|
| 354 | + * @since 1.0.19 |
|
| 355 | + * @param string $context View or edit context. |
|
| 356 | + * @return string |
|
| 357 | + */ |
|
| 358 | + public function get_date_created( $context = 'view' ) { |
|
| 359 | + return $this->get_prop( 'date_created', $context ); |
|
| 360 | + } |
|
| 361 | 361 | |
| 362 | - /** |
|
| 363 | - * Alias for self::get_date_created(). |
|
| 364 | - * |
|
| 365 | - * @since 1.0.19 |
|
| 366 | - * @param string $context View or edit context. |
|
| 367 | - * @return string |
|
| 368 | - */ |
|
| 369 | - public function get_created_date( $context = 'view' ) { |
|
| 370 | - return $this->get_date_created( $context ); |
|
| 371 | - } |
|
| 372 | - |
|
| 373 | - /** |
|
| 374 | - * Get GMT date when the invoice was created. |
|
| 375 | - * |
|
| 376 | - * @since 1.0.19 |
|
| 377 | - * @param string $context View or edit context. |
|
| 378 | - * @return string |
|
| 379 | - */ |
|
| 380 | - public function get_date_created_gmt( $context = 'view' ) { |
|
| 362 | + /** |
|
| 363 | + * Alias for self::get_date_created(). |
|
| 364 | + * |
|
| 365 | + * @since 1.0.19 |
|
| 366 | + * @param string $context View or edit context. |
|
| 367 | + * @return string |
|
| 368 | + */ |
|
| 369 | + public function get_created_date( $context = 'view' ) { |
|
| 370 | + return $this->get_date_created( $context ); |
|
| 371 | + } |
|
| 372 | + |
|
| 373 | + /** |
|
| 374 | + * Get GMT date when the invoice was created. |
|
| 375 | + * |
|
| 376 | + * @since 1.0.19 |
|
| 377 | + * @param string $context View or edit context. |
|
| 378 | + * @return string |
|
| 379 | + */ |
|
| 380 | + public function get_date_created_gmt( $context = 'view' ) { |
|
| 381 | 381 | $date = $this->get_date_created( $context ); |
| 382 | 382 | |
| 383 | 383 | if ( $date ) { |
| 384 | 384 | $date = get_gmt_from_date( $date ); |
| 385 | 385 | } |
| 386 | - return $date; |
|
| 386 | + return $date; |
|
| 387 | 387 | } |
| 388 | 388 | |
| 389 | 389 | /** |
| 390 | - * Get date when the invoice was last modified. |
|
| 391 | - * |
|
| 392 | - * @since 1.0.19 |
|
| 393 | - * @param string $context View or edit context. |
|
| 394 | - * @return string |
|
| 395 | - */ |
|
| 396 | - public function get_date_modified( $context = 'view' ) { |
|
| 397 | - return $this->get_prop( 'date_modified', $context ); |
|
| 398 | - } |
|
| 390 | + * Get date when the invoice was last modified. |
|
| 391 | + * |
|
| 392 | + * @since 1.0.19 |
|
| 393 | + * @param string $context View or edit context. |
|
| 394 | + * @return string |
|
| 395 | + */ |
|
| 396 | + public function get_date_modified( $context = 'view' ) { |
|
| 397 | + return $this->get_prop( 'date_modified', $context ); |
|
| 398 | + } |
|
| 399 | 399 | |
| 400 | - /** |
|
| 401 | - * Alias for self::get_date_modified(). |
|
| 402 | - * |
|
| 403 | - * @since 1.0.19 |
|
| 404 | - * @param string $context View or edit context. |
|
| 405 | - * @return string |
|
| 406 | - */ |
|
| 407 | - public function get_modified_date( $context = 'view' ) { |
|
| 408 | - return $this->get_date_modified( $context ); |
|
| 400 | + /** |
|
| 401 | + * Alias for self::get_date_modified(). |
|
| 402 | + * |
|
| 403 | + * @since 1.0.19 |
|
| 404 | + * @param string $context View or edit context. |
|
| 405 | + * @return string |
|
| 406 | + */ |
|
| 407 | + public function get_modified_date( $context = 'view' ) { |
|
| 408 | + return $this->get_date_modified( $context ); |
|
| 409 | 409 | } |
| 410 | 410 | |
| 411 | 411 | /** |
| 412 | - * Get GMT date when the invoice was last modified. |
|
| 413 | - * |
|
| 414 | - * @since 1.0.19 |
|
| 415 | - * @param string $context View or edit context. |
|
| 416 | - * @return string |
|
| 417 | - */ |
|
| 418 | - public function get_date_modified_gmt( $context = 'view' ) { |
|
| 412 | + * Get GMT date when the invoice was last modified. |
|
| 413 | + * |
|
| 414 | + * @since 1.0.19 |
|
| 415 | + * @param string $context View or edit context. |
|
| 416 | + * @return string |
|
| 417 | + */ |
|
| 418 | + public function get_date_modified_gmt( $context = 'view' ) { |
|
| 419 | 419 | $date = $this->get_date_modified( $context ); |
| 420 | 420 | |
| 421 | 421 | if ( $date ) { |
| 422 | 422 | $date = get_gmt_from_date( $date ); |
| 423 | 423 | } |
| 424 | - return $date; |
|
| 424 | + return $date; |
|
| 425 | 425 | } |
| 426 | 426 | |
| 427 | 427 | /** |
| 428 | - * Get the invoice due date. |
|
| 429 | - * |
|
| 430 | - * @since 1.0.19 |
|
| 431 | - * @param string $context View or edit context. |
|
| 432 | - * @return string |
|
| 433 | - */ |
|
| 434 | - public function get_due_date( $context = 'view' ) { |
|
| 435 | - return $this->get_prop( 'due_date', $context ); |
|
| 428 | + * Get the invoice due date. |
|
| 429 | + * |
|
| 430 | + * @since 1.0.19 |
|
| 431 | + * @param string $context View or edit context. |
|
| 432 | + * @return string |
|
| 433 | + */ |
|
| 434 | + public function get_due_date( $context = 'view' ) { |
|
| 435 | + return $this->get_prop( 'due_date', $context ); |
|
| 436 | 436 | } |
| 437 | 437 | |
| 438 | 438 | /** |
| 439 | - * Alias for self::get_due_date(). |
|
| 440 | - * |
|
| 441 | - * @since 1.0.19 |
|
| 442 | - * @param string $context View or edit context. |
|
| 443 | - * @return string |
|
| 444 | - */ |
|
| 445 | - public function get_date_due( $context = 'view' ) { |
|
| 446 | - return $this->get_due_date( $context ); |
|
| 439 | + * Alias for self::get_due_date(). |
|
| 440 | + * |
|
| 441 | + * @since 1.0.19 |
|
| 442 | + * @param string $context View or edit context. |
|
| 443 | + * @return string |
|
| 444 | + */ |
|
| 445 | + public function get_date_due( $context = 'view' ) { |
|
| 446 | + return $this->get_due_date( $context ); |
|
| 447 | 447 | } |
| 448 | 448 | |
| 449 | 449 | /** |
| 450 | - * Get the invoice GMT due date. |
|
| 451 | - * |
|
| 452 | - * @since 1.0.19 |
|
| 453 | - * @param string $context View or edit context. |
|
| 454 | - * @return string |
|
| 455 | - */ |
|
| 456 | - public function get_due_date_gmt( $context = 'view' ) { |
|
| 450 | + * Get the invoice GMT due date. |
|
| 451 | + * |
|
| 452 | + * @since 1.0.19 |
|
| 453 | + * @param string $context View or edit context. |
|
| 454 | + * @return string |
|
| 455 | + */ |
|
| 456 | + public function get_due_date_gmt( $context = 'view' ) { |
|
| 457 | 457 | $date = $this->get_due_date( $context ); |
| 458 | 458 | |
| 459 | 459 | if ( $date ) { |
| 460 | 460 | $date = get_gmt_from_date( $date ); |
| 461 | 461 | } |
| 462 | - return $date; |
|
| 462 | + return $date; |
|
| 463 | 463 | } |
| 464 | 464 | |
| 465 | 465 | /** |
| 466 | - * Alias for self::get_due_date_gmt(). |
|
| 467 | - * |
|
| 468 | - * @since 1.0.19 |
|
| 469 | - * @param string $context View or edit context. |
|
| 470 | - * @return string |
|
| 471 | - */ |
|
| 472 | - public function get_gmt_date_due( $context = 'view' ) { |
|
| 473 | - return $this->get_due_date_gmt( $context ); |
|
| 466 | + * Alias for self::get_due_date_gmt(). |
|
| 467 | + * |
|
| 468 | + * @since 1.0.19 |
|
| 469 | + * @param string $context View or edit context. |
|
| 470 | + * @return string |
|
| 471 | + */ |
|
| 472 | + public function get_gmt_date_due( $context = 'view' ) { |
|
| 473 | + return $this->get_due_date_gmt( $context ); |
|
| 474 | 474 | } |
| 475 | 475 | |
| 476 | 476 | /** |
| 477 | - * Get date when the invoice was completed. |
|
| 478 | - * |
|
| 479 | - * @since 1.0.19 |
|
| 480 | - * @param string $context View or edit context. |
|
| 481 | - * @return string |
|
| 482 | - */ |
|
| 483 | - public function get_completed_date( $context = 'view' ) { |
|
| 484 | - return $this->get_prop( 'completed_date', $context ); |
|
| 477 | + * Get date when the invoice was completed. |
|
| 478 | + * |
|
| 479 | + * @since 1.0.19 |
|
| 480 | + * @param string $context View or edit context. |
|
| 481 | + * @return string |
|
| 482 | + */ |
|
| 483 | + public function get_completed_date( $context = 'view' ) { |
|
| 484 | + return $this->get_prop( 'completed_date', $context ); |
|
| 485 | 485 | } |
| 486 | 486 | |
| 487 | 487 | /** |
| 488 | - * Alias for self::get_completed_date(). |
|
| 489 | - * |
|
| 490 | - * @since 1.0.19 |
|
| 491 | - * @param string $context View or edit context. |
|
| 492 | - * @return string |
|
| 493 | - */ |
|
| 494 | - public function get_date_completed( $context = 'view' ) { |
|
| 495 | - return $this->get_completed_date( $context ); |
|
| 488 | + * Alias for self::get_completed_date(). |
|
| 489 | + * |
|
| 490 | + * @since 1.0.19 |
|
| 491 | + * @param string $context View or edit context. |
|
| 492 | + * @return string |
|
| 493 | + */ |
|
| 494 | + public function get_date_completed( $context = 'view' ) { |
|
| 495 | + return $this->get_completed_date( $context ); |
|
| 496 | 496 | } |
| 497 | 497 | |
| 498 | 498 | /** |
| 499 | - * Get GMT date when the invoice was was completed. |
|
| 500 | - * |
|
| 501 | - * @since 1.0.19 |
|
| 502 | - * @param string $context View or edit context. |
|
| 503 | - * @return string |
|
| 504 | - */ |
|
| 505 | - public function get_completed_date_gmt( $context = 'view' ) { |
|
| 499 | + * Get GMT date when the invoice was was completed. |
|
| 500 | + * |
|
| 501 | + * @since 1.0.19 |
|
| 502 | + * @param string $context View or edit context. |
|
| 503 | + * @return string |
|
| 504 | + */ |
|
| 505 | + public function get_completed_date_gmt( $context = 'view' ) { |
|
| 506 | 506 | $date = $this->get_completed_date( $context ); |
| 507 | 507 | |
| 508 | 508 | if ( $date ) { |
| 509 | 509 | $date = get_gmt_from_date( $date ); |
| 510 | 510 | } |
| 511 | - return $date; |
|
| 511 | + return $date; |
|
| 512 | 512 | } |
| 513 | 513 | |
| 514 | 514 | /** |
| 515 | - * Alias for self::get_completed_date_gmt(). |
|
| 516 | - * |
|
| 517 | - * @since 1.0.19 |
|
| 518 | - * @param string $context View or edit context. |
|
| 519 | - * @return string |
|
| 520 | - */ |
|
| 521 | - public function get_gmt_completed_date( $context = 'view' ) { |
|
| 522 | - return $this->get_completed_date_gmt( $context ); |
|
| 515 | + * Alias for self::get_completed_date_gmt(). |
|
| 516 | + * |
|
| 517 | + * @since 1.0.19 |
|
| 518 | + * @param string $context View or edit context. |
|
| 519 | + * @return string |
|
| 520 | + */ |
|
| 521 | + public function get_gmt_completed_date( $context = 'view' ) { |
|
| 522 | + return $this->get_completed_date_gmt( $context ); |
|
| 523 | 523 | } |
| 524 | 524 | |
| 525 | 525 | /** |
| 526 | - * Get the invoice number. |
|
| 527 | - * |
|
| 528 | - * @since 1.0.19 |
|
| 529 | - * @param string $context View or edit context. |
|
| 530 | - * @return string |
|
| 531 | - */ |
|
| 532 | - public function get_number( $context = 'view' ) { |
|
| 533 | - $number = $this->get_prop( 'number', $context ); |
|
| 526 | + * Get the invoice number. |
|
| 527 | + * |
|
| 528 | + * @since 1.0.19 |
|
| 529 | + * @param string $context View or edit context. |
|
| 530 | + * @return string |
|
| 531 | + */ |
|
| 532 | + public function get_number( $context = 'view' ) { |
|
| 533 | + $number = $this->get_prop( 'number', $context ); |
|
| 534 | 534 | |
| 535 | - if ( empty( $number ) ) { |
|
| 536 | - $number = $this->generate_number(); |
|
| 537 | - $this->set_number( $this->generate_number() ); |
|
| 538 | - } |
|
| 535 | + if ( empty( $number ) ) { |
|
| 536 | + $number = $this->generate_number(); |
|
| 537 | + $this->set_number( $this->generate_number() ); |
|
| 538 | + } |
|
| 539 | 539 | |
| 540 | - return $number; |
|
| 540 | + return $number; |
|
| 541 | 541 | } |
| 542 | 542 | |
| 543 | - /** |
|
| 544 | - * Set the invoice number. |
|
| 545 | - * |
|
| 546 | - * @since 1.0.19 |
|
| 547 | - */ |
|
| 548 | - public function maybe_set_number() { |
|
| 543 | + /** |
|
| 544 | + * Set the invoice number. |
|
| 545 | + * |
|
| 546 | + * @since 1.0.19 |
|
| 547 | + */ |
|
| 548 | + public function maybe_set_number() { |
|
| 549 | 549 | $number = $this->get_number(); |
| 550 | 550 | |
| 551 | 551 | if ( empty( $number ) || $this->get_id() == $number ) { |
| 552 | - $this->set_number( $this->generate_number() ); |
|
| 552 | + $this->set_number( $this->generate_number() ); |
|
| 553 | 553 | } |
| 554 | 554 | |
| 555 | - } |
|
| 555 | + } |
|
| 556 | 556 | |
| 557 | 557 | /** |
| 558 | - * Get the invoice key. |
|
| 559 | - * |
|
| 560 | - * @since 1.0.19 |
|
| 561 | - * @param string $context View or edit context. |
|
| 562 | - * @return string |
|
| 563 | - */ |
|
| 564 | - public function get_key( $context = 'view' ) { |
|
| 558 | + * Get the invoice key. |
|
| 559 | + * |
|
| 560 | + * @since 1.0.19 |
|
| 561 | + * @param string $context View or edit context. |
|
| 562 | + * @return string |
|
| 563 | + */ |
|
| 564 | + public function get_key( $context = 'view' ) { |
|
| 565 | 565 | return $this->get_prop( 'key', $context ); |
| 566 | - } |
|
| 567 | - |
|
| 568 | - /** |
|
| 569 | - * Set the invoice key. |
|
| 570 | - * |
|
| 571 | - * @since 1.0.19 |
|
| 572 | - */ |
|
| 573 | - public function maybe_set_key() { |
|
| 566 | + } |
|
| 567 | + |
|
| 568 | + /** |
|
| 569 | + * Set the invoice key. |
|
| 570 | + * |
|
| 571 | + * @since 1.0.19 |
|
| 572 | + */ |
|
| 573 | + public function maybe_set_key() { |
|
| 574 | 574 | $key = $this->get_key(); |
| 575 | 575 | |
| 576 | 576 | if ( empty( $key ) ) { |
@@ -581,126 +581,126 @@ discard block |
||
| 581 | 581 | } |
| 582 | 582 | |
| 583 | 583 | /** |
| 584 | - * Get the invoice type. |
|
| 585 | - * |
|
| 586 | - * @since 1.0.19 |
|
| 587 | - * @param string $context View or edit context. |
|
| 588 | - * @return string |
|
| 589 | - */ |
|
| 590 | - public function get_type( $context = 'view' ) { |
|
| 584 | + * Get the invoice type. |
|
| 585 | + * |
|
| 586 | + * @since 1.0.19 |
|
| 587 | + * @param string $context View or edit context. |
|
| 588 | + * @return string |
|
| 589 | + */ |
|
| 590 | + public function get_type( $context = 'view' ) { |
|
| 591 | 591 | return $this->get_prop( 'type', $context ); |
| 592 | - } |
|
| 592 | + } |
|
| 593 | 593 | |
| 594 | - /** |
|
| 595 | - * @deprecated |
|
| 596 | - */ |
|
| 597 | - public function get_invoice_quote_type() { |
|
| 594 | + /** |
|
| 595 | + * @deprecated |
|
| 596 | + */ |
|
| 597 | + public function get_invoice_quote_type() { |
|
| 598 | 598 | ucfirst( $this->get_type() ); |
| 599 | 599 | } |
| 600 | 600 | |
| 601 | 601 | /** |
| 602 | - * Get the invoice post type. |
|
| 603 | - * |
|
| 604 | - * @since 1.0.19 |
|
| 605 | - * @param string $context View or edit context. |
|
| 606 | - * @return string |
|
| 607 | - */ |
|
| 608 | - public function get_post_type( $context = 'view' ) { |
|
| 602 | + * Get the invoice post type. |
|
| 603 | + * |
|
| 604 | + * @since 1.0.19 |
|
| 605 | + * @param string $context View or edit context. |
|
| 606 | + * @return string |
|
| 607 | + */ |
|
| 608 | + public function get_post_type( $context = 'view' ) { |
|
| 609 | 609 | return $this->get_prop( 'post_type', $context ); |
| 610 | 610 | } |
| 611 | 611 | |
| 612 | 612 | /** |
| 613 | - * Get the invoice mode. |
|
| 614 | - * |
|
| 615 | - * @since 1.0.19 |
|
| 616 | - * @param string $context View or edit context. |
|
| 617 | - * @return string |
|
| 618 | - */ |
|
| 619 | - public function get_mode( $context = 'view' ) { |
|
| 613 | + * Get the invoice mode. |
|
| 614 | + * |
|
| 615 | + * @since 1.0.19 |
|
| 616 | + * @param string $context View or edit context. |
|
| 617 | + * @return string |
|
| 618 | + */ |
|
| 619 | + public function get_mode( $context = 'view' ) { |
|
| 620 | 620 | return $this->get_prop( 'mode', $context ); |
| 621 | 621 | } |
| 622 | 622 | |
| 623 | 623 | /** |
| 624 | - * Get the invoice path. |
|
| 625 | - * |
|
| 626 | - * @since 1.0.19 |
|
| 627 | - * @param string $context View or edit context. |
|
| 628 | - * @return string |
|
| 629 | - */ |
|
| 630 | - public function get_path( $context = 'view' ) { |
|
| 624 | + * Get the invoice path. |
|
| 625 | + * |
|
| 626 | + * @since 1.0.19 |
|
| 627 | + * @param string $context View or edit context. |
|
| 628 | + * @return string |
|
| 629 | + */ |
|
| 630 | + public function get_path( $context = 'view' ) { |
|
| 631 | 631 | $path = $this->get_prop( 'path', $context ); |
| 632 | - $prefix = $this->get_type(); |
|
| 632 | + $prefix = $this->get_type(); |
|
| 633 | 633 | |
| 634 | - if ( 0 !== strpos( $path, $prefix ) ) { |
|
| 635 | - $path = sanitize_title( $prefix . '-' . $this->get_id() ); |
|
| 636 | - $this->set_path( $path ); |
|
| 637 | - } |
|
| 634 | + if ( 0 !== strpos( $path, $prefix ) ) { |
|
| 635 | + $path = sanitize_title( $prefix . '-' . $this->get_id() ); |
|
| 636 | + $this->set_path( $path ); |
|
| 637 | + } |
|
| 638 | 638 | |
| 639 | - return $path; |
|
| 639 | + return $path; |
|
| 640 | 640 | } |
| 641 | 641 | |
| 642 | 642 | /** |
| 643 | - * Get the invoice name/title. |
|
| 644 | - * |
|
| 645 | - * @since 1.0.19 |
|
| 646 | - * @param string $context View or edit context. |
|
| 647 | - * @return string |
|
| 648 | - */ |
|
| 649 | - public function get_name( $context = 'view' ) { |
|
| 643 | + * Get the invoice name/title. |
|
| 644 | + * |
|
| 645 | + * @since 1.0.19 |
|
| 646 | + * @param string $context View or edit context. |
|
| 647 | + * @return string |
|
| 648 | + */ |
|
| 649 | + public function get_name( $context = 'view' ) { |
|
| 650 | 650 | return $this->get_prop( 'title', $context ); |
| 651 | 651 | } |
| 652 | 652 | |
| 653 | 653 | /** |
| 654 | - * Alias of self::get_name(). |
|
| 655 | - * |
|
| 656 | - * @since 1.0.19 |
|
| 657 | - * @param string $context View or edit context. |
|
| 658 | - * @return string |
|
| 659 | - */ |
|
| 660 | - public function get_title( $context = 'view' ) { |
|
| 661 | - return $this->get_name( $context ); |
|
| 654 | + * Alias of self::get_name(). |
|
| 655 | + * |
|
| 656 | + * @since 1.0.19 |
|
| 657 | + * @param string $context View or edit context. |
|
| 658 | + * @return string |
|
| 659 | + */ |
|
| 660 | + public function get_title( $context = 'view' ) { |
|
| 661 | + return $this->get_name( $context ); |
|
| 662 | 662 | } |
| 663 | 663 | |
| 664 | 664 | /** |
| 665 | - * Get the invoice description. |
|
| 666 | - * |
|
| 667 | - * @since 1.0.19 |
|
| 668 | - * @param string $context View or edit context. |
|
| 669 | - * @return string |
|
| 670 | - */ |
|
| 671 | - public function get_description( $context = 'view' ) { |
|
| 672 | - return $this->get_prop( 'description', $context ); |
|
| 665 | + * Get the invoice description. |
|
| 666 | + * |
|
| 667 | + * @since 1.0.19 |
|
| 668 | + * @param string $context View or edit context. |
|
| 669 | + * @return string |
|
| 670 | + */ |
|
| 671 | + public function get_description( $context = 'view' ) { |
|
| 672 | + return $this->get_prop( 'description', $context ); |
|
| 673 | 673 | } |
| 674 | 674 | |
| 675 | 675 | /** |
| 676 | - * Alias of self::get_description(). |
|
| 677 | - * |
|
| 678 | - * @since 1.0.19 |
|
| 679 | - * @param string $context View or edit context. |
|
| 680 | - * @return string |
|
| 681 | - */ |
|
| 682 | - public function get_excerpt( $context = 'view' ) { |
|
| 683 | - return $this->get_description( $context ); |
|
| 676 | + * Alias of self::get_description(). |
|
| 677 | + * |
|
| 678 | + * @since 1.0.19 |
|
| 679 | + * @param string $context View or edit context. |
|
| 680 | + * @return string |
|
| 681 | + */ |
|
| 682 | + public function get_excerpt( $context = 'view' ) { |
|
| 683 | + return $this->get_description( $context ); |
|
| 684 | 684 | } |
| 685 | 685 | |
| 686 | 686 | /** |
| 687 | - * Alias of self::get_description(). |
|
| 688 | - * |
|
| 689 | - * @since 1.0.19 |
|
| 690 | - * @param string $context View or edit context. |
|
| 691 | - * @return string |
|
| 692 | - */ |
|
| 693 | - public function get_summary( $context = 'view' ) { |
|
| 694 | - return $this->get_description( $context ); |
|
| 687 | + * Alias of self::get_description(). |
|
| 688 | + * |
|
| 689 | + * @since 1.0.19 |
|
| 690 | + * @param string $context View or edit context. |
|
| 691 | + * @return string |
|
| 692 | + */ |
|
| 693 | + public function get_summary( $context = 'view' ) { |
|
| 694 | + return $this->get_description( $context ); |
|
| 695 | 695 | } |
| 696 | 696 | |
| 697 | 697 | /** |
| 698 | - * Returns the user info. |
|
| 699 | - * |
|
| 700 | - * @since 1.0.19 |
|
| 698 | + * Returns the user info. |
|
| 699 | + * |
|
| 700 | + * @since 1.0.19 |
|
| 701 | 701 | * @param string $context View or edit context. |
| 702 | - * @return array |
|
| 703 | - */ |
|
| 702 | + * @return array |
|
| 703 | + */ |
|
| 704 | 704 | public function get_user_info( $context = 'view' ) { |
| 705 | 705 | |
| 706 | 706 | $user_info = array( |
@@ -717,616 +717,616 @@ discard block |
||
| 717 | 717 | 'company' => $this->get_company( $context ), |
| 718 | 718 | 'vat_number' => $this->get_vat_number( $context ), |
| 719 | 719 | 'discount' => $this->get_discount_code( $context ), |
| 720 | - ); |
|
| 720 | + ); |
|
| 721 | 721 | |
| 722 | - return apply_filters( 'wpinv_user_info', $user_info, $this->get_id(), $this ); |
|
| 722 | + return apply_filters( 'wpinv_user_info', $user_info, $this->get_id(), $this ); |
|
| 723 | 723 | |
| 724 | 724 | } |
| 725 | 725 | |
| 726 | 726 | /** |
| 727 | - * Get the customer id. |
|
| 728 | - * |
|
| 729 | - * @since 1.0.19 |
|
| 730 | - * @param string $context View or edit context. |
|
| 731 | - * @return int |
|
| 732 | - */ |
|
| 733 | - public function get_author( $context = 'view' ) { |
|
| 734 | - return (int) $this->get_prop( 'author', $context ); |
|
| 727 | + * Get the customer id. |
|
| 728 | + * |
|
| 729 | + * @since 1.0.19 |
|
| 730 | + * @param string $context View or edit context. |
|
| 731 | + * @return int |
|
| 732 | + */ |
|
| 733 | + public function get_author( $context = 'view' ) { |
|
| 734 | + return (int) $this->get_prop( 'author', $context ); |
|
| 735 | 735 | } |
| 736 | 736 | |
| 737 | 737 | /** |
| 738 | - * Alias of self::get_author(). |
|
| 739 | - * |
|
| 740 | - * @since 1.0.19 |
|
| 741 | - * @param string $context View or edit context. |
|
| 742 | - * @return int |
|
| 743 | - */ |
|
| 744 | - public function get_user_id( $context = 'view' ) { |
|
| 745 | - return $this->get_author( $context ); |
|
| 738 | + * Alias of self::get_author(). |
|
| 739 | + * |
|
| 740 | + * @since 1.0.19 |
|
| 741 | + * @param string $context View or edit context. |
|
| 742 | + * @return int |
|
| 743 | + */ |
|
| 744 | + public function get_user_id( $context = 'view' ) { |
|
| 745 | + return $this->get_author( $context ); |
|
| 746 | 746 | } |
| 747 | 747 | |
| 748 | - /** |
|
| 749 | - * Alias of self::get_author(). |
|
| 750 | - * |
|
| 751 | - * @since 1.0.19 |
|
| 752 | - * @param string $context View or edit context. |
|
| 753 | - * @return int |
|
| 754 | - */ |
|
| 755 | - public function get_customer_id( $context = 'view' ) { |
|
| 756 | - return $this->get_author( $context ); |
|
| 748 | + /** |
|
| 749 | + * Alias of self::get_author(). |
|
| 750 | + * |
|
| 751 | + * @since 1.0.19 |
|
| 752 | + * @param string $context View or edit context. |
|
| 753 | + * @return int |
|
| 754 | + */ |
|
| 755 | + public function get_customer_id( $context = 'view' ) { |
|
| 756 | + return $this->get_author( $context ); |
|
| 757 | 757 | } |
| 758 | 758 | |
| 759 | 759 | /** |
| 760 | - * Get the customer's ip. |
|
| 761 | - * |
|
| 762 | - * @since 1.0.19 |
|
| 763 | - * @param string $context View or edit context. |
|
| 764 | - * @return string |
|
| 765 | - */ |
|
| 766 | - public function get_ip( $context = 'view' ) { |
|
| 767 | - return $this->get_prop( 'user_ip', $context ); |
|
| 760 | + * Get the customer's ip. |
|
| 761 | + * |
|
| 762 | + * @since 1.0.19 |
|
| 763 | + * @param string $context View or edit context. |
|
| 764 | + * @return string |
|
| 765 | + */ |
|
| 766 | + public function get_ip( $context = 'view' ) { |
|
| 767 | + return $this->get_prop( 'user_ip', $context ); |
|
| 768 | 768 | } |
| 769 | 769 | |
| 770 | 770 | /** |
| 771 | - * Alias of self::get_ip(). |
|
| 772 | - * |
|
| 773 | - * @since 1.0.19 |
|
| 774 | - * @param string $context View or edit context. |
|
| 775 | - * @return string |
|
| 776 | - */ |
|
| 777 | - public function get_user_ip( $context = 'view' ) { |
|
| 778 | - return $this->get_ip( $context ); |
|
| 771 | + * Alias of self::get_ip(). |
|
| 772 | + * |
|
| 773 | + * @since 1.0.19 |
|
| 774 | + * @param string $context View or edit context. |
|
| 775 | + * @return string |
|
| 776 | + */ |
|
| 777 | + public function get_user_ip( $context = 'view' ) { |
|
| 778 | + return $this->get_ip( $context ); |
|
| 779 | 779 | } |
| 780 | 780 | |
| 781 | - /** |
|
| 782 | - * Alias of self::get_ip(). |
|
| 783 | - * |
|
| 784 | - * @since 1.0.19 |
|
| 785 | - * @param string $context View or edit context. |
|
| 786 | - * @return string |
|
| 787 | - */ |
|
| 788 | - public function get_customer_ip( $context = 'view' ) { |
|
| 789 | - return $this->get_ip( $context ); |
|
| 781 | + /** |
|
| 782 | + * Alias of self::get_ip(). |
|
| 783 | + * |
|
| 784 | + * @since 1.0.19 |
|
| 785 | + * @param string $context View or edit context. |
|
| 786 | + * @return string |
|
| 787 | + */ |
|
| 788 | + public function get_customer_ip( $context = 'view' ) { |
|
| 789 | + return $this->get_ip( $context ); |
|
| 790 | 790 | } |
| 791 | 791 | |
| 792 | 792 | /** |
| 793 | - * Get the customer's first name. |
|
| 794 | - * |
|
| 795 | - * @since 1.0.19 |
|
| 796 | - * @param string $context View or edit context. |
|
| 797 | - * @return string |
|
| 798 | - */ |
|
| 799 | - public function get_first_name( $context = 'view' ) { |
|
| 800 | - return $this->get_prop( 'first_name', $context ); |
|
| 793 | + * Get the customer's first name. |
|
| 794 | + * |
|
| 795 | + * @since 1.0.19 |
|
| 796 | + * @param string $context View or edit context. |
|
| 797 | + * @return string |
|
| 798 | + */ |
|
| 799 | + public function get_first_name( $context = 'view' ) { |
|
| 800 | + return $this->get_prop( 'first_name', $context ); |
|
| 801 | 801 | } |
| 802 | 802 | |
| 803 | 803 | /** |
| 804 | - * Alias of self::get_first_name(). |
|
| 805 | - * |
|
| 806 | - * @since 1.0.19 |
|
| 807 | - * @param string $context View or edit context. |
|
| 808 | - * @return string |
|
| 809 | - */ |
|
| 810 | - public function get_user_first_name( $context = 'view' ) { |
|
| 811 | - return $this->get_first_name( $context ); |
|
| 804 | + * Alias of self::get_first_name(). |
|
| 805 | + * |
|
| 806 | + * @since 1.0.19 |
|
| 807 | + * @param string $context View or edit context. |
|
| 808 | + * @return string |
|
| 809 | + */ |
|
| 810 | + public function get_user_first_name( $context = 'view' ) { |
|
| 811 | + return $this->get_first_name( $context ); |
|
| 812 | 812 | } |
| 813 | 813 | |
| 814 | - /** |
|
| 815 | - * Alias of self::get_first_name(). |
|
| 816 | - * |
|
| 817 | - * @since 1.0.19 |
|
| 818 | - * @param string $context View or edit context. |
|
| 819 | - * @return string |
|
| 820 | - */ |
|
| 821 | - public function get_customer_first_name( $context = 'view' ) { |
|
| 822 | - return $this->get_first_name( $context ); |
|
| 814 | + /** |
|
| 815 | + * Alias of self::get_first_name(). |
|
| 816 | + * |
|
| 817 | + * @since 1.0.19 |
|
| 818 | + * @param string $context View or edit context. |
|
| 819 | + * @return string |
|
| 820 | + */ |
|
| 821 | + public function get_customer_first_name( $context = 'view' ) { |
|
| 822 | + return $this->get_first_name( $context ); |
|
| 823 | 823 | } |
| 824 | 824 | |
| 825 | 825 | /** |
| 826 | - * Get the customer's last name. |
|
| 827 | - * |
|
| 828 | - * @since 1.0.19 |
|
| 829 | - * @param string $context View or edit context. |
|
| 830 | - * @return string |
|
| 831 | - */ |
|
| 832 | - public function get_last_name( $context = 'view' ) { |
|
| 833 | - return $this->get_prop( 'last_name', $context ); |
|
| 826 | + * Get the customer's last name. |
|
| 827 | + * |
|
| 828 | + * @since 1.0.19 |
|
| 829 | + * @param string $context View or edit context. |
|
| 830 | + * @return string |
|
| 831 | + */ |
|
| 832 | + public function get_last_name( $context = 'view' ) { |
|
| 833 | + return $this->get_prop( 'last_name', $context ); |
|
| 834 | 834 | } |
| 835 | 835 | |
| 836 | 836 | /** |
| 837 | - * Alias of self::get_last_name(). |
|
| 838 | - * |
|
| 839 | - * @since 1.0.19 |
|
| 840 | - * @param string $context View or edit context. |
|
| 841 | - * @return string |
|
| 842 | - */ |
|
| 843 | - public function get_user_last_name( $context = 'view' ) { |
|
| 844 | - return $this->get_last_name( $context ); |
|
| 837 | + * Alias of self::get_last_name(). |
|
| 838 | + * |
|
| 839 | + * @since 1.0.19 |
|
| 840 | + * @param string $context View or edit context. |
|
| 841 | + * @return string |
|
| 842 | + */ |
|
| 843 | + public function get_user_last_name( $context = 'view' ) { |
|
| 844 | + return $this->get_last_name( $context ); |
|
| 845 | 845 | } |
| 846 | 846 | |
| 847 | 847 | /** |
| 848 | - * Alias of self::get_last_name(). |
|
| 849 | - * |
|
| 850 | - * @since 1.0.19 |
|
| 851 | - * @param string $context View or edit context. |
|
| 852 | - * @return string |
|
| 853 | - */ |
|
| 854 | - public function get_customer_last_name( $context = 'view' ) { |
|
| 855 | - return $this->get_last_name( $context ); |
|
| 848 | + * Alias of self::get_last_name(). |
|
| 849 | + * |
|
| 850 | + * @since 1.0.19 |
|
| 851 | + * @param string $context View or edit context. |
|
| 852 | + * @return string |
|
| 853 | + */ |
|
| 854 | + public function get_customer_last_name( $context = 'view' ) { |
|
| 855 | + return $this->get_last_name( $context ); |
|
| 856 | + } |
|
| 857 | + |
|
| 858 | + /** |
|
| 859 | + * Get the customer's full name. |
|
| 860 | + * |
|
| 861 | + * @since 1.0.19 |
|
| 862 | + * @param string $context View or edit context. |
|
| 863 | + * @return string |
|
| 864 | + */ |
|
| 865 | + public function get_full_name( $context = 'view' ) { |
|
| 866 | + return trim( $this->get_first_name( $context ) . ' ' . $this->get_last_name( $context ) ); |
|
| 867 | + } |
|
| 868 | + |
|
| 869 | + /** |
|
| 870 | + * Alias of self::get_full_name(). |
|
| 871 | + * |
|
| 872 | + * @since 1.0.19 |
|
| 873 | + * @param string $context View or edit context. |
|
| 874 | + * @return string |
|
| 875 | + */ |
|
| 876 | + public function get_user_full_name( $context = 'view' ) { |
|
| 877 | + return $this->get_full_name( $context ); |
|
| 878 | + } |
|
| 879 | + |
|
| 880 | + /** |
|
| 881 | + * Alias of self::get_full_name(). |
|
| 882 | + * |
|
| 883 | + * @since 1.0.19 |
|
| 884 | + * @param string $context View or edit context. |
|
| 885 | + * @return string |
|
| 886 | + */ |
|
| 887 | + public function get_customer_full_name( $context = 'view' ) { |
|
| 888 | + return $this->get_full_name( $context ); |
|
| 889 | + } |
|
| 890 | + |
|
| 891 | + /** |
|
| 892 | + * Get the customer's phone number. |
|
| 893 | + * |
|
| 894 | + * @since 1.0.19 |
|
| 895 | + * @param string $context View or edit context. |
|
| 896 | + * @return string |
|
| 897 | + */ |
|
| 898 | + public function get_phone( $context = 'view' ) { |
|
| 899 | + return $this->get_prop( 'phone', $context ); |
|
| 856 | 900 | } |
| 857 | 901 | |
| 858 | 902 | /** |
| 859 | - * Get the customer's full name. |
|
| 860 | - * |
|
| 861 | - * @since 1.0.19 |
|
| 862 | - * @param string $context View or edit context. |
|
| 863 | - * @return string |
|
| 864 | - */ |
|
| 865 | - public function get_full_name( $context = 'view' ) { |
|
| 866 | - return trim( $this->get_first_name( $context ) . ' ' . $this->get_last_name( $context ) ); |
|
| 903 | + * Alias of self::get_phone(). |
|
| 904 | + * |
|
| 905 | + * @since 1.0.19 |
|
| 906 | + * @param string $context View or edit context. |
|
| 907 | + * @return string |
|
| 908 | + */ |
|
| 909 | + public function get_phone_number( $context = 'view' ) { |
|
| 910 | + return $this->get_phone( $context ); |
|
| 867 | 911 | } |
| 868 | 912 | |
| 869 | 913 | /** |
| 870 | - * Alias of self::get_full_name(). |
|
| 871 | - * |
|
| 872 | - * @since 1.0.19 |
|
| 873 | - * @param string $context View or edit context. |
|
| 874 | - * @return string |
|
| 875 | - */ |
|
| 876 | - public function get_user_full_name( $context = 'view' ) { |
|
| 877 | - return $this->get_full_name( $context ); |
|
| 914 | + * Alias of self::get_phone(). |
|
| 915 | + * |
|
| 916 | + * @since 1.0.19 |
|
| 917 | + * @param string $context View or edit context. |
|
| 918 | + * @return string |
|
| 919 | + */ |
|
| 920 | + public function get_user_phone( $context = 'view' ) { |
|
| 921 | + return $this->get_phone( $context ); |
|
| 878 | 922 | } |
| 879 | 923 | |
| 880 | 924 | /** |
| 881 | - * Alias of self::get_full_name(). |
|
| 882 | - * |
|
| 883 | - * @since 1.0.19 |
|
| 884 | - * @param string $context View or edit context. |
|
| 885 | - * @return string |
|
| 886 | - */ |
|
| 887 | - public function get_customer_full_name( $context = 'view' ) { |
|
| 888 | - return $this->get_full_name( $context ); |
|
| 925 | + * Alias of self::get_phone(). |
|
| 926 | + * |
|
| 927 | + * @since 1.0.19 |
|
| 928 | + * @param string $context View or edit context. |
|
| 929 | + * @return string |
|
| 930 | + */ |
|
| 931 | + public function get_customer_phone( $context = 'view' ) { |
|
| 932 | + return $this->get_phone( $context ); |
|
| 889 | 933 | } |
| 890 | 934 | |
| 891 | 935 | /** |
| 892 | - * Get the customer's phone number. |
|
| 893 | - * |
|
| 894 | - * @since 1.0.19 |
|
| 895 | - * @param string $context View or edit context. |
|
| 896 | - * @return string |
|
| 897 | - */ |
|
| 898 | - public function get_phone( $context = 'view' ) { |
|
| 899 | - return $this->get_prop( 'phone', $context ); |
|
| 936 | + * Get the customer's email address. |
|
| 937 | + * |
|
| 938 | + * @since 1.0.19 |
|
| 939 | + * @param string $context View or edit context. |
|
| 940 | + * @return string |
|
| 941 | + */ |
|
| 942 | + public function get_email( $context = 'view' ) { |
|
| 943 | + return $this->get_prop( 'email', $context ); |
|
| 944 | + } |
|
| 945 | + |
|
| 946 | + /** |
|
| 947 | + * Alias of self::get_email(). |
|
| 948 | + * |
|
| 949 | + * @since 1.0.19 |
|
| 950 | + * @param string $context View or edit context. |
|
| 951 | + * @return string |
|
| 952 | + */ |
|
| 953 | + public function get_email_address( $context = 'view' ) { |
|
| 954 | + return $this->get_email( $context ); |
|
| 955 | + } |
|
| 956 | + |
|
| 957 | + /** |
|
| 958 | + * Alias of self::get_email(). |
|
| 959 | + * |
|
| 960 | + * @since 1.0.19 |
|
| 961 | + * @param string $context View or edit context. |
|
| 962 | + * @return string |
|
| 963 | + */ |
|
| 964 | + public function get_user_email( $context = 'view' ) { |
|
| 965 | + return $this->get_email( $context ); |
|
| 966 | + } |
|
| 967 | + |
|
| 968 | + /** |
|
| 969 | + * Alias of self::get_email(). |
|
| 970 | + * |
|
| 971 | + * @since 1.0.19 |
|
| 972 | + * @param string $context View or edit context. |
|
| 973 | + * @return string |
|
| 974 | + */ |
|
| 975 | + public function get_customer_email( $context = 'view' ) { |
|
| 976 | + return $this->get_email( $context ); |
|
| 977 | + } |
|
| 978 | + |
|
| 979 | + /** |
|
| 980 | + * Get the customer's country. |
|
| 981 | + * |
|
| 982 | + * @since 1.0.19 |
|
| 983 | + * @param string $context View or edit context. |
|
| 984 | + * @return string |
|
| 985 | + */ |
|
| 986 | + public function get_country( $context = 'view' ) { |
|
| 987 | + $country = $this->get_prop( 'country', $context ); |
|
| 988 | + return empty( $country ) ? wpinv_get_default_country() : $country; |
|
| 989 | + } |
|
| 990 | + |
|
| 991 | + /** |
|
| 992 | + * Alias of self::get_country(). |
|
| 993 | + * |
|
| 994 | + * @since 1.0.19 |
|
| 995 | + * @param string $context View or edit context. |
|
| 996 | + * @return string |
|
| 997 | + */ |
|
| 998 | + public function get_user_country( $context = 'view' ) { |
|
| 999 | + return $this->get_country( $context ); |
|
| 1000 | + } |
|
| 1001 | + |
|
| 1002 | + /** |
|
| 1003 | + * Alias of self::get_country(). |
|
| 1004 | + * |
|
| 1005 | + * @since 1.0.19 |
|
| 1006 | + * @param string $context View or edit context. |
|
| 1007 | + * @return string |
|
| 1008 | + */ |
|
| 1009 | + public function get_customer_country( $context = 'view' ) { |
|
| 1010 | + return $this->get_country( $context ); |
|
| 1011 | + } |
|
| 1012 | + |
|
| 1013 | + /** |
|
| 1014 | + * Get the customer's state. |
|
| 1015 | + * |
|
| 1016 | + * @since 1.0.19 |
|
| 1017 | + * @param string $context View or edit context. |
|
| 1018 | + * @return string |
|
| 1019 | + */ |
|
| 1020 | + public function get_state( $context = 'view' ) { |
|
| 1021 | + $state = $this->get_prop( 'state', $context ); |
|
| 1022 | + return empty( $state ) ? wpinv_get_default_state() : $state; |
|
| 1023 | + } |
|
| 1024 | + |
|
| 1025 | + /** |
|
| 1026 | + * Alias of self::get_state(). |
|
| 1027 | + * |
|
| 1028 | + * @since 1.0.19 |
|
| 1029 | + * @param string $context View or edit context. |
|
| 1030 | + * @return string |
|
| 1031 | + */ |
|
| 1032 | + public function get_user_state( $context = 'view' ) { |
|
| 1033 | + return $this->get_state( $context ); |
|
| 1034 | + } |
|
| 1035 | + |
|
| 1036 | + /** |
|
| 1037 | + * Alias of self::get_state(). |
|
| 1038 | + * |
|
| 1039 | + * @since 1.0.19 |
|
| 1040 | + * @param string $context View or edit context. |
|
| 1041 | + * @return string |
|
| 1042 | + */ |
|
| 1043 | + public function get_customer_state( $context = 'view' ) { |
|
| 1044 | + return $this->get_state( $context ); |
|
| 900 | 1045 | } |
| 901 | 1046 | |
| 902 | 1047 | /** |
| 903 | - * Alias of self::get_phone(). |
|
| 904 | - * |
|
| 905 | - * @since 1.0.19 |
|
| 906 | - * @param string $context View or edit context. |
|
| 907 | - * @return string |
|
| 908 | - */ |
|
| 909 | - public function get_phone_number( $context = 'view' ) { |
|
| 910 | - return $this->get_phone( $context ); |
|
| 1048 | + * Get the customer's city. |
|
| 1049 | + * |
|
| 1050 | + * @since 1.0.19 |
|
| 1051 | + * @param string $context View or edit context. |
|
| 1052 | + * @return string |
|
| 1053 | + */ |
|
| 1054 | + public function get_city( $context = 'view' ) { |
|
| 1055 | + return $this->get_prop( 'city', $context ); |
|
| 911 | 1056 | } |
| 912 | 1057 | |
| 913 | 1058 | /** |
| 914 | - * Alias of self::get_phone(). |
|
| 915 | - * |
|
| 916 | - * @since 1.0.19 |
|
| 917 | - * @param string $context View or edit context. |
|
| 918 | - * @return string |
|
| 919 | - */ |
|
| 920 | - public function get_user_phone( $context = 'view' ) { |
|
| 921 | - return $this->get_phone( $context ); |
|
| 1059 | + * Alias of self::get_city(). |
|
| 1060 | + * |
|
| 1061 | + * @since 1.0.19 |
|
| 1062 | + * @param string $context View or edit context. |
|
| 1063 | + * @return string |
|
| 1064 | + */ |
|
| 1065 | + public function get_user_city( $context = 'view' ) { |
|
| 1066 | + return $this->get_city( $context ); |
|
| 922 | 1067 | } |
| 923 | 1068 | |
| 924 | 1069 | /** |
| 925 | - * Alias of self::get_phone(). |
|
| 926 | - * |
|
| 927 | - * @since 1.0.19 |
|
| 928 | - * @param string $context View or edit context. |
|
| 929 | - * @return string |
|
| 930 | - */ |
|
| 931 | - public function get_customer_phone( $context = 'view' ) { |
|
| 932 | - return $this->get_phone( $context ); |
|
| 1070 | + * Alias of self::get_city(). |
|
| 1071 | + * |
|
| 1072 | + * @since 1.0.19 |
|
| 1073 | + * @param string $context View or edit context. |
|
| 1074 | + * @return string |
|
| 1075 | + */ |
|
| 1076 | + public function get_customer_city( $context = 'view' ) { |
|
| 1077 | + return $this->get_city( $context ); |
|
| 933 | 1078 | } |
| 934 | 1079 | |
| 935 | 1080 | /** |
| 936 | - * Get the customer's email address. |
|
| 937 | - * |
|
| 938 | - * @since 1.0.19 |
|
| 939 | - * @param string $context View or edit context. |
|
| 940 | - * @return string |
|
| 941 | - */ |
|
| 942 | - public function get_email( $context = 'view' ) { |
|
| 943 | - return $this->get_prop( 'email', $context ); |
|
| 1081 | + * Get the customer's zip. |
|
| 1082 | + * |
|
| 1083 | + * @since 1.0.19 |
|
| 1084 | + * @param string $context View or edit context. |
|
| 1085 | + * @return string |
|
| 1086 | + */ |
|
| 1087 | + public function get_zip( $context = 'view' ) { |
|
| 1088 | + return $this->get_prop( 'zip', $context ); |
|
| 944 | 1089 | } |
| 945 | 1090 | |
| 946 | 1091 | /** |
| 947 | - * Alias of self::get_email(). |
|
| 948 | - * |
|
| 949 | - * @since 1.0.19 |
|
| 950 | - * @param string $context View or edit context. |
|
| 951 | - * @return string |
|
| 952 | - */ |
|
| 953 | - public function get_email_address( $context = 'view' ) { |
|
| 954 | - return $this->get_email( $context ); |
|
| 1092 | + * Alias of self::get_zip(). |
|
| 1093 | + * |
|
| 1094 | + * @since 1.0.19 |
|
| 1095 | + * @param string $context View or edit context. |
|
| 1096 | + * @return string |
|
| 1097 | + */ |
|
| 1098 | + public function get_user_zip( $context = 'view' ) { |
|
| 1099 | + return $this->get_zip( $context ); |
|
| 955 | 1100 | } |
| 956 | 1101 | |
| 957 | 1102 | /** |
| 958 | - * Alias of self::get_email(). |
|
| 959 | - * |
|
| 960 | - * @since 1.0.19 |
|
| 961 | - * @param string $context View or edit context. |
|
| 962 | - * @return string |
|
| 963 | - */ |
|
| 964 | - public function get_user_email( $context = 'view' ) { |
|
| 965 | - return $this->get_email( $context ); |
|
| 1103 | + * Alias of self::get_zip(). |
|
| 1104 | + * |
|
| 1105 | + * @since 1.0.19 |
|
| 1106 | + * @param string $context View or edit context. |
|
| 1107 | + * @return string |
|
| 1108 | + */ |
|
| 1109 | + public function get_customer_zip( $context = 'view' ) { |
|
| 1110 | + return $this->get_zip( $context ); |
|
| 966 | 1111 | } |
| 967 | 1112 | |
| 968 | 1113 | /** |
| 969 | - * Alias of self::get_email(). |
|
| 970 | - * |
|
| 971 | - * @since 1.0.19 |
|
| 972 | - * @param string $context View or edit context. |
|
| 973 | - * @return string |
|
| 974 | - */ |
|
| 975 | - public function get_customer_email( $context = 'view' ) { |
|
| 976 | - return $this->get_email( $context ); |
|
| 1114 | + * Get the customer's company. |
|
| 1115 | + * |
|
| 1116 | + * @since 1.0.19 |
|
| 1117 | + * @param string $context View or edit context. |
|
| 1118 | + * @return string |
|
| 1119 | + */ |
|
| 1120 | + public function get_company( $context = 'view' ) { |
|
| 1121 | + return $this->get_prop( 'company', $context ); |
|
| 977 | 1122 | } |
| 978 | 1123 | |
| 979 | 1124 | /** |
| 980 | - * Get the customer's country. |
|
| 981 | - * |
|
| 982 | - * @since 1.0.19 |
|
| 983 | - * @param string $context View or edit context. |
|
| 984 | - * @return string |
|
| 985 | - */ |
|
| 986 | - public function get_country( $context = 'view' ) { |
|
| 987 | - $country = $this->get_prop( 'country', $context ); |
|
| 988 | - return empty( $country ) ? wpinv_get_default_country() : $country; |
|
| 1125 | + * Alias of self::get_company(). |
|
| 1126 | + * |
|
| 1127 | + * @since 1.0.19 |
|
| 1128 | + * @param string $context View or edit context. |
|
| 1129 | + * @return string |
|
| 1130 | + */ |
|
| 1131 | + public function get_user_company( $context = 'view' ) { |
|
| 1132 | + return $this->get_company( $context ); |
|
| 989 | 1133 | } |
| 990 | 1134 | |
| 991 | 1135 | /** |
| 992 | - * Alias of self::get_country(). |
|
| 993 | - * |
|
| 994 | - * @since 1.0.19 |
|
| 995 | - * @param string $context View or edit context. |
|
| 996 | - * @return string |
|
| 997 | - */ |
|
| 998 | - public function get_user_country( $context = 'view' ) { |
|
| 999 | - return $this->get_country( $context ); |
|
| 1136 | + * Alias of self::get_company(). |
|
| 1137 | + * |
|
| 1138 | + * @since 1.0.19 |
|
| 1139 | + * @param string $context View or edit context. |
|
| 1140 | + * @return string |
|
| 1141 | + */ |
|
| 1142 | + public function get_customer_company( $context = 'view' ) { |
|
| 1143 | + return $this->get_company( $context ); |
|
| 1000 | 1144 | } |
| 1001 | 1145 | |
| 1002 | 1146 | /** |
| 1003 | - * Alias of self::get_country(). |
|
| 1004 | - * |
|
| 1005 | - * @since 1.0.19 |
|
| 1006 | - * @param string $context View or edit context. |
|
| 1007 | - * @return string |
|
| 1008 | - */ |
|
| 1009 | - public function get_customer_country( $context = 'view' ) { |
|
| 1010 | - return $this->get_country( $context ); |
|
| 1147 | + * Get the customer's vat number. |
|
| 1148 | + * |
|
| 1149 | + * @since 1.0.19 |
|
| 1150 | + * @param string $context View or edit context. |
|
| 1151 | + * @return string |
|
| 1152 | + */ |
|
| 1153 | + public function get_vat_number( $context = 'view' ) { |
|
| 1154 | + return $this->get_prop( 'vat_number', $context ); |
|
| 1011 | 1155 | } |
| 1012 | 1156 | |
| 1013 | 1157 | /** |
| 1014 | - * Get the customer's state. |
|
| 1015 | - * |
|
| 1016 | - * @since 1.0.19 |
|
| 1017 | - * @param string $context View or edit context. |
|
| 1018 | - * @return string |
|
| 1019 | - */ |
|
| 1020 | - public function get_state( $context = 'view' ) { |
|
| 1021 | - $state = $this->get_prop( 'state', $context ); |
|
| 1022 | - return empty( $state ) ? wpinv_get_default_state() : $state; |
|
| 1158 | + * Alias of self::get_vat_number(). |
|
| 1159 | + * |
|
| 1160 | + * @since 1.0.19 |
|
| 1161 | + * @param string $context View or edit context. |
|
| 1162 | + * @return string |
|
| 1163 | + */ |
|
| 1164 | + public function get_user_vat_number( $context = 'view' ) { |
|
| 1165 | + return $this->get_vat_number( $context ); |
|
| 1023 | 1166 | } |
| 1024 | 1167 | |
| 1025 | 1168 | /** |
| 1026 | - * Alias of self::get_state(). |
|
| 1027 | - * |
|
| 1028 | - * @since 1.0.19 |
|
| 1029 | - * @param string $context View or edit context. |
|
| 1030 | - * @return string |
|
| 1031 | - */ |
|
| 1032 | - public function get_user_state( $context = 'view' ) { |
|
| 1033 | - return $this->get_state( $context ); |
|
| 1169 | + * Alias of self::get_vat_number(). |
|
| 1170 | + * |
|
| 1171 | + * @since 1.0.19 |
|
| 1172 | + * @param string $context View or edit context. |
|
| 1173 | + * @return string |
|
| 1174 | + */ |
|
| 1175 | + public function get_customer_vat_number( $context = 'view' ) { |
|
| 1176 | + return $this->get_vat_number( $context ); |
|
| 1034 | 1177 | } |
| 1035 | 1178 | |
| 1036 | 1179 | /** |
| 1037 | - * Alias of self::get_state(). |
|
| 1038 | - * |
|
| 1039 | - * @since 1.0.19 |
|
| 1040 | - * @param string $context View or edit context. |
|
| 1041 | - * @return string |
|
| 1042 | - */ |
|
| 1043 | - public function get_customer_state( $context = 'view' ) { |
|
| 1044 | - return $this->get_state( $context ); |
|
| 1180 | + * Get the customer's vat rate. |
|
| 1181 | + * |
|
| 1182 | + * @since 1.0.19 |
|
| 1183 | + * @param string $context View or edit context. |
|
| 1184 | + * @return string |
|
| 1185 | + */ |
|
| 1186 | + public function get_vat_rate( $context = 'view' ) { |
|
| 1187 | + return $this->get_prop( 'vat_rate', $context ); |
|
| 1045 | 1188 | } |
| 1046 | 1189 | |
| 1047 | 1190 | /** |
| 1048 | - * Get the customer's city. |
|
| 1049 | - * |
|
| 1050 | - * @since 1.0.19 |
|
| 1051 | - * @param string $context View or edit context. |
|
| 1052 | - * @return string |
|
| 1053 | - */ |
|
| 1054 | - public function get_city( $context = 'view' ) { |
|
| 1055 | - return $this->get_prop( 'city', $context ); |
|
| 1191 | + * Alias of self::get_vat_rate(). |
|
| 1192 | + * |
|
| 1193 | + * @since 1.0.19 |
|
| 1194 | + * @param string $context View or edit context. |
|
| 1195 | + * @return string |
|
| 1196 | + */ |
|
| 1197 | + public function get_user_vat_rate( $context = 'view' ) { |
|
| 1198 | + return $this->get_vat_rate( $context ); |
|
| 1056 | 1199 | } |
| 1057 | 1200 | |
| 1058 | 1201 | /** |
| 1059 | - * Alias of self::get_city(). |
|
| 1060 | - * |
|
| 1061 | - * @since 1.0.19 |
|
| 1062 | - * @param string $context View or edit context. |
|
| 1063 | - * @return string |
|
| 1064 | - */ |
|
| 1065 | - public function get_user_city( $context = 'view' ) { |
|
| 1066 | - return $this->get_city( $context ); |
|
| 1202 | + * Alias of self::get_vat_rate(). |
|
| 1203 | + * |
|
| 1204 | + * @since 1.0.19 |
|
| 1205 | + * @param string $context View or edit context. |
|
| 1206 | + * @return string |
|
| 1207 | + */ |
|
| 1208 | + public function get_customer_vat_rate( $context = 'view' ) { |
|
| 1209 | + return $this->get_vat_rate( $context ); |
|
| 1067 | 1210 | } |
| 1068 | 1211 | |
| 1069 | 1212 | /** |
| 1070 | - * Alias of self::get_city(). |
|
| 1071 | - * |
|
| 1072 | - * @since 1.0.19 |
|
| 1073 | - * @param string $context View or edit context. |
|
| 1074 | - * @return string |
|
| 1075 | - */ |
|
| 1076 | - public function get_customer_city( $context = 'view' ) { |
|
| 1077 | - return $this->get_city( $context ); |
|
| 1213 | + * Get the customer's address. |
|
| 1214 | + * |
|
| 1215 | + * @since 1.0.19 |
|
| 1216 | + * @param string $context View or edit context. |
|
| 1217 | + * @return string |
|
| 1218 | + */ |
|
| 1219 | + public function get_address( $context = 'view' ) { |
|
| 1220 | + return $this->get_prop( 'address', $context ); |
|
| 1078 | 1221 | } |
| 1079 | 1222 | |
| 1080 | 1223 | /** |
| 1081 | - * Get the customer's zip. |
|
| 1082 | - * |
|
| 1083 | - * @since 1.0.19 |
|
| 1084 | - * @param string $context View or edit context. |
|
| 1085 | - * @return string |
|
| 1086 | - */ |
|
| 1087 | - public function get_zip( $context = 'view' ) { |
|
| 1088 | - return $this->get_prop( 'zip', $context ); |
|
| 1224 | + * Alias of self::get_address(). |
|
| 1225 | + * |
|
| 1226 | + * @since 1.0.19 |
|
| 1227 | + * @param string $context View or edit context. |
|
| 1228 | + * @return string |
|
| 1229 | + */ |
|
| 1230 | + public function get_user_address( $context = 'view' ) { |
|
| 1231 | + return $this->get_address( $context ); |
|
| 1089 | 1232 | } |
| 1090 | 1233 | |
| 1091 | 1234 | /** |
| 1092 | - * Alias of self::get_zip(). |
|
| 1093 | - * |
|
| 1094 | - * @since 1.0.19 |
|
| 1095 | - * @param string $context View or edit context. |
|
| 1096 | - * @return string |
|
| 1097 | - */ |
|
| 1098 | - public function get_user_zip( $context = 'view' ) { |
|
| 1099 | - return $this->get_zip( $context ); |
|
| 1235 | + * Alias of self::get_address(). |
|
| 1236 | + * |
|
| 1237 | + * @since 1.0.19 |
|
| 1238 | + * @param string $context View or edit context. |
|
| 1239 | + * @return string |
|
| 1240 | + */ |
|
| 1241 | + public function get_customer_address( $context = 'view' ) { |
|
| 1242 | + return $this->get_address( $context ); |
|
| 1100 | 1243 | } |
| 1101 | 1244 | |
| 1102 | 1245 | /** |
| 1103 | - * Alias of self::get_zip(). |
|
| 1104 | - * |
|
| 1105 | - * @since 1.0.19 |
|
| 1106 | - * @param string $context View or edit context. |
|
| 1107 | - * @return string |
|
| 1108 | - */ |
|
| 1109 | - public function get_customer_zip( $context = 'view' ) { |
|
| 1110 | - return $this->get_zip( $context ); |
|
| 1246 | + * Get whether the customer has viewed the invoice or not. |
|
| 1247 | + * |
|
| 1248 | + * @since 1.0.19 |
|
| 1249 | + * @param string $context View or edit context. |
|
| 1250 | + * @return bool |
|
| 1251 | + */ |
|
| 1252 | + public function get_is_viewed( $context = 'view' ) { |
|
| 1253 | + return (bool) $this->get_prop( 'is_viewed', $context ); |
|
| 1111 | 1254 | } |
| 1112 | 1255 | |
| 1113 | 1256 | /** |
| 1114 | - * Get the customer's company. |
|
| 1115 | - * |
|
| 1116 | - * @since 1.0.19 |
|
| 1117 | - * @param string $context View or edit context. |
|
| 1118 | - * @return string |
|
| 1119 | - */ |
|
| 1120 | - public function get_company( $context = 'view' ) { |
|
| 1121 | - return $this->get_prop( 'company', $context ); |
|
| 1257 | + * Get other recipients for invoice communications. |
|
| 1258 | + * |
|
| 1259 | + * @since 1.0.19 |
|
| 1260 | + * @param string $context View or edit context. |
|
| 1261 | + * @return bool |
|
| 1262 | + */ |
|
| 1263 | + public function get_email_cc( $context = 'view' ) { |
|
| 1264 | + return $this->get_prop( 'email_cc', $context ); |
|
| 1122 | 1265 | } |
| 1123 | 1266 | |
| 1124 | 1267 | /** |
| 1125 | - * Alias of self::get_company(). |
|
| 1126 | - * |
|
| 1127 | - * @since 1.0.19 |
|
| 1128 | - * @param string $context View or edit context. |
|
| 1129 | - * @return string |
|
| 1130 | - */ |
|
| 1131 | - public function get_user_company( $context = 'view' ) { |
|
| 1132 | - return $this->get_company( $context ); |
|
| 1268 | + * Get invoice template. |
|
| 1269 | + * |
|
| 1270 | + * @since 1.0.19 |
|
| 1271 | + * @param string $context View or edit context. |
|
| 1272 | + * @return bool |
|
| 1273 | + */ |
|
| 1274 | + public function get_template( $context = 'view' ) { |
|
| 1275 | + return $this->get_prop( 'template', $context ); |
|
| 1133 | 1276 | } |
| 1134 | 1277 | |
| 1135 | 1278 | /** |
| 1136 | - * Alias of self::get_company(). |
|
| 1137 | - * |
|
| 1138 | - * @since 1.0.19 |
|
| 1139 | - * @param string $context View or edit context. |
|
| 1140 | - * @return string |
|
| 1141 | - */ |
|
| 1142 | - public function get_customer_company( $context = 'view' ) { |
|
| 1143 | - return $this->get_company( $context ); |
|
| 1279 | + * Get invoice source. |
|
| 1280 | + * |
|
| 1281 | + * @since 1.0.19 |
|
| 1282 | + * @param string $context View or edit context. |
|
| 1283 | + * @return bool |
|
| 1284 | + */ |
|
| 1285 | + public function get_created_via( $context = 'view' ) { |
|
| 1286 | + return $this->get_prop( 'created_via', $context ); |
|
| 1144 | 1287 | } |
| 1145 | 1288 | |
| 1146 | 1289 | /** |
| 1147 | - * Get the customer's vat number. |
|
| 1148 | - * |
|
| 1149 | - * @since 1.0.19 |
|
| 1150 | - * @param string $context View or edit context. |
|
| 1151 | - * @return string |
|
| 1152 | - */ |
|
| 1153 | - public function get_vat_number( $context = 'view' ) { |
|
| 1154 | - return $this->get_prop( 'vat_number', $context ); |
|
| 1290 | + * Get whether the customer has confirmed their address. |
|
| 1291 | + * |
|
| 1292 | + * @since 1.0.19 |
|
| 1293 | + * @param string $context View or edit context. |
|
| 1294 | + * @return bool |
|
| 1295 | + */ |
|
| 1296 | + public function get_address_confirmed( $context = 'view' ) { |
|
| 1297 | + return (bool) $this->get_prop( 'address_confirmed', $context ); |
|
| 1155 | 1298 | } |
| 1156 | 1299 | |
| 1157 | 1300 | /** |
| 1158 | - * Alias of self::get_vat_number(). |
|
| 1159 | - * |
|
| 1160 | - * @since 1.0.19 |
|
| 1161 | - * @param string $context View or edit context. |
|
| 1162 | - * @return string |
|
| 1163 | - */ |
|
| 1164 | - public function get_user_vat_number( $context = 'view' ) { |
|
| 1165 | - return $this->get_vat_number( $context ); |
|
| 1301 | + * Alias of self::get_address_confirmed(). |
|
| 1302 | + * |
|
| 1303 | + * @since 1.0.19 |
|
| 1304 | + * @param string $context View or edit context. |
|
| 1305 | + * @return bool |
|
| 1306 | + */ |
|
| 1307 | + public function get_user_address_confirmed( $context = 'view' ) { |
|
| 1308 | + return $this->get_address_confirmed( $context ); |
|
| 1166 | 1309 | } |
| 1167 | 1310 | |
| 1168 | 1311 | /** |
| 1169 | - * Alias of self::get_vat_number(). |
|
| 1170 | - * |
|
| 1171 | - * @since 1.0.19 |
|
| 1172 | - * @param string $context View or edit context. |
|
| 1173 | - * @return string |
|
| 1174 | - */ |
|
| 1175 | - public function get_customer_vat_number( $context = 'view' ) { |
|
| 1176 | - return $this->get_vat_number( $context ); |
|
| 1312 | + * Alias of self::get_address(). |
|
| 1313 | + * |
|
| 1314 | + * @since 1.0.19 |
|
| 1315 | + * @param string $context View or edit context. |
|
| 1316 | + * @return bool |
|
| 1317 | + */ |
|
| 1318 | + public function get_customer_address_confirmed( $context = 'view' ) { |
|
| 1319 | + return $this->get_address_confirmed( $context ); |
|
| 1177 | 1320 | } |
| 1178 | 1321 | |
| 1179 | 1322 | /** |
| 1180 | - * Get the customer's vat rate. |
|
| 1181 | - * |
|
| 1182 | - * @since 1.0.19 |
|
| 1183 | - * @param string $context View or edit context. |
|
| 1184 | - * @return string |
|
| 1185 | - */ |
|
| 1186 | - public function get_vat_rate( $context = 'view' ) { |
|
| 1187 | - return $this->get_prop( 'vat_rate', $context ); |
|
| 1188 | - } |
|
| 1189 | - |
|
| 1190 | - /** |
|
| 1191 | - * Alias of self::get_vat_rate(). |
|
| 1192 | - * |
|
| 1193 | - * @since 1.0.19 |
|
| 1194 | - * @param string $context View or edit context. |
|
| 1195 | - * @return string |
|
| 1196 | - */ |
|
| 1197 | - public function get_user_vat_rate( $context = 'view' ) { |
|
| 1198 | - return $this->get_vat_rate( $context ); |
|
| 1199 | - } |
|
| 1200 | - |
|
| 1201 | - /** |
|
| 1202 | - * Alias of self::get_vat_rate(). |
|
| 1203 | - * |
|
| 1204 | - * @since 1.0.19 |
|
| 1205 | - * @param string $context View or edit context. |
|
| 1206 | - * @return string |
|
| 1207 | - */ |
|
| 1208 | - public function get_customer_vat_rate( $context = 'view' ) { |
|
| 1209 | - return $this->get_vat_rate( $context ); |
|
| 1210 | - } |
|
| 1211 | - |
|
| 1212 | - /** |
|
| 1213 | - * Get the customer's address. |
|
| 1214 | - * |
|
| 1215 | - * @since 1.0.19 |
|
| 1216 | - * @param string $context View or edit context. |
|
| 1217 | - * @return string |
|
| 1218 | - */ |
|
| 1219 | - public function get_address( $context = 'view' ) { |
|
| 1220 | - return $this->get_prop( 'address', $context ); |
|
| 1221 | - } |
|
| 1222 | - |
|
| 1223 | - /** |
|
| 1224 | - * Alias of self::get_address(). |
|
| 1225 | - * |
|
| 1226 | - * @since 1.0.19 |
|
| 1227 | - * @param string $context View or edit context. |
|
| 1228 | - * @return string |
|
| 1229 | - */ |
|
| 1230 | - public function get_user_address( $context = 'view' ) { |
|
| 1231 | - return $this->get_address( $context ); |
|
| 1232 | - } |
|
| 1233 | - |
|
| 1234 | - /** |
|
| 1235 | - * Alias of self::get_address(). |
|
| 1236 | - * |
|
| 1237 | - * @since 1.0.19 |
|
| 1238 | - * @param string $context View or edit context. |
|
| 1239 | - * @return string |
|
| 1240 | - */ |
|
| 1241 | - public function get_customer_address( $context = 'view' ) { |
|
| 1242 | - return $this->get_address( $context ); |
|
| 1243 | - } |
|
| 1244 | - |
|
| 1245 | - /** |
|
| 1246 | - * Get whether the customer has viewed the invoice or not. |
|
| 1247 | - * |
|
| 1248 | - * @since 1.0.19 |
|
| 1249 | - * @param string $context View or edit context. |
|
| 1250 | - * @return bool |
|
| 1251 | - */ |
|
| 1252 | - public function get_is_viewed( $context = 'view' ) { |
|
| 1253 | - return (bool) $this->get_prop( 'is_viewed', $context ); |
|
| 1254 | - } |
|
| 1255 | - |
|
| 1256 | - /** |
|
| 1257 | - * Get other recipients for invoice communications. |
|
| 1258 | - * |
|
| 1259 | - * @since 1.0.19 |
|
| 1260 | - * @param string $context View or edit context. |
|
| 1261 | - * @return bool |
|
| 1262 | - */ |
|
| 1263 | - public function get_email_cc( $context = 'view' ) { |
|
| 1264 | - return $this->get_prop( 'email_cc', $context ); |
|
| 1265 | - } |
|
| 1266 | - |
|
| 1267 | - /** |
|
| 1268 | - * Get invoice template. |
|
| 1269 | - * |
|
| 1270 | - * @since 1.0.19 |
|
| 1271 | - * @param string $context View or edit context. |
|
| 1272 | - * @return bool |
|
| 1273 | - */ |
|
| 1274 | - public function get_template( $context = 'view' ) { |
|
| 1275 | - return $this->get_prop( 'template', $context ); |
|
| 1276 | - } |
|
| 1277 | - |
|
| 1278 | - /** |
|
| 1279 | - * Get invoice source. |
|
| 1280 | - * |
|
| 1281 | - * @since 1.0.19 |
|
| 1282 | - * @param string $context View or edit context. |
|
| 1283 | - * @return bool |
|
| 1284 | - */ |
|
| 1285 | - public function get_created_via( $context = 'view' ) { |
|
| 1286 | - return $this->get_prop( 'created_via', $context ); |
|
| 1287 | - } |
|
| 1288 | - |
|
| 1289 | - /** |
|
| 1290 | - * Get whether the customer has confirmed their address. |
|
| 1291 | - * |
|
| 1292 | - * @since 1.0.19 |
|
| 1293 | - * @param string $context View or edit context. |
|
| 1294 | - * @return bool |
|
| 1295 | - */ |
|
| 1296 | - public function get_address_confirmed( $context = 'view' ) { |
|
| 1297 | - return (bool) $this->get_prop( 'address_confirmed', $context ); |
|
| 1298 | - } |
|
| 1299 | - |
|
| 1300 | - /** |
|
| 1301 | - * Alias of self::get_address_confirmed(). |
|
| 1302 | - * |
|
| 1303 | - * @since 1.0.19 |
|
| 1304 | - * @param string $context View or edit context. |
|
| 1305 | - * @return bool |
|
| 1306 | - */ |
|
| 1307 | - public function get_user_address_confirmed( $context = 'view' ) { |
|
| 1308 | - return $this->get_address_confirmed( $context ); |
|
| 1309 | - } |
|
| 1310 | - |
|
| 1311 | - /** |
|
| 1312 | - * Alias of self::get_address(). |
|
| 1313 | - * |
|
| 1314 | - * @since 1.0.19 |
|
| 1315 | - * @param string $context View or edit context. |
|
| 1316 | - * @return bool |
|
| 1317 | - */ |
|
| 1318 | - public function get_customer_address_confirmed( $context = 'view' ) { |
|
| 1319 | - return $this->get_address_confirmed( $context ); |
|
| 1320 | - } |
|
| 1321 | - |
|
| 1322 | - /** |
|
| 1323 | - * Get the invoice subtotal. |
|
| 1324 | - * |
|
| 1325 | - * @since 1.0.19 |
|
| 1326 | - * @param string $context View or edit context. |
|
| 1327 | - * @return float |
|
| 1328 | - */ |
|
| 1329 | - public function get_subtotal( $context = 'view' ) { |
|
| 1323 | + * Get the invoice subtotal. |
|
| 1324 | + * |
|
| 1325 | + * @since 1.0.19 |
|
| 1326 | + * @param string $context View or edit context. |
|
| 1327 | + * @return float |
|
| 1328 | + */ |
|
| 1329 | + public function get_subtotal( $context = 'view' ) { |
|
| 1330 | 1330 | $subtotal = (float) $this->get_prop( 'subtotal', $context ); |
| 1331 | 1331 | |
| 1332 | 1332 | // Backwards compatibility. |
@@ -1338,165 +1338,165 @@ discard block |
||
| 1338 | 1338 | } |
| 1339 | 1339 | |
| 1340 | 1340 | /** |
| 1341 | - * Get the invoice discount total. |
|
| 1342 | - * |
|
| 1343 | - * @since 1.0.19 |
|
| 1344 | - * @param string $context View or edit context. |
|
| 1345 | - * @return float |
|
| 1346 | - */ |
|
| 1347 | - public function get_total_discount( $context = 'view' ) { |
|
| 1348 | - return (float) $this->get_prop( 'total_discount', $context ); |
|
| 1341 | + * Get the invoice discount total. |
|
| 1342 | + * |
|
| 1343 | + * @since 1.0.19 |
|
| 1344 | + * @param string $context View or edit context. |
|
| 1345 | + * @return float |
|
| 1346 | + */ |
|
| 1347 | + public function get_total_discount( $context = 'view' ) { |
|
| 1348 | + return (float) $this->get_prop( 'total_discount', $context ); |
|
| 1349 | + } |
|
| 1350 | + |
|
| 1351 | + /** |
|
| 1352 | + * Get the invoice tax total. |
|
| 1353 | + * |
|
| 1354 | + * @since 1.0.19 |
|
| 1355 | + * @param string $context View or edit context. |
|
| 1356 | + * @return float |
|
| 1357 | + */ |
|
| 1358 | + public function get_total_tax( $context = 'view' ) { |
|
| 1359 | + return (float) $this->get_prop( 'total_tax', $context ); |
|
| 1349 | 1360 | } |
| 1350 | 1361 | |
| 1351 | 1362 | /** |
| 1352 | - * Get the invoice tax total. |
|
| 1353 | - * |
|
| 1354 | - * @since 1.0.19 |
|
| 1355 | - * @param string $context View or edit context. |
|
| 1356 | - * @return float |
|
| 1357 | - */ |
|
| 1358 | - public function get_total_tax( $context = 'view' ) { |
|
| 1359 | - return (float) $this->get_prop( 'total_tax', $context ); |
|
| 1360 | - } |
|
| 1361 | - |
|
| 1362 | - /** |
|
| 1363 | - * @deprecated |
|
| 1364 | - */ |
|
| 1365 | - public function get_final_tax( $currency = false ) { |
|
| 1366 | - $tax = $this->get_total_tax(); |
|
| 1363 | + * @deprecated |
|
| 1364 | + */ |
|
| 1365 | + public function get_final_tax( $currency = false ) { |
|
| 1366 | + $tax = $this->get_total_tax(); |
|
| 1367 | 1367 | |
| 1368 | 1368 | if ( $currency ) { |
| 1369 | - return wpinv_price( $tax, $this->get_currency() ); |
|
| 1369 | + return wpinv_price( $tax, $this->get_currency() ); |
|
| 1370 | 1370 | } |
| 1371 | 1371 | |
| 1372 | 1372 | return $tax; |
| 1373 | 1373 | } |
| 1374 | 1374 | |
| 1375 | 1375 | /** |
| 1376 | - * Get the invoice fees total. |
|
| 1377 | - * |
|
| 1378 | - * @since 1.0.19 |
|
| 1379 | - * @param string $context View or edit context. |
|
| 1380 | - * @return float |
|
| 1381 | - */ |
|
| 1382 | - public function get_total_fees( $context = 'view' ) { |
|
| 1383 | - return (float) $this->get_prop( 'total_fees', $context ); |
|
| 1376 | + * Get the invoice fees total. |
|
| 1377 | + * |
|
| 1378 | + * @since 1.0.19 |
|
| 1379 | + * @param string $context View or edit context. |
|
| 1380 | + * @return float |
|
| 1381 | + */ |
|
| 1382 | + public function get_total_fees( $context = 'view' ) { |
|
| 1383 | + return (float) $this->get_prop( 'total_fees', $context ); |
|
| 1384 | 1384 | } |
| 1385 | 1385 | |
| 1386 | 1386 | /** |
| 1387 | - * Alias for self::get_total_fees(). |
|
| 1388 | - * |
|
| 1389 | - * @since 1.0.19 |
|
| 1390 | - * @param string $context View or edit context. |
|
| 1391 | - * @return float |
|
| 1392 | - */ |
|
| 1393 | - public function get_fees_total( $context = 'view' ) { |
|
| 1394 | - return $this->get_total_fees( $context ); |
|
| 1387 | + * Alias for self::get_total_fees(). |
|
| 1388 | + * |
|
| 1389 | + * @since 1.0.19 |
|
| 1390 | + * @param string $context View or edit context. |
|
| 1391 | + * @return float |
|
| 1392 | + */ |
|
| 1393 | + public function get_fees_total( $context = 'view' ) { |
|
| 1394 | + return $this->get_total_fees( $context ); |
|
| 1395 | 1395 | } |
| 1396 | 1396 | |
| 1397 | 1397 | /** |
| 1398 | - * Get the invoice total. |
|
| 1399 | - * |
|
| 1400 | - * @since 1.0.19 |
|
| 1398 | + * Get the invoice total. |
|
| 1399 | + * |
|
| 1400 | + * @since 1.0.19 |
|
| 1401 | 1401 | * @return float |
| 1402 | - */ |
|
| 1403 | - public function get_total() { |
|
| 1404 | - $total = $this->is_renewal() ? $this->get_recurring_total() : $this->get_initial_total(); |
|
| 1405 | - return apply_filters( 'getpaid_get_invoice_total_amount', $total, $this ); |
|
| 1406 | - } |
|
| 1402 | + */ |
|
| 1403 | + public function get_total() { |
|
| 1404 | + $total = $this->is_renewal() ? $this->get_recurring_total() : $this->get_initial_total(); |
|
| 1405 | + return apply_filters( 'getpaid_get_invoice_total_amount', $total, $this ); |
|
| 1406 | + } |
|
| 1407 | 1407 | |
| 1408 | - /** |
|
| 1409 | - * Get the invoice totals. |
|
| 1410 | - * |
|
| 1411 | - * @since 1.0.19 |
|
| 1408 | + /** |
|
| 1409 | + * Get the invoice totals. |
|
| 1410 | + * |
|
| 1411 | + * @since 1.0.19 |
|
| 1412 | 1412 | * @return array |
| 1413 | - */ |
|
| 1414 | - public function get_totals() { |
|
| 1415 | - return $this->totals; |
|
| 1413 | + */ |
|
| 1414 | + public function get_totals() { |
|
| 1415 | + return $this->totals; |
|
| 1416 | 1416 | } |
| 1417 | 1417 | |
| 1418 | 1418 | /** |
| 1419 | - * Get the initial invoice total. |
|
| 1420 | - * |
|
| 1421 | - * @since 1.0.19 |
|
| 1419 | + * Get the initial invoice total. |
|
| 1420 | + * |
|
| 1421 | + * @since 1.0.19 |
|
| 1422 | 1422 | * @param string $context View or edit context. |
| 1423 | 1423 | * @return float |
| 1424 | - */ |
|
| 1424 | + */ |
|
| 1425 | 1425 | public function get_initial_total() { |
| 1426 | 1426 | |
| 1427 | - if ( empty( $this->totals ) ) { |
|
| 1428 | - $this->recalculate_total(); |
|
| 1429 | - } |
|
| 1427 | + if ( empty( $this->totals ) ) { |
|
| 1428 | + $this->recalculate_total(); |
|
| 1429 | + } |
|
| 1430 | 1430 | |
| 1431 | - $tax = $this->totals['tax']['initial']; |
|
| 1432 | - $fee = $this->totals['fee']['initial']; |
|
| 1433 | - $discount = $this->totals['discount']['initial']; |
|
| 1434 | - $subtotal = $this->totals['subtotal']['initial']; |
|
| 1435 | - $total = $tax + $fee - $discount + $subtotal; |
|
| 1431 | + $tax = $this->totals['tax']['initial']; |
|
| 1432 | + $fee = $this->totals['fee']['initial']; |
|
| 1433 | + $discount = $this->totals['discount']['initial']; |
|
| 1434 | + $subtotal = $this->totals['subtotal']['initial']; |
|
| 1435 | + $total = $tax + $fee - $discount + $subtotal; |
|
| 1436 | 1436 | |
| 1437 | - if ( 0 > $total ) { |
|
| 1438 | - $total = 0; |
|
| 1439 | - } |
|
| 1437 | + if ( 0 > $total ) { |
|
| 1438 | + $total = 0; |
|
| 1439 | + } |
|
| 1440 | 1440 | |
| 1441 | 1441 | return apply_filters( 'wpinv_get_initial_invoice_total', $total, $this ); |
| 1442 | - } |
|
| 1442 | + } |
|
| 1443 | 1443 | |
| 1444 | - /** |
|
| 1445 | - * Get the recurring invoice total. |
|
| 1446 | - * |
|
| 1447 | - * @since 1.0.19 |
|
| 1444 | + /** |
|
| 1445 | + * Get the recurring invoice total. |
|
| 1446 | + * |
|
| 1447 | + * @since 1.0.19 |
|
| 1448 | 1448 | * @param string $context View or edit context. |
| 1449 | 1449 | * @return float |
| 1450 | - */ |
|
| 1450 | + */ |
|
| 1451 | 1451 | public function get_recurring_total() { |
| 1452 | 1452 | |
| 1453 | - if ( empty( $this->totals ) ) { |
|
| 1454 | - $this->recalculate_total(); |
|
| 1455 | - } |
|
| 1453 | + if ( empty( $this->totals ) ) { |
|
| 1454 | + $this->recalculate_total(); |
|
| 1455 | + } |
|
| 1456 | 1456 | |
| 1457 | - $tax = $this->totals['tax']['recurring']; |
|
| 1458 | - $fee = $this->totals['fee']['recurring']; |
|
| 1459 | - $discount = $this->totals['discount']['recurring']; |
|
| 1460 | - $subtotal = $this->totals['subtotal']['recurring']; |
|
| 1461 | - $total = $tax + $fee - $discount + $subtotal; |
|
| 1457 | + $tax = $this->totals['tax']['recurring']; |
|
| 1458 | + $fee = $this->totals['fee']['recurring']; |
|
| 1459 | + $discount = $this->totals['discount']['recurring']; |
|
| 1460 | + $subtotal = $this->totals['subtotal']['recurring']; |
|
| 1461 | + $total = $tax + $fee - $discount + $subtotal; |
|
| 1462 | 1462 | |
| 1463 | - if ( 0 > $total ) { |
|
| 1464 | - $total = 0; |
|
| 1465 | - } |
|
| 1463 | + if ( 0 > $total ) { |
|
| 1464 | + $total = 0; |
|
| 1465 | + } |
|
| 1466 | 1466 | |
| 1467 | 1467 | return apply_filters( 'wpinv_get_recurring_invoice_total', $total, $this ); |
| 1468 | - } |
|
| 1468 | + } |
|
| 1469 | 1469 | |
| 1470 | - /** |
|
| 1471 | - * Returns recurring payment details. |
|
| 1472 | - * |
|
| 1473 | - * @since 1.0.19 |
|
| 1470 | + /** |
|
| 1471 | + * Returns recurring payment details. |
|
| 1472 | + * |
|
| 1473 | + * @since 1.0.19 |
|
| 1474 | 1474 | * @param string $field Optionally provide a field to return. |
| 1475 | - * @param string $currency Whether to include the currency. |
|
| 1475 | + * @param string $currency Whether to include the currency. |
|
| 1476 | 1476 | * @return float|string |
| 1477 | - */ |
|
| 1477 | + */ |
|
| 1478 | 1478 | public function get_recurring_details( $field = '', $currency = false ) { |
| 1479 | 1479 | |
| 1480 | - // Maybe recalculate totals. |
|
| 1481 | - if ( empty( $this->totals ) ) { |
|
| 1482 | - $this->recalculate_total(); |
|
| 1483 | - } |
|
| 1480 | + // Maybe recalculate totals. |
|
| 1481 | + if ( empty( $this->totals ) ) { |
|
| 1482 | + $this->recalculate_total(); |
|
| 1483 | + } |
|
| 1484 | 1484 | |
| 1485 | - // Prepare recurring totals. |
|
| 1485 | + // Prepare recurring totals. |
|
| 1486 | 1486 | $data = apply_filters( |
| 1487 | - 'wpinv_get_invoice_recurring_details', |
|
| 1488 | - array( |
|
| 1489 | - 'cart_details' => $this->get_cart_details(), |
|
| 1490 | - 'subtotal' => $this->totals['subtotal']['recurring'], |
|
| 1491 | - 'discount' => $this->totals['discount']['recurring'], |
|
| 1492 | - 'tax' => $this->totals['tax']['recurring'], |
|
| 1493 | - 'fee' => $this->totals['fee']['recurring'], |
|
| 1494 | - 'total' => $this->get_recurring_total(), |
|
| 1495 | - ), |
|
| 1496 | - $this, |
|
| 1497 | - $field, |
|
| 1498 | - $currency |
|
| 1499 | - ); |
|
| 1487 | + 'wpinv_get_invoice_recurring_details', |
|
| 1488 | + array( |
|
| 1489 | + 'cart_details' => $this->get_cart_details(), |
|
| 1490 | + 'subtotal' => $this->totals['subtotal']['recurring'], |
|
| 1491 | + 'discount' => $this->totals['discount']['recurring'], |
|
| 1492 | + 'tax' => $this->totals['tax']['recurring'], |
|
| 1493 | + 'fee' => $this->totals['fee']['recurring'], |
|
| 1494 | + 'total' => $this->get_recurring_total(), |
|
| 1495 | + ), |
|
| 1496 | + $this, |
|
| 1497 | + $field, |
|
| 1498 | + $currency |
|
| 1499 | + ); |
|
| 1500 | 1500 | |
| 1501 | 1501 | if ( isset( $data[$field] ) ) { |
| 1502 | 1502 | return ( $currency ? wpinv_price( $data[$field], $this->get_currency() ) : $data[$field] ); |
@@ -1506,156 +1506,156 @@ discard block |
||
| 1506 | 1506 | } |
| 1507 | 1507 | |
| 1508 | 1508 | /** |
| 1509 | - * Get the invoice fees. |
|
| 1510 | - * |
|
| 1511 | - * @since 1.0.19 |
|
| 1512 | - * @param string $context View or edit context. |
|
| 1513 | - * @return array |
|
| 1514 | - */ |
|
| 1515 | - public function get_fees( $context = 'view' ) { |
|
| 1516 | - return wpinv_parse_list( $this->get_prop( 'fees', $context ) ); |
|
| 1509 | + * Get the invoice fees. |
|
| 1510 | + * |
|
| 1511 | + * @since 1.0.19 |
|
| 1512 | + * @param string $context View or edit context. |
|
| 1513 | + * @return array |
|
| 1514 | + */ |
|
| 1515 | + public function get_fees( $context = 'view' ) { |
|
| 1516 | + return wpinv_parse_list( $this->get_prop( 'fees', $context ) ); |
|
| 1517 | 1517 | } |
| 1518 | 1518 | |
| 1519 | 1519 | /** |
| 1520 | - * Get the invoice discounts. |
|
| 1521 | - * |
|
| 1522 | - * @since 1.0.19 |
|
| 1523 | - * @param string $context View or edit context. |
|
| 1524 | - * @return array |
|
| 1525 | - */ |
|
| 1526 | - public function get_discounts( $context = 'view' ) { |
|
| 1527 | - return wpinv_parse_list( $this->get_prop( 'discounts', $context ) ); |
|
| 1520 | + * Get the invoice discounts. |
|
| 1521 | + * |
|
| 1522 | + * @since 1.0.19 |
|
| 1523 | + * @param string $context View or edit context. |
|
| 1524 | + * @return array |
|
| 1525 | + */ |
|
| 1526 | + public function get_discounts( $context = 'view' ) { |
|
| 1527 | + return wpinv_parse_list( $this->get_prop( 'discounts', $context ) ); |
|
| 1528 | 1528 | } |
| 1529 | 1529 | |
| 1530 | 1530 | /** |
| 1531 | - * Get the invoice taxes. |
|
| 1532 | - * |
|
| 1533 | - * @since 1.0.19 |
|
| 1534 | - * @param string $context View or edit context. |
|
| 1535 | - * @return array |
|
| 1536 | - */ |
|
| 1537 | - public function get_taxes( $context = 'view' ) { |
|
| 1538 | - return wpinv_parse_list( $this->get_prop( 'taxes', $context ) ); |
|
| 1531 | + * Get the invoice taxes. |
|
| 1532 | + * |
|
| 1533 | + * @since 1.0.19 |
|
| 1534 | + * @param string $context View or edit context. |
|
| 1535 | + * @return array |
|
| 1536 | + */ |
|
| 1537 | + public function get_taxes( $context = 'view' ) { |
|
| 1538 | + return wpinv_parse_list( $this->get_prop( 'taxes', $context ) ); |
|
| 1539 | 1539 | } |
| 1540 | 1540 | |
| 1541 | 1541 | /** |
| 1542 | - * Get the invoice items. |
|
| 1543 | - * |
|
| 1544 | - * @since 1.0.19 |
|
| 1545 | - * @param string $context View or edit context. |
|
| 1546 | - * @return GetPaid_Form_Item[] |
|
| 1547 | - */ |
|
| 1548 | - public function get_items( $context = 'view' ) { |
|
| 1542 | + * Get the invoice items. |
|
| 1543 | + * |
|
| 1544 | + * @since 1.0.19 |
|
| 1545 | + * @param string $context View or edit context. |
|
| 1546 | + * @return GetPaid_Form_Item[] |
|
| 1547 | + */ |
|
| 1548 | + public function get_items( $context = 'view' ) { |
|
| 1549 | 1549 | return $this->get_prop( 'items', $context ); |
| 1550 | 1550 | } |
| 1551 | 1551 | |
| 1552 | 1552 | /** |
| 1553 | - * Get the invoice's payment form. |
|
| 1554 | - * |
|
| 1555 | - * @since 1.0.19 |
|
| 1556 | - * @param string $context View or edit context. |
|
| 1557 | - * @return int |
|
| 1558 | - */ |
|
| 1559 | - public function get_payment_form( $context = 'view' ) { |
|
| 1560 | - return intval( $this->get_prop( 'payment_form', $context ) ); |
|
| 1553 | + * Get the invoice's payment form. |
|
| 1554 | + * |
|
| 1555 | + * @since 1.0.19 |
|
| 1556 | + * @param string $context View or edit context. |
|
| 1557 | + * @return int |
|
| 1558 | + */ |
|
| 1559 | + public function get_payment_form( $context = 'view' ) { |
|
| 1560 | + return intval( $this->get_prop( 'payment_form', $context ) ); |
|
| 1561 | 1561 | } |
| 1562 | 1562 | |
| 1563 | 1563 | /** |
| 1564 | - * Get the invoice's submission id. |
|
| 1565 | - * |
|
| 1566 | - * @since 1.0.19 |
|
| 1567 | - * @param string $context View or edit context. |
|
| 1568 | - * @return string |
|
| 1569 | - */ |
|
| 1570 | - public function get_submission_id( $context = 'view' ) { |
|
| 1571 | - return $this->get_prop( 'submission_id', $context ); |
|
| 1564 | + * Get the invoice's submission id. |
|
| 1565 | + * |
|
| 1566 | + * @since 1.0.19 |
|
| 1567 | + * @param string $context View or edit context. |
|
| 1568 | + * @return string |
|
| 1569 | + */ |
|
| 1570 | + public function get_submission_id( $context = 'view' ) { |
|
| 1571 | + return $this->get_prop( 'submission_id', $context ); |
|
| 1572 | 1572 | } |
| 1573 | 1573 | |
| 1574 | 1574 | /** |
| 1575 | - * Get the invoice's discount code. |
|
| 1576 | - * |
|
| 1577 | - * @since 1.0.19 |
|
| 1578 | - * @param string $context View or edit context. |
|
| 1579 | - * @return string |
|
| 1580 | - */ |
|
| 1581 | - public function get_discount_code( $context = 'view' ) { |
|
| 1582 | - return $this->get_prop( 'discount_code', $context ); |
|
| 1575 | + * Get the invoice's discount code. |
|
| 1576 | + * |
|
| 1577 | + * @since 1.0.19 |
|
| 1578 | + * @param string $context View or edit context. |
|
| 1579 | + * @return string |
|
| 1580 | + */ |
|
| 1581 | + public function get_discount_code( $context = 'view' ) { |
|
| 1582 | + return $this->get_prop( 'discount_code', $context ); |
|
| 1583 | 1583 | } |
| 1584 | 1584 | |
| 1585 | 1585 | /** |
| 1586 | - * Get the invoice's gateway. |
|
| 1587 | - * |
|
| 1588 | - * @since 1.0.19 |
|
| 1589 | - * @param string $context View or edit context. |
|
| 1590 | - * @return string |
|
| 1591 | - */ |
|
| 1592 | - public function get_gateway( $context = 'view' ) { |
|
| 1593 | - return $this->get_prop( 'gateway', $context ); |
|
| 1586 | + * Get the invoice's gateway. |
|
| 1587 | + * |
|
| 1588 | + * @since 1.0.19 |
|
| 1589 | + * @param string $context View or edit context. |
|
| 1590 | + * @return string |
|
| 1591 | + */ |
|
| 1592 | + public function get_gateway( $context = 'view' ) { |
|
| 1593 | + return $this->get_prop( 'gateway', $context ); |
|
| 1594 | 1594 | } |
| 1595 | 1595 | |
| 1596 | 1596 | /** |
| 1597 | - * Get the invoice's gateway display title. |
|
| 1598 | - * |
|
| 1599 | - * @since 1.0.19 |
|
| 1600 | - * @return string |
|
| 1601 | - */ |
|
| 1597 | + * Get the invoice's gateway display title. |
|
| 1598 | + * |
|
| 1599 | + * @since 1.0.19 |
|
| 1600 | + * @return string |
|
| 1601 | + */ |
|
| 1602 | 1602 | public function get_gateway_title() { |
| 1603 | 1603 | $title = wpinv_get_gateway_checkout_label( $this->get_gateway() ); |
| 1604 | 1604 | return apply_filters( 'wpinv_gateway_title', $title, $this->get_id(), $this ); |
| 1605 | 1605 | } |
| 1606 | 1606 | |
| 1607 | 1607 | /** |
| 1608 | - * Get the invoice's transaction id. |
|
| 1609 | - * |
|
| 1610 | - * @since 1.0.19 |
|
| 1611 | - * @param string $context View or edit context. |
|
| 1612 | - * @return string |
|
| 1613 | - */ |
|
| 1614 | - public function get_transaction_id( $context = 'view' ) { |
|
| 1615 | - return $this->get_prop( 'transaction_id', $context ); |
|
| 1608 | + * Get the invoice's transaction id. |
|
| 1609 | + * |
|
| 1610 | + * @since 1.0.19 |
|
| 1611 | + * @param string $context View or edit context. |
|
| 1612 | + * @return string |
|
| 1613 | + */ |
|
| 1614 | + public function get_transaction_id( $context = 'view' ) { |
|
| 1615 | + return $this->get_prop( 'transaction_id', $context ); |
|
| 1616 | 1616 | } |
| 1617 | 1617 | |
| 1618 | 1618 | /** |
| 1619 | - * Get the invoice's currency. |
|
| 1620 | - * |
|
| 1621 | - * @since 1.0.19 |
|
| 1622 | - * @param string $context View or edit context. |
|
| 1623 | - * @return string |
|
| 1624 | - */ |
|
| 1625 | - public function get_currency( $context = 'view' ) { |
|
| 1619 | + * Get the invoice's currency. |
|
| 1620 | + * |
|
| 1621 | + * @since 1.0.19 |
|
| 1622 | + * @param string $context View or edit context. |
|
| 1623 | + * @return string |
|
| 1624 | + */ |
|
| 1625 | + public function get_currency( $context = 'view' ) { |
|
| 1626 | 1626 | $currency = $this->get_prop( 'currency', $context ); |
| 1627 | 1627 | return empty( $currency ) ? wpinv_get_currency() : $currency; |
| 1628 | 1628 | } |
| 1629 | 1629 | |
| 1630 | 1630 | /** |
| 1631 | - * Checks if we are charging taxes for this invoice. |
|
| 1632 | - * |
|
| 1633 | - * @since 1.0.19 |
|
| 1634 | - * @param string $context View or edit context. |
|
| 1635 | - * @return bool |
|
| 1636 | - */ |
|
| 1637 | - public function get_disable_taxes( $context = 'view' ) { |
|
| 1631 | + * Checks if we are charging taxes for this invoice. |
|
| 1632 | + * |
|
| 1633 | + * @since 1.0.19 |
|
| 1634 | + * @param string $context View or edit context. |
|
| 1635 | + * @return bool |
|
| 1636 | + */ |
|
| 1637 | + public function get_disable_taxes( $context = 'view' ) { |
|
| 1638 | 1638 | return (bool) $this->get_prop( 'disable_taxes', $context ); |
| 1639 | 1639 | } |
| 1640 | 1640 | |
| 1641 | 1641 | /** |
| 1642 | - * Retrieves the subscription id for an invoice. |
|
| 1643 | - * |
|
| 1644 | - * @since 1.0.19 |
|
| 1645 | - * @param string $context View or edit context. |
|
| 1646 | - * @return int |
|
| 1647 | - */ |
|
| 1642 | + * Retrieves the subscription id for an invoice. |
|
| 1643 | + * |
|
| 1644 | + * @since 1.0.19 |
|
| 1645 | + * @param string $context View or edit context. |
|
| 1646 | + * @return int |
|
| 1647 | + */ |
|
| 1648 | 1648 | public function get_subscription_id( $context = 'view' ) { |
| 1649 | - return $this->is_renewal() ? $this->get_parent()->get_subscription_id( $context ) : $this->get_prop( 'subscription_id', $context ); |
|
| 1650 | - } |
|
| 1651 | - |
|
| 1652 | - /** |
|
| 1653 | - * Retrieves the remote subscription id for an invoice. |
|
| 1654 | - * |
|
| 1655 | - * @since 1.0.19 |
|
| 1656 | - * @param string $context View or edit context. |
|
| 1657 | - * @return int |
|
| 1658 | - */ |
|
| 1649 | + return $this->is_renewal() ? $this->get_parent()->get_subscription_id( $context ) : $this->get_prop( 'subscription_id', $context ); |
|
| 1650 | + } |
|
| 1651 | + |
|
| 1652 | + /** |
|
| 1653 | + * Retrieves the remote subscription id for an invoice. |
|
| 1654 | + * |
|
| 1655 | + * @since 1.0.19 |
|
| 1656 | + * @param string $context View or edit context. |
|
| 1657 | + * @return int |
|
| 1658 | + */ |
|
| 1659 | 1659 | public function get_remote_subscription_id( $context = 'view' ) { |
| 1660 | 1660 | $subscription_id = $this->get_prop( 'remote_subscription_id', $context ); |
| 1661 | 1661 | |
@@ -1668,12 +1668,12 @@ discard block |
||
| 1668 | 1668 | } |
| 1669 | 1669 | |
| 1670 | 1670 | /** |
| 1671 | - * Retrieves the payment meta for an invoice. |
|
| 1672 | - * |
|
| 1673 | - * @since 1.0.19 |
|
| 1674 | - * @param string $context View or edit context. |
|
| 1675 | - * @return array |
|
| 1676 | - */ |
|
| 1671 | + * Retrieves the payment meta for an invoice. |
|
| 1672 | + * |
|
| 1673 | + * @since 1.0.19 |
|
| 1674 | + * @param string $context View or edit context. |
|
| 1675 | + * @return array |
|
| 1676 | + */ |
|
| 1677 | 1677 | public function get_payment_meta( $context = 'view' ) { |
| 1678 | 1678 | |
| 1679 | 1679 | return array( |
@@ -1693,31 +1693,31 @@ discard block |
||
| 1693 | 1693 | } |
| 1694 | 1694 | |
| 1695 | 1695 | /** |
| 1696 | - * Retrieves the cart details for an invoice. |
|
| 1697 | - * |
|
| 1698 | - * @since 1.0.19 |
|
| 1699 | - * @return array |
|
| 1700 | - */ |
|
| 1696 | + * Retrieves the cart details for an invoice. |
|
| 1697 | + * |
|
| 1698 | + * @since 1.0.19 |
|
| 1699 | + * @return array |
|
| 1700 | + */ |
|
| 1701 | 1701 | public function get_cart_details() { |
| 1702 | 1702 | $items = $this->get_items(); |
| 1703 | 1703 | $cart_details = array(); |
| 1704 | 1704 | |
| 1705 | 1705 | foreach ( $items as $item_id => $item ) { |
| 1706 | - $item->invoice_id = $this->get_id(); |
|
| 1706 | + $item->invoice_id = $this->get_id(); |
|
| 1707 | 1707 | $cart_details[] = $item->prepare_data_for_saving(); |
| 1708 | 1708 | } |
| 1709 | 1709 | |
| 1710 | 1710 | return $cart_details; |
| 1711 | - } |
|
| 1711 | + } |
|
| 1712 | 1712 | |
| 1713 | - /** |
|
| 1714 | - * Retrieves the recurring item. |
|
| 1715 | - * |
|
| 1716 | - * @return null|GetPaid_Form_Item|int |
|
| 1717 | - */ |
|
| 1718 | - public function get_recurring( $object = false ) { |
|
| 1713 | + /** |
|
| 1714 | + * Retrieves the recurring item. |
|
| 1715 | + * |
|
| 1716 | + * @return null|GetPaid_Form_Item|int |
|
| 1717 | + */ |
|
| 1718 | + public function get_recurring( $object = false ) { |
|
| 1719 | 1719 | |
| 1720 | - // Are we returning an object? |
|
| 1720 | + // Are we returning an object? |
|
| 1721 | 1721 | if ( $object ) { |
| 1722 | 1722 | return $this->get_item( $this->recurring_item ); |
| 1723 | 1723 | } |
@@ -1725,114 +1725,114 @@ discard block |
||
| 1725 | 1725 | return $this->recurring_item; |
| 1726 | 1726 | } |
| 1727 | 1727 | |
| 1728 | - /** |
|
| 1729 | - * Retrieves the subscription name. |
|
| 1730 | - * |
|
| 1731 | - * @since 1.0.19 |
|
| 1732 | - * @return string |
|
| 1733 | - */ |
|
| 1734 | - public function get_subscription_name() { |
|
| 1728 | + /** |
|
| 1729 | + * Retrieves the subscription name. |
|
| 1730 | + * |
|
| 1731 | + * @since 1.0.19 |
|
| 1732 | + * @return string |
|
| 1733 | + */ |
|
| 1734 | + public function get_subscription_name() { |
|
| 1735 | 1735 | |
| 1736 | - // Retrieve the recurring name |
|
| 1736 | + // Retrieve the recurring name |
|
| 1737 | 1737 | $item = $this->get_recurring( true ); |
| 1738 | 1738 | |
| 1739 | - // Abort if it does not exist. |
|
| 1739 | + // Abort if it does not exist. |
|
| 1740 | 1740 | if ( empty( $item ) ) { |
| 1741 | 1741 | return ''; |
| 1742 | 1742 | } |
| 1743 | 1743 | |
| 1744 | - // Return the item name. |
|
| 1744 | + // Return the item name. |
|
| 1745 | 1745 | return apply_filters( 'wpinv_invoice_get_subscription_name', $item->get_name(), $this ); |
| 1746 | - } |
|
| 1747 | - |
|
| 1748 | - /** |
|
| 1749 | - * Retrieves the view url. |
|
| 1750 | - * |
|
| 1751 | - * @since 1.0.19 |
|
| 1752 | - * @return string |
|
| 1753 | - */ |
|
| 1754 | - public function get_view_url() { |
|
| 1746 | + } |
|
| 1747 | + |
|
| 1748 | + /** |
|
| 1749 | + * Retrieves the view url. |
|
| 1750 | + * |
|
| 1751 | + * @since 1.0.19 |
|
| 1752 | + * @return string |
|
| 1753 | + */ |
|
| 1754 | + public function get_view_url() { |
|
| 1755 | 1755 | $invoice_url = get_permalink( $this->get_id() ); |
| 1756 | - $invoice_url = add_query_arg( 'invoice_key', $this->get_key(), $invoice_url ); |
|
| 1756 | + $invoice_url = add_query_arg( 'invoice_key', $this->get_key(), $invoice_url ); |
|
| 1757 | 1757 | return apply_filters( 'wpinv_get_view_url', $invoice_url, $this ); |
| 1758 | - } |
|
| 1758 | + } |
|
| 1759 | 1759 | |
| 1760 | - /** |
|
| 1761 | - * Retrieves the payment url. |
|
| 1762 | - * |
|
| 1763 | - * @since 1.0.19 |
|
| 1764 | - * @return string |
|
| 1765 | - */ |
|
| 1766 | - public function get_checkout_payment_url( $deprecated = false, $secret = false ) { |
|
| 1760 | + /** |
|
| 1761 | + * Retrieves the payment url. |
|
| 1762 | + * |
|
| 1763 | + * @since 1.0.19 |
|
| 1764 | + * @return string |
|
| 1765 | + */ |
|
| 1766 | + public function get_checkout_payment_url( $deprecated = false, $secret = false ) { |
|
| 1767 | 1767 | |
| 1768 | - // Retrieve the checkout url. |
|
| 1768 | + // Retrieve the checkout url. |
|
| 1769 | 1769 | $pay_url = wpinv_get_checkout_uri(); |
| 1770 | 1770 | |
| 1771 | - // Maybe force ssl. |
|
| 1771 | + // Maybe force ssl. |
|
| 1772 | 1772 | if ( is_ssl() ) { |
| 1773 | 1773 | $pay_url = str_replace( 'http:', 'https:', $pay_url ); |
| 1774 | 1774 | } |
| 1775 | 1775 | |
| 1776 | - // Add the invoice key. |
|
| 1777 | - $pay_url = add_query_arg( 'invoice_key', $this->get_key(), $pay_url ); |
|
| 1776 | + // Add the invoice key. |
|
| 1777 | + $pay_url = add_query_arg( 'invoice_key', $this->get_key(), $pay_url ); |
|
| 1778 | 1778 | |
| 1779 | - // (Maybe?) add a secret |
|
| 1779 | + // (Maybe?) add a secret |
|
| 1780 | 1780 | if ( $secret ) { |
| 1781 | 1781 | $pay_url = add_query_arg( array( '_wpipay' => md5( $this->get_user_id() . '::' . $this->get_email() . '::' . $this->get_key() ) ), $pay_url ); |
| 1782 | 1782 | } |
| 1783 | 1783 | |
| 1784 | 1784 | return apply_filters( 'wpinv_get_checkout_payment_url', $pay_url, $this, $deprecated, $secret ); |
| 1785 | - } |
|
| 1785 | + } |
|
| 1786 | 1786 | |
| 1787 | - /** |
|
| 1788 | - * Retrieves the receipt url. |
|
| 1789 | - * |
|
| 1790 | - * @since 1.0.19 |
|
| 1791 | - * @return string |
|
| 1792 | - */ |
|
| 1793 | - public function get_receipt_url() { |
|
| 1794 | - |
|
| 1795 | - // Retrieve the checkout url. |
|
| 1787 | + /** |
|
| 1788 | + * Retrieves the receipt url. |
|
| 1789 | + * |
|
| 1790 | + * @since 1.0.19 |
|
| 1791 | + * @return string |
|
| 1792 | + */ |
|
| 1793 | + public function get_receipt_url() { |
|
| 1794 | + |
|
| 1795 | + // Retrieve the checkout url. |
|
| 1796 | 1796 | $receipt_url = wpinv_get_success_page_uri(); |
| 1797 | 1797 | |
| 1798 | - // Maybe force ssl. |
|
| 1798 | + // Maybe force ssl. |
|
| 1799 | 1799 | if ( is_ssl() ) { |
| 1800 | 1800 | $receipt_url = str_replace( 'http:', 'https:', $receipt_url ); |
| 1801 | 1801 | } |
| 1802 | 1802 | |
| 1803 | - // Add the invoice key. |
|
| 1804 | - $receipt_url = add_query_arg( 'invoice_key', $this->get_key(), $receipt_url ); |
|
| 1803 | + // Add the invoice key. |
|
| 1804 | + $receipt_url = add_query_arg( 'invoice_key', $this->get_key(), $receipt_url ); |
|
| 1805 | 1805 | |
| 1806 | 1806 | return apply_filters( 'getpaid_get_invoice_receipt_url', $receipt_url, $this ); |
| 1807 | - } |
|
| 1807 | + } |
|
| 1808 | 1808 | |
| 1809 | - /** |
|
| 1810 | - * Retrieves the default status. |
|
| 1811 | - * |
|
| 1812 | - * @since 1.0.19 |
|
| 1813 | - * @return string |
|
| 1814 | - */ |
|
| 1815 | - public function get_default_status() { |
|
| 1816 | - |
|
| 1817 | - $type = $this->get_type(); |
|
| 1818 | - $status = "wpi-$type-pending"; |
|
| 1819 | - return str_replace( '-invoice', '', $status ); |
|
| 1820 | - |
|
| 1821 | - } |
|
| 1822 | - |
|
| 1823 | - /** |
|
| 1824 | - * Magic method for accessing invoice properties. |
|
| 1825 | - * |
|
| 1826 | - * @since 1.0.15 |
|
| 1827 | - * @access public |
|
| 1828 | - * |
|
| 1829 | - * @param string $key Discount data to retrieve |
|
| 1830 | - * @param string $context View or edit context. |
|
| 1831 | - * @return mixed Value of the given invoice property (if set). |
|
| 1832 | - */ |
|
| 1833 | - public function get( $key, $context = 'view' ) { |
|
| 1809 | + /** |
|
| 1810 | + * Retrieves the default status. |
|
| 1811 | + * |
|
| 1812 | + * @since 1.0.19 |
|
| 1813 | + * @return string |
|
| 1814 | + */ |
|
| 1815 | + public function get_default_status() { |
|
| 1816 | + |
|
| 1817 | + $type = $this->get_type(); |
|
| 1818 | + $status = "wpi-$type-pending"; |
|
| 1819 | + return str_replace( '-invoice', '', $status ); |
|
| 1820 | + |
|
| 1821 | + } |
|
| 1822 | + |
|
| 1823 | + /** |
|
| 1824 | + * Magic method for accessing invoice properties. |
|
| 1825 | + * |
|
| 1826 | + * @since 1.0.15 |
|
| 1827 | + * @access public |
|
| 1828 | + * |
|
| 1829 | + * @param string $key Discount data to retrieve |
|
| 1830 | + * @param string $context View or edit context. |
|
| 1831 | + * @return mixed Value of the given invoice property (if set). |
|
| 1832 | + */ |
|
| 1833 | + public function get( $key, $context = 'view' ) { |
|
| 1834 | 1834 | return $this->get_prop( $key, $context ); |
| 1835 | - } |
|
| 1835 | + } |
|
| 1836 | 1836 | |
| 1837 | 1837 | /* |
| 1838 | 1838 | |-------------------------------------------------------------------------- |
@@ -1845,130 +1845,130 @@ discard block |
||
| 1845 | 1845 | */ |
| 1846 | 1846 | |
| 1847 | 1847 | /** |
| 1848 | - * Magic method for setting invoice properties. |
|
| 1849 | - * |
|
| 1850 | - * @since 1.0.19 |
|
| 1851 | - * @access public |
|
| 1852 | - * |
|
| 1853 | - * @param string $key Discount data to retrieve |
|
| 1854 | - * @param mixed $value new value. |
|
| 1855 | - * @return mixed Value of the given invoice property (if set). |
|
| 1856 | - */ |
|
| 1857 | - public function set( $key, $value ) { |
|
| 1848 | + * Magic method for setting invoice properties. |
|
| 1849 | + * |
|
| 1850 | + * @since 1.0.19 |
|
| 1851 | + * @access public |
|
| 1852 | + * |
|
| 1853 | + * @param string $key Discount data to retrieve |
|
| 1854 | + * @param mixed $value new value. |
|
| 1855 | + * @return mixed Value of the given invoice property (if set). |
|
| 1856 | + */ |
|
| 1857 | + public function set( $key, $value ) { |
|
| 1858 | 1858 | |
| 1859 | 1859 | $setter = "set_$key"; |
| 1860 | 1860 | if ( is_callable( array( $this, $setter ) ) ) { |
| 1861 | 1861 | $this->{$setter}( $value ); |
| 1862 | 1862 | } |
| 1863 | 1863 | |
| 1864 | - } |
|
| 1864 | + } |
|
| 1865 | 1865 | |
| 1866 | - /** |
|
| 1867 | - * Sets item status. |
|
| 1868 | - * |
|
| 1869 | - * @since 1.0.19 |
|
| 1870 | - * @param string $new_status New status. |
|
| 1871 | - * @param string $note Optional note to add. |
|
| 1872 | - * @param bool $manual_update Is this a manual status change?. |
|
| 1873 | - * @return array details of change. |
|
| 1874 | - */ |
|
| 1875 | - public function set_status( $new_status, $note = '', $manual_update = false ) { |
|
| 1876 | - $old_status = $this->get_status(); |
|
| 1866 | + /** |
|
| 1867 | + * Sets item status. |
|
| 1868 | + * |
|
| 1869 | + * @since 1.0.19 |
|
| 1870 | + * @param string $new_status New status. |
|
| 1871 | + * @param string $note Optional note to add. |
|
| 1872 | + * @param bool $manual_update Is this a manual status change?. |
|
| 1873 | + * @return array details of change. |
|
| 1874 | + */ |
|
| 1875 | + public function set_status( $new_status, $note = '', $manual_update = false ) { |
|
| 1876 | + $old_status = $this->get_status(); |
|
| 1877 | 1877 | |
| 1878 | - $statuses = $this->get_all_statuses(); |
|
| 1878 | + $statuses = $this->get_all_statuses(); |
|
| 1879 | 1879 | |
| 1880 | - if ( isset( $statuses[ 'draft' ] ) ) { |
|
| 1881 | - unset( $statuses[ 'draft' ] ); |
|
| 1882 | - } |
|
| 1880 | + if ( isset( $statuses[ 'draft' ] ) ) { |
|
| 1881 | + unset( $statuses[ 'draft' ] ); |
|
| 1882 | + } |
|
| 1883 | 1883 | |
| 1884 | - $this->set_prop( 'status', $new_status ); |
|
| 1884 | + $this->set_prop( 'status', $new_status ); |
|
| 1885 | 1885 | |
| 1886 | - // If setting the status, ensure it's set to a valid status. |
|
| 1887 | - if ( true === $this->object_read ) { |
|
| 1886 | + // If setting the status, ensure it's set to a valid status. |
|
| 1887 | + if ( true === $this->object_read ) { |
|
| 1888 | 1888 | |
| 1889 | - // Only allow valid new status. |
|
| 1890 | - if ( ! array_key_exists( $new_status, $statuses ) ) { |
|
| 1891 | - $new_status = $this->get_default_status(); |
|
| 1892 | - } |
|
| 1889 | + // Only allow valid new status. |
|
| 1890 | + if ( ! array_key_exists( $new_status, $statuses ) ) { |
|
| 1891 | + $new_status = $this->get_default_status(); |
|
| 1892 | + } |
|
| 1893 | 1893 | |
| 1894 | - // If the old status is set but unknown (e.g. draft) assume its pending for action usage. |
|
| 1895 | - if ( $old_status && ! array_key_exists( $new_status, $statuses ) ) { |
|
| 1896 | - $old_status = $this->get_default_status(); |
|
| 1897 | - } |
|
| 1894 | + // If the old status is set but unknown (e.g. draft) assume its pending for action usage. |
|
| 1895 | + if ( $old_status && ! array_key_exists( $new_status, $statuses ) ) { |
|
| 1896 | + $old_status = $this->get_default_status(); |
|
| 1897 | + } |
|
| 1898 | 1898 | |
| 1899 | - // Paid - Renewal (i.e when duplicating a parent invoice ) |
|
| 1900 | - if ( $new_status == 'wpi-pending' && $old_status == 'publish' && ! $this->get_id() ) { |
|
| 1901 | - $old_status = 'wpi-pending'; |
|
| 1902 | - } |
|
| 1899 | + // Paid - Renewal (i.e when duplicating a parent invoice ) |
|
| 1900 | + if ( $new_status == 'wpi-pending' && $old_status == 'publish' && ! $this->get_id() ) { |
|
| 1901 | + $old_status = 'wpi-pending'; |
|
| 1902 | + } |
|
| 1903 | 1903 | |
| 1904 | - } |
|
| 1904 | + } |
|
| 1905 | 1905 | |
| 1906 | - if ( true === $this->object_read && $old_status !== $new_status ) { |
|
| 1907 | - $this->status_transition = array( |
|
| 1908 | - 'from' => ! empty( $this->status_transition['from'] ) ? $this->status_transition['from'] : $old_status, |
|
| 1909 | - 'to' => $new_status, |
|
| 1910 | - 'note' => $note, |
|
| 1911 | - 'manual' => (bool) $manual_update, |
|
| 1912 | - ); |
|
| 1906 | + if ( true === $this->object_read && $old_status !== $new_status ) { |
|
| 1907 | + $this->status_transition = array( |
|
| 1908 | + 'from' => ! empty( $this->status_transition['from'] ) ? $this->status_transition['from'] : $old_status, |
|
| 1909 | + 'to' => $new_status, |
|
| 1910 | + 'note' => $note, |
|
| 1911 | + 'manual' => (bool) $manual_update, |
|
| 1912 | + ); |
|
| 1913 | 1913 | |
| 1914 | - if ( $manual_update ) { |
|
| 1915 | - do_action( 'getpaid_' . $this->object_type .'_edit_status', $this->get_id(), $new_status ); |
|
| 1916 | - } |
|
| 1914 | + if ( $manual_update ) { |
|
| 1915 | + do_action( 'getpaid_' . $this->object_type .'_edit_status', $this->get_id(), $new_status ); |
|
| 1916 | + } |
|
| 1917 | 1917 | |
| 1918 | - $this->maybe_set_date_paid(); |
|
| 1918 | + $this->maybe_set_date_paid(); |
|
| 1919 | 1919 | |
| 1920 | - } |
|
| 1920 | + } |
|
| 1921 | 1921 | |
| 1922 | - return array( |
|
| 1923 | - 'from' => $old_status, |
|
| 1924 | - 'to' => $new_status, |
|
| 1925 | - ); |
|
| 1926 | - } |
|
| 1922 | + return array( |
|
| 1923 | + 'from' => $old_status, |
|
| 1924 | + 'to' => $new_status, |
|
| 1925 | + ); |
|
| 1926 | + } |
|
| 1927 | 1927 | |
| 1928 | - /** |
|
| 1929 | - * Maybe set date paid. |
|
| 1930 | - * |
|
| 1931 | - * Sets the date paid variable when transitioning to the payment complete |
|
| 1932 | - * order status. |
|
| 1933 | - * |
|
| 1934 | - * @since 1.0.19 |
|
| 1935 | - */ |
|
| 1936 | - public function maybe_set_date_paid() { |
|
| 1928 | + /** |
|
| 1929 | + * Maybe set date paid. |
|
| 1930 | + * |
|
| 1931 | + * Sets the date paid variable when transitioning to the payment complete |
|
| 1932 | + * order status. |
|
| 1933 | + * |
|
| 1934 | + * @since 1.0.19 |
|
| 1935 | + */ |
|
| 1936 | + public function maybe_set_date_paid() { |
|
| 1937 | 1937 | |
| 1938 | - if ( ! $this->get_date_completed( 'edit' ) && $this->is_paid() ) { |
|
| 1939 | - $this->set_date_completed( current_time( 'mysql' ) ); |
|
| 1940 | - } |
|
| 1941 | - } |
|
| 1938 | + if ( ! $this->get_date_completed( 'edit' ) && $this->is_paid() ) { |
|
| 1939 | + $this->set_date_completed( current_time( 'mysql' ) ); |
|
| 1940 | + } |
|
| 1941 | + } |
|
| 1942 | 1942 | |
| 1943 | 1943 | /** |
| 1944 | - * Set parent invoice ID. |
|
| 1945 | - * |
|
| 1946 | - * @since 1.0.19 |
|
| 1947 | - */ |
|
| 1948 | - public function set_parent_id( $value ) { |
|
| 1949 | - if ( $value && ( $value === $this->get_id() ) ) { |
|
| 1950 | - return; |
|
| 1951 | - } |
|
| 1952 | - $this->set_prop( 'parent_id', absint( $value ) ); |
|
| 1944 | + * Set parent invoice ID. |
|
| 1945 | + * |
|
| 1946 | + * @since 1.0.19 |
|
| 1947 | + */ |
|
| 1948 | + public function set_parent_id( $value ) { |
|
| 1949 | + if ( $value && ( $value === $this->get_id() ) ) { |
|
| 1950 | + return; |
|
| 1951 | + } |
|
| 1952 | + $this->set_prop( 'parent_id', absint( $value ) ); |
|
| 1953 | 1953 | } |
| 1954 | 1954 | |
| 1955 | 1955 | /** |
| 1956 | - * Set plugin version when the invoice was created. |
|
| 1957 | - * |
|
| 1958 | - * @since 1.0.19 |
|
| 1959 | - */ |
|
| 1960 | - public function set_version( $value ) { |
|
| 1961 | - $this->set_prop( 'version', $value ); |
|
| 1956 | + * Set plugin version when the invoice was created. |
|
| 1957 | + * |
|
| 1958 | + * @since 1.0.19 |
|
| 1959 | + */ |
|
| 1960 | + public function set_version( $value ) { |
|
| 1961 | + $this->set_prop( 'version', $value ); |
|
| 1962 | 1962 | } |
| 1963 | - |
|
| 1964 | - /** |
|
| 1965 | - * Set date when the invoice was created. |
|
| 1966 | - * |
|
| 1967 | - * @since 1.0.19 |
|
| 1968 | - * @param string $value Value to set. |
|
| 1963 | + |
|
| 1964 | + /** |
|
| 1965 | + * Set date when the invoice was created. |
|
| 1966 | + * |
|
| 1967 | + * @since 1.0.19 |
|
| 1968 | + * @param string $value Value to set. |
|
| 1969 | 1969 | * @return bool Whether or not the date was set. |
| 1970 | - */ |
|
| 1971 | - public function set_date_created( $value ) { |
|
| 1970 | + */ |
|
| 1971 | + public function set_date_created( $value ) { |
|
| 1972 | 1972 | $date = strtotime( $value ); |
| 1973 | 1973 | |
| 1974 | 1974 | if ( $date && $value !== '0000-00-00 00:00:00' ) { |
@@ -1976,19 +1976,19 @@ discard block |
||
| 1976 | 1976 | return true; |
| 1977 | 1977 | } |
| 1978 | 1978 | |
| 1979 | - $this->set_prop( 'date_created', '' ); |
|
| 1980 | - return false; |
|
| 1979 | + $this->set_prop( 'date_created', '' ); |
|
| 1980 | + return false; |
|
| 1981 | 1981 | |
| 1982 | 1982 | } |
| 1983 | 1983 | |
| 1984 | 1984 | /** |
| 1985 | - * Set date invoice due date. |
|
| 1986 | - * |
|
| 1987 | - * @since 1.0.19 |
|
| 1988 | - * @param string $value Value to set. |
|
| 1985 | + * Set date invoice due date. |
|
| 1986 | + * |
|
| 1987 | + * @since 1.0.19 |
|
| 1988 | + * @param string $value Value to set. |
|
| 1989 | 1989 | * @return bool Whether or not the date was set. |
| 1990 | - */ |
|
| 1991 | - public function set_due_date( $value ) { |
|
| 1990 | + */ |
|
| 1991 | + public function set_due_date( $value ) { |
|
| 1992 | 1992 | $date = strtotime( $value ); |
| 1993 | 1993 | |
| 1994 | 1994 | if ( $date && $value !== '0000-00-00 00:00:00' ) { |
@@ -1996,29 +1996,29 @@ discard block |
||
| 1996 | 1996 | return true; |
| 1997 | 1997 | } |
| 1998 | 1998 | |
| 1999 | - $this->set_prop( 'due_date', '' ); |
|
| 1999 | + $this->set_prop( 'due_date', '' ); |
|
| 2000 | 2000 | return false; |
| 2001 | 2001 | |
| 2002 | 2002 | } |
| 2003 | 2003 | |
| 2004 | 2004 | /** |
| 2005 | - * Alias of self::set_due_date(). |
|
| 2006 | - * |
|
| 2007 | - * @since 1.0.19 |
|
| 2008 | - * @param string $value New name. |
|
| 2009 | - */ |
|
| 2010 | - public function set_date_due( $value ) { |
|
| 2011 | - $this->set_due_date( $value ); |
|
| 2005 | + * Alias of self::set_due_date(). |
|
| 2006 | + * |
|
| 2007 | + * @since 1.0.19 |
|
| 2008 | + * @param string $value New name. |
|
| 2009 | + */ |
|
| 2010 | + public function set_date_due( $value ) { |
|
| 2011 | + $this->set_due_date( $value ); |
|
| 2012 | 2012 | } |
| 2013 | 2013 | |
| 2014 | 2014 | /** |
| 2015 | - * Set date invoice was completed. |
|
| 2016 | - * |
|
| 2017 | - * @since 1.0.19 |
|
| 2018 | - * @param string $value Value to set. |
|
| 2015 | + * Set date invoice was completed. |
|
| 2016 | + * |
|
| 2017 | + * @since 1.0.19 |
|
| 2018 | + * @param string $value Value to set. |
|
| 2019 | 2019 | * @return bool Whether or not the date was set. |
| 2020 | - */ |
|
| 2021 | - public function set_completed_date( $value ) { |
|
| 2020 | + */ |
|
| 2021 | + public function set_completed_date( $value ) { |
|
| 2022 | 2022 | $date = strtotime( $value ); |
| 2023 | 2023 | |
| 2024 | 2024 | if ( $date && $value !== '0000-00-00 00:00:00' ) { |
@@ -2026,29 +2026,29 @@ discard block |
||
| 2026 | 2026 | return true; |
| 2027 | 2027 | } |
| 2028 | 2028 | |
| 2029 | - $this->set_prop( 'completed_date', '' ); |
|
| 2029 | + $this->set_prop( 'completed_date', '' ); |
|
| 2030 | 2030 | return false; |
| 2031 | 2031 | |
| 2032 | 2032 | } |
| 2033 | 2033 | |
| 2034 | 2034 | /** |
| 2035 | - * Alias of self::set_completed_date(). |
|
| 2036 | - * |
|
| 2037 | - * @since 1.0.19 |
|
| 2038 | - * @param string $value New name. |
|
| 2039 | - */ |
|
| 2040 | - public function set_date_completed( $value ) { |
|
| 2041 | - $this->set_completed_date( $value ); |
|
| 2035 | + * Alias of self::set_completed_date(). |
|
| 2036 | + * |
|
| 2037 | + * @since 1.0.19 |
|
| 2038 | + * @param string $value New name. |
|
| 2039 | + */ |
|
| 2040 | + public function set_date_completed( $value ) { |
|
| 2041 | + $this->set_completed_date( $value ); |
|
| 2042 | 2042 | } |
| 2043 | 2043 | |
| 2044 | 2044 | /** |
| 2045 | - * Set date when the invoice was last modified. |
|
| 2046 | - * |
|
| 2047 | - * @since 1.0.19 |
|
| 2048 | - * @param string $value Value to set. |
|
| 2045 | + * Set date when the invoice was last modified. |
|
| 2046 | + * |
|
| 2047 | + * @since 1.0.19 |
|
| 2048 | + * @param string $value Value to set. |
|
| 2049 | 2049 | * @return bool Whether or not the date was set. |
| 2050 | - */ |
|
| 2051 | - public function set_date_modified( $value ) { |
|
| 2050 | + */ |
|
| 2051 | + public function set_date_modified( $value ) { |
|
| 2052 | 2052 | $date = strtotime( $value ); |
| 2053 | 2053 | |
| 2054 | 2054 | if ( $date && $value !== '0000-00-00 00:00:00' ) { |
@@ -2056,763 +2056,763 @@ discard block |
||
| 2056 | 2056 | return true; |
| 2057 | 2057 | } |
| 2058 | 2058 | |
| 2059 | - $this->set_prop( 'date_modified', '' ); |
|
| 2059 | + $this->set_prop( 'date_modified', '' ); |
|
| 2060 | 2060 | return false; |
| 2061 | 2061 | |
| 2062 | 2062 | } |
| 2063 | 2063 | |
| 2064 | 2064 | /** |
| 2065 | - * Set the invoice number. |
|
| 2066 | - * |
|
| 2067 | - * @since 1.0.19 |
|
| 2068 | - * @param string $value New number. |
|
| 2069 | - */ |
|
| 2070 | - public function set_number( $value ) { |
|
| 2065 | + * Set the invoice number. |
|
| 2066 | + * |
|
| 2067 | + * @since 1.0.19 |
|
| 2068 | + * @param string $value New number. |
|
| 2069 | + */ |
|
| 2070 | + public function set_number( $value ) { |
|
| 2071 | 2071 | $number = sanitize_text_field( $value ); |
| 2072 | - $this->set_prop( 'number', $number ); |
|
| 2072 | + $this->set_prop( 'number', $number ); |
|
| 2073 | 2073 | } |
| 2074 | 2074 | |
| 2075 | 2075 | /** |
| 2076 | - * Set the invoice type. |
|
| 2077 | - * |
|
| 2078 | - * @since 1.0.19 |
|
| 2079 | - * @param string $value Type. |
|
| 2080 | - */ |
|
| 2081 | - public function set_type( $value ) { |
|
| 2076 | + * Set the invoice type. |
|
| 2077 | + * |
|
| 2078 | + * @since 1.0.19 |
|
| 2079 | + * @param string $value Type. |
|
| 2080 | + */ |
|
| 2081 | + public function set_type( $value ) { |
|
| 2082 | 2082 | $type = sanitize_text_field( str_replace( 'wpi_', '', $value ) ); |
| 2083 | - $this->set_prop( 'type', $type ); |
|
| 2084 | - } |
|
| 2083 | + $this->set_prop( 'type', $type ); |
|
| 2084 | + } |
|
| 2085 | 2085 | |
| 2086 | 2086 | /** |
| 2087 | - * Set the invoice post type. |
|
| 2088 | - * |
|
| 2089 | - * @since 1.0.19 |
|
| 2090 | - * @param string $value Post type. |
|
| 2091 | - */ |
|
| 2092 | - public function set_post_type( $value ) { |
|
| 2087 | + * Set the invoice post type. |
|
| 2088 | + * |
|
| 2089 | + * @since 1.0.19 |
|
| 2090 | + * @param string $value Post type. |
|
| 2091 | + */ |
|
| 2092 | + public function set_post_type( $value ) { |
|
| 2093 | 2093 | if ( getpaid_is_invoice_post_type( $value ) ) { |
| 2094 | - $this->set_type( $value ); |
|
| 2094 | + $this->set_type( $value ); |
|
| 2095 | 2095 | $this->set_prop( 'post_type', $value ); |
| 2096 | 2096 | } |
| 2097 | 2097 | } |
| 2098 | 2098 | |
| 2099 | 2099 | /** |
| 2100 | - * Set the invoice key. |
|
| 2101 | - * |
|
| 2102 | - * @since 1.0.19 |
|
| 2103 | - * @param string $value New key. |
|
| 2104 | - */ |
|
| 2105 | - public function set_key( $value ) { |
|
| 2100 | + * Set the invoice key. |
|
| 2101 | + * |
|
| 2102 | + * @since 1.0.19 |
|
| 2103 | + * @param string $value New key. |
|
| 2104 | + */ |
|
| 2105 | + public function set_key( $value ) { |
|
| 2106 | 2106 | $key = sanitize_text_field( $value ); |
| 2107 | - $this->set_prop( 'key', $key ); |
|
| 2107 | + $this->set_prop( 'key', $key ); |
|
| 2108 | 2108 | } |
| 2109 | 2109 | |
| 2110 | 2110 | /** |
| 2111 | - * Set the invoice mode. |
|
| 2112 | - * |
|
| 2113 | - * @since 1.0.19 |
|
| 2114 | - * @param string $value mode. |
|
| 2115 | - */ |
|
| 2116 | - public function set_mode( $value ) { |
|
| 2111 | + * Set the invoice mode. |
|
| 2112 | + * |
|
| 2113 | + * @since 1.0.19 |
|
| 2114 | + * @param string $value mode. |
|
| 2115 | + */ |
|
| 2116 | + public function set_mode( $value ) { |
|
| 2117 | 2117 | if ( ! in_array( $value, array( 'live', 'test' ) ) ) { |
| 2118 | 2118 | $this->set_prop( 'value', $value ); |
| 2119 | 2119 | } |
| 2120 | 2120 | } |
| 2121 | 2121 | |
| 2122 | 2122 | /** |
| 2123 | - * Set the invoice path. |
|
| 2124 | - * |
|
| 2125 | - * @since 1.0.19 |
|
| 2126 | - * @param string $value path. |
|
| 2127 | - */ |
|
| 2128 | - public function set_path( $value ) { |
|
| 2123 | + * Set the invoice path. |
|
| 2124 | + * |
|
| 2125 | + * @since 1.0.19 |
|
| 2126 | + * @param string $value path. |
|
| 2127 | + */ |
|
| 2128 | + public function set_path( $value ) { |
|
| 2129 | 2129 | $this->set_prop( 'path', $value ); |
| 2130 | 2130 | } |
| 2131 | 2131 | |
| 2132 | 2132 | /** |
| 2133 | - * Set the invoice name. |
|
| 2134 | - * |
|
| 2135 | - * @since 1.0.19 |
|
| 2136 | - * @param string $value New name. |
|
| 2137 | - */ |
|
| 2138 | - public function set_name( $value ) { |
|
| 2133 | + * Set the invoice name. |
|
| 2134 | + * |
|
| 2135 | + * @since 1.0.19 |
|
| 2136 | + * @param string $value New name. |
|
| 2137 | + */ |
|
| 2138 | + public function set_name( $value ) { |
|
| 2139 | 2139 | $name = sanitize_text_field( $value ); |
| 2140 | - $this->set_prop( 'name', $name ); |
|
| 2140 | + $this->set_prop( 'name', $name ); |
|
| 2141 | 2141 | } |
| 2142 | 2142 | |
| 2143 | 2143 | /** |
| 2144 | - * Alias of self::set_name(). |
|
| 2145 | - * |
|
| 2146 | - * @since 1.0.19 |
|
| 2147 | - * @param string $value New name. |
|
| 2148 | - */ |
|
| 2149 | - public function set_title( $value ) { |
|
| 2150 | - $this->set_name( $value ); |
|
| 2144 | + * Alias of self::set_name(). |
|
| 2145 | + * |
|
| 2146 | + * @since 1.0.19 |
|
| 2147 | + * @param string $value New name. |
|
| 2148 | + */ |
|
| 2149 | + public function set_title( $value ) { |
|
| 2150 | + $this->set_name( $value ); |
|
| 2151 | 2151 | } |
| 2152 | 2152 | |
| 2153 | 2153 | /** |
| 2154 | - * Set the invoice description. |
|
| 2155 | - * |
|
| 2156 | - * @since 1.0.19 |
|
| 2157 | - * @param string $value New description. |
|
| 2158 | - */ |
|
| 2159 | - public function set_description( $value ) { |
|
| 2154 | + * Set the invoice description. |
|
| 2155 | + * |
|
| 2156 | + * @since 1.0.19 |
|
| 2157 | + * @param string $value New description. |
|
| 2158 | + */ |
|
| 2159 | + public function set_description( $value ) { |
|
| 2160 | 2160 | $description = wp_kses_post( $value ); |
| 2161 | - $this->set_prop( 'description', $description ); |
|
| 2161 | + $this->set_prop( 'description', $description ); |
|
| 2162 | + } |
|
| 2163 | + |
|
| 2164 | + /** |
|
| 2165 | + * Alias of self::set_description(). |
|
| 2166 | + * |
|
| 2167 | + * @since 1.0.19 |
|
| 2168 | + * @param string $value New description. |
|
| 2169 | + */ |
|
| 2170 | + public function set_excerpt( $value ) { |
|
| 2171 | + $this->set_description( $value ); |
|
| 2172 | + } |
|
| 2173 | + |
|
| 2174 | + /** |
|
| 2175 | + * Alias of self::set_description(). |
|
| 2176 | + * |
|
| 2177 | + * @since 1.0.19 |
|
| 2178 | + * @param string $value New description. |
|
| 2179 | + */ |
|
| 2180 | + public function set_summary( $value ) { |
|
| 2181 | + $this->set_description( $value ); |
|
| 2162 | 2182 | } |
| 2163 | 2183 | |
| 2164 | 2184 | /** |
| 2165 | - * Alias of self::set_description(). |
|
| 2166 | - * |
|
| 2167 | - * @since 1.0.19 |
|
| 2168 | - * @param string $value New description. |
|
| 2169 | - */ |
|
| 2170 | - public function set_excerpt( $value ) { |
|
| 2171 | - $this->set_description( $value ); |
|
| 2185 | + * Set the receiver of the invoice. |
|
| 2186 | + * |
|
| 2187 | + * @since 1.0.19 |
|
| 2188 | + * @param int $value New author. |
|
| 2189 | + */ |
|
| 2190 | + public function set_author( $value ) { |
|
| 2191 | + $user = get_user_by( 'id', (int) $value ); |
|
| 2192 | + |
|
| 2193 | + if ( $user && $user->ID ) { |
|
| 2194 | + $this->set_prop( 'author', $user->ID ); |
|
| 2195 | + $this->set_prop( 'email', $user->user_email ); |
|
| 2196 | + } |
|
| 2197 | + |
|
| 2172 | 2198 | } |
| 2173 | 2199 | |
| 2174 | 2200 | /** |
| 2175 | - * Alias of self::set_description(). |
|
| 2176 | - * |
|
| 2177 | - * @since 1.0.19 |
|
| 2178 | - * @param string $value New description. |
|
| 2179 | - */ |
|
| 2180 | - public function set_summary( $value ) { |
|
| 2181 | - $this->set_description( $value ); |
|
| 2201 | + * Alias of self::set_author(). |
|
| 2202 | + * |
|
| 2203 | + * @since 1.0.19 |
|
| 2204 | + * @param int $value New user id. |
|
| 2205 | + */ |
|
| 2206 | + public function set_user_id( $value ) { |
|
| 2207 | + $this->set_author( $value ); |
|
| 2182 | 2208 | } |
| 2183 | 2209 | |
| 2184 | 2210 | /** |
| 2185 | - * Set the receiver of the invoice. |
|
| 2186 | - * |
|
| 2187 | - * @since 1.0.19 |
|
| 2188 | - * @param int $value New author. |
|
| 2189 | - */ |
|
| 2190 | - public function set_author( $value ) { |
|
| 2191 | - $user = get_user_by( 'id', (int) $value ); |
|
| 2211 | + * Alias of self::set_author(). |
|
| 2212 | + * |
|
| 2213 | + * @since 1.0.19 |
|
| 2214 | + * @param int $value New user id. |
|
| 2215 | + */ |
|
| 2216 | + public function set_customer_id( $value ) { |
|
| 2217 | + $this->set_author( $value ); |
|
| 2218 | + } |
|
| 2192 | 2219 | |
| 2193 | - if ( $user && $user->ID ) { |
|
| 2194 | - $this->set_prop( 'author', $user->ID ); |
|
| 2195 | - $this->set_prop( 'email', $user->user_email ); |
|
| 2196 | - } |
|
| 2220 | + /** |
|
| 2221 | + * Set the customer's ip. |
|
| 2222 | + * |
|
| 2223 | + * @since 1.0.19 |
|
| 2224 | + * @param string $value ip address. |
|
| 2225 | + */ |
|
| 2226 | + public function set_ip( $value ) { |
|
| 2227 | + $this->set_prop( 'ip', $value ); |
|
| 2228 | + } |
|
| 2197 | 2229 | |
| 2230 | + /** |
|
| 2231 | + * Alias of self::set_ip(). |
|
| 2232 | + * |
|
| 2233 | + * @since 1.0.19 |
|
| 2234 | + * @param string $value ip address. |
|
| 2235 | + */ |
|
| 2236 | + public function set_user_ip( $value ) { |
|
| 2237 | + $this->set_ip( $value ); |
|
| 2198 | 2238 | } |
| 2199 | 2239 | |
| 2200 | 2240 | /** |
| 2201 | - * Alias of self::set_author(). |
|
| 2202 | - * |
|
| 2203 | - * @since 1.0.19 |
|
| 2204 | - * @param int $value New user id. |
|
| 2205 | - */ |
|
| 2206 | - public function set_user_id( $value ) { |
|
| 2207 | - $this->set_author( $value ); |
|
| 2241 | + * Set the customer's first name. |
|
| 2242 | + * |
|
| 2243 | + * @since 1.0.19 |
|
| 2244 | + * @param string $value first name. |
|
| 2245 | + */ |
|
| 2246 | + public function set_first_name( $value ) { |
|
| 2247 | + $this->set_prop( 'first_name', $value ); |
|
| 2208 | 2248 | } |
| 2209 | 2249 | |
| 2210 | 2250 | /** |
| 2211 | - * Alias of self::set_author(). |
|
| 2212 | - * |
|
| 2213 | - * @since 1.0.19 |
|
| 2214 | - * @param int $value New user id. |
|
| 2215 | - */ |
|
| 2216 | - public function set_customer_id( $value ) { |
|
| 2217 | - $this->set_author( $value ); |
|
| 2251 | + * Alias of self::set_first_name(). |
|
| 2252 | + * |
|
| 2253 | + * @since 1.0.19 |
|
| 2254 | + * @param string $value first name. |
|
| 2255 | + */ |
|
| 2256 | + public function set_user_first_name( $value ) { |
|
| 2257 | + $this->set_first_name( $value ); |
|
| 2218 | 2258 | } |
| 2219 | 2259 | |
| 2220 | 2260 | /** |
| 2221 | - * Set the customer's ip. |
|
| 2222 | - * |
|
| 2223 | - * @since 1.0.19 |
|
| 2224 | - * @param string $value ip address. |
|
| 2225 | - */ |
|
| 2226 | - public function set_ip( $value ) { |
|
| 2227 | - $this->set_prop( 'ip', $value ); |
|
| 2261 | + * Alias of self::set_first_name(). |
|
| 2262 | + * |
|
| 2263 | + * @since 1.0.19 |
|
| 2264 | + * @param string $value first name. |
|
| 2265 | + */ |
|
| 2266 | + public function set_customer_first_name( $value ) { |
|
| 2267 | + $this->set_first_name( $value ); |
|
| 2228 | 2268 | } |
| 2229 | 2269 | |
| 2230 | 2270 | /** |
| 2231 | - * Alias of self::set_ip(). |
|
| 2232 | - * |
|
| 2233 | - * @since 1.0.19 |
|
| 2234 | - * @param string $value ip address. |
|
| 2235 | - */ |
|
| 2236 | - public function set_user_ip( $value ) { |
|
| 2237 | - $this->set_ip( $value ); |
|
| 2271 | + * Set the customer's last name. |
|
| 2272 | + * |
|
| 2273 | + * @since 1.0.19 |
|
| 2274 | + * @param string $value last name. |
|
| 2275 | + */ |
|
| 2276 | + public function set_last_name( $value ) { |
|
| 2277 | + $this->set_prop( 'last_name', $value ); |
|
| 2238 | 2278 | } |
| 2239 | 2279 | |
| 2240 | 2280 | /** |
| 2241 | - * Set the customer's first name. |
|
| 2242 | - * |
|
| 2243 | - * @since 1.0.19 |
|
| 2244 | - * @param string $value first name. |
|
| 2245 | - */ |
|
| 2246 | - public function set_first_name( $value ) { |
|
| 2247 | - $this->set_prop( 'first_name', $value ); |
|
| 2281 | + * Alias of self::set_last_name(). |
|
| 2282 | + * |
|
| 2283 | + * @since 1.0.19 |
|
| 2284 | + * @param string $value last name. |
|
| 2285 | + */ |
|
| 2286 | + public function set_user_last_name( $value ) { |
|
| 2287 | + $this->set_last_name( $value ); |
|
| 2248 | 2288 | } |
| 2249 | 2289 | |
| 2250 | 2290 | /** |
| 2251 | - * Alias of self::set_first_name(). |
|
| 2252 | - * |
|
| 2253 | - * @since 1.0.19 |
|
| 2254 | - * @param string $value first name. |
|
| 2255 | - */ |
|
| 2256 | - public function set_user_first_name( $value ) { |
|
| 2257 | - $this->set_first_name( $value ); |
|
| 2291 | + * Alias of self::set_last_name(). |
|
| 2292 | + * |
|
| 2293 | + * @since 1.0.19 |
|
| 2294 | + * @param string $value last name. |
|
| 2295 | + */ |
|
| 2296 | + public function set_customer_last_name( $value ) { |
|
| 2297 | + $this->set_last_name( $value ); |
|
| 2258 | 2298 | } |
| 2259 | 2299 | |
| 2260 | 2300 | /** |
| 2261 | - * Alias of self::set_first_name(). |
|
| 2262 | - * |
|
| 2263 | - * @since 1.0.19 |
|
| 2264 | - * @param string $value first name. |
|
| 2265 | - */ |
|
| 2266 | - public function set_customer_first_name( $value ) { |
|
| 2267 | - $this->set_first_name( $value ); |
|
| 2301 | + * Set the customer's phone number. |
|
| 2302 | + * |
|
| 2303 | + * @since 1.0.19 |
|
| 2304 | + * @param string $value phone. |
|
| 2305 | + */ |
|
| 2306 | + public function set_phone( $value ) { |
|
| 2307 | + $this->set_prop( 'phone', $value ); |
|
| 2268 | 2308 | } |
| 2269 | 2309 | |
| 2270 | 2310 | /** |
| 2271 | - * Set the customer's last name. |
|
| 2272 | - * |
|
| 2273 | - * @since 1.0.19 |
|
| 2274 | - * @param string $value last name. |
|
| 2275 | - */ |
|
| 2276 | - public function set_last_name( $value ) { |
|
| 2277 | - $this->set_prop( 'last_name', $value ); |
|
| 2311 | + * Alias of self::set_phone(). |
|
| 2312 | + * |
|
| 2313 | + * @since 1.0.19 |
|
| 2314 | + * @param string $value phone. |
|
| 2315 | + */ |
|
| 2316 | + public function set_user_phone( $value ) { |
|
| 2317 | + $this->set_phone( $value ); |
|
| 2278 | 2318 | } |
| 2279 | 2319 | |
| 2280 | 2320 | /** |
| 2281 | - * Alias of self::set_last_name(). |
|
| 2282 | - * |
|
| 2283 | - * @since 1.0.19 |
|
| 2284 | - * @param string $value last name. |
|
| 2285 | - */ |
|
| 2286 | - public function set_user_last_name( $value ) { |
|
| 2287 | - $this->set_last_name( $value ); |
|
| 2321 | + * Alias of self::set_phone(). |
|
| 2322 | + * |
|
| 2323 | + * @since 1.0.19 |
|
| 2324 | + * @param string $value phone. |
|
| 2325 | + */ |
|
| 2326 | + public function set_customer_phone( $value ) { |
|
| 2327 | + $this->set_phone( $value ); |
|
| 2288 | 2328 | } |
| 2289 | 2329 | |
| 2290 | 2330 | /** |
| 2291 | - * Alias of self::set_last_name(). |
|
| 2292 | - * |
|
| 2293 | - * @since 1.0.19 |
|
| 2294 | - * @param string $value last name. |
|
| 2295 | - */ |
|
| 2296 | - public function set_customer_last_name( $value ) { |
|
| 2297 | - $this->set_last_name( $value ); |
|
| 2331 | + * Alias of self::set_phone(). |
|
| 2332 | + * |
|
| 2333 | + * @since 1.0.19 |
|
| 2334 | + * @param string $value phone. |
|
| 2335 | + */ |
|
| 2336 | + public function set_phone_number( $value ) { |
|
| 2337 | + $this->set_phone( $value ); |
|
| 2298 | 2338 | } |
| 2299 | 2339 | |
| 2300 | 2340 | /** |
| 2301 | - * Set the customer's phone number. |
|
| 2302 | - * |
|
| 2303 | - * @since 1.0.19 |
|
| 2304 | - * @param string $value phone. |
|
| 2305 | - */ |
|
| 2306 | - public function set_phone( $value ) { |
|
| 2307 | - $this->set_prop( 'phone', $value ); |
|
| 2341 | + * Set the customer's email address. |
|
| 2342 | + * |
|
| 2343 | + * @since 1.0.19 |
|
| 2344 | + * @param string $value email address. |
|
| 2345 | + */ |
|
| 2346 | + public function set_email( $value ) { |
|
| 2347 | + $this->set_prop( 'email', $value ); |
|
| 2308 | 2348 | } |
| 2309 | 2349 | |
| 2310 | 2350 | /** |
| 2311 | - * Alias of self::set_phone(). |
|
| 2312 | - * |
|
| 2313 | - * @since 1.0.19 |
|
| 2314 | - * @param string $value phone. |
|
| 2315 | - */ |
|
| 2316 | - public function set_user_phone( $value ) { |
|
| 2317 | - $this->set_phone( $value ); |
|
| 2351 | + * Alias of self::set_email(). |
|
| 2352 | + * |
|
| 2353 | + * @since 1.0.19 |
|
| 2354 | + * @param string $value email address. |
|
| 2355 | + */ |
|
| 2356 | + public function set_user_email( $value ) { |
|
| 2357 | + $this->set_email( $value ); |
|
| 2318 | 2358 | } |
| 2319 | 2359 | |
| 2320 | 2360 | /** |
| 2321 | - * Alias of self::set_phone(). |
|
| 2322 | - * |
|
| 2323 | - * @since 1.0.19 |
|
| 2324 | - * @param string $value phone. |
|
| 2325 | - */ |
|
| 2326 | - public function set_customer_phone( $value ) { |
|
| 2327 | - $this->set_phone( $value ); |
|
| 2361 | + * Alias of self::set_email(). |
|
| 2362 | + * |
|
| 2363 | + * @since 1.0.19 |
|
| 2364 | + * @param string $value email address. |
|
| 2365 | + */ |
|
| 2366 | + public function set_email_address( $value ) { |
|
| 2367 | + $this->set_email( $value ); |
|
| 2328 | 2368 | } |
| 2329 | 2369 | |
| 2330 | 2370 | /** |
| 2331 | - * Alias of self::set_phone(). |
|
| 2332 | - * |
|
| 2333 | - * @since 1.0.19 |
|
| 2334 | - * @param string $value phone. |
|
| 2335 | - */ |
|
| 2336 | - public function set_phone_number( $value ) { |
|
| 2337 | - $this->set_phone( $value ); |
|
| 2371 | + * Alias of self::set_email(). |
|
| 2372 | + * |
|
| 2373 | + * @since 1.0.19 |
|
| 2374 | + * @param string $value email address. |
|
| 2375 | + */ |
|
| 2376 | + public function set_customer_email( $value ) { |
|
| 2377 | + $this->set_email( $value ); |
|
| 2338 | 2378 | } |
| 2339 | 2379 | |
| 2340 | 2380 | /** |
| 2341 | - * Set the customer's email address. |
|
| 2342 | - * |
|
| 2343 | - * @since 1.0.19 |
|
| 2344 | - * @param string $value email address. |
|
| 2345 | - */ |
|
| 2346 | - public function set_email( $value ) { |
|
| 2347 | - $this->set_prop( 'email', $value ); |
|
| 2381 | + * Set the customer's country. |
|
| 2382 | + * |
|
| 2383 | + * @since 1.0.19 |
|
| 2384 | + * @param string $value country. |
|
| 2385 | + */ |
|
| 2386 | + public function set_country( $value ) { |
|
| 2387 | + $this->set_prop( 'country', $value ); |
|
| 2348 | 2388 | } |
| 2349 | 2389 | |
| 2350 | 2390 | /** |
| 2351 | - * Alias of self::set_email(). |
|
| 2352 | - * |
|
| 2353 | - * @since 1.0.19 |
|
| 2354 | - * @param string $value email address. |
|
| 2355 | - */ |
|
| 2356 | - public function set_user_email( $value ) { |
|
| 2357 | - $this->set_email( $value ); |
|
| 2391 | + * Alias of self::set_country(). |
|
| 2392 | + * |
|
| 2393 | + * @since 1.0.19 |
|
| 2394 | + * @param string $value country. |
|
| 2395 | + */ |
|
| 2396 | + public function set_user_country( $value ) { |
|
| 2397 | + $this->set_country( $value ); |
|
| 2358 | 2398 | } |
| 2359 | 2399 | |
| 2360 | 2400 | /** |
| 2361 | - * Alias of self::set_email(). |
|
| 2362 | - * |
|
| 2363 | - * @since 1.0.19 |
|
| 2364 | - * @param string $value email address. |
|
| 2365 | - */ |
|
| 2366 | - public function set_email_address( $value ) { |
|
| 2367 | - $this->set_email( $value ); |
|
| 2401 | + * Alias of self::set_country(). |
|
| 2402 | + * |
|
| 2403 | + * @since 1.0.19 |
|
| 2404 | + * @param string $value country. |
|
| 2405 | + */ |
|
| 2406 | + public function set_customer_country( $value ) { |
|
| 2407 | + $this->set_country( $value ); |
|
| 2368 | 2408 | } |
| 2369 | 2409 | |
| 2370 | 2410 | /** |
| 2371 | - * Alias of self::set_email(). |
|
| 2372 | - * |
|
| 2373 | - * @since 1.0.19 |
|
| 2374 | - * @param string $value email address. |
|
| 2375 | - */ |
|
| 2376 | - public function set_customer_email( $value ) { |
|
| 2377 | - $this->set_email( $value ); |
|
| 2411 | + * Set the customer's state. |
|
| 2412 | + * |
|
| 2413 | + * @since 1.0.19 |
|
| 2414 | + * @param string $value state. |
|
| 2415 | + */ |
|
| 2416 | + public function set_state( $value ) { |
|
| 2417 | + $this->set_prop( 'state', $value ); |
|
| 2378 | 2418 | } |
| 2379 | 2419 | |
| 2380 | 2420 | /** |
| 2381 | - * Set the customer's country. |
|
| 2382 | - * |
|
| 2383 | - * @since 1.0.19 |
|
| 2384 | - * @param string $value country. |
|
| 2385 | - */ |
|
| 2386 | - public function set_country( $value ) { |
|
| 2387 | - $this->set_prop( 'country', $value ); |
|
| 2421 | + * Alias of self::set_state(). |
|
| 2422 | + * |
|
| 2423 | + * @since 1.0.19 |
|
| 2424 | + * @param string $value state. |
|
| 2425 | + */ |
|
| 2426 | + public function set_user_state( $value ) { |
|
| 2427 | + $this->set_state( $value ); |
|
| 2388 | 2428 | } |
| 2389 | 2429 | |
| 2390 | 2430 | /** |
| 2391 | - * Alias of self::set_country(). |
|
| 2392 | - * |
|
| 2393 | - * @since 1.0.19 |
|
| 2394 | - * @param string $value country. |
|
| 2395 | - */ |
|
| 2396 | - public function set_user_country( $value ) { |
|
| 2397 | - $this->set_country( $value ); |
|
| 2431 | + * Alias of self::set_state(). |
|
| 2432 | + * |
|
| 2433 | + * @since 1.0.19 |
|
| 2434 | + * @param string $value state. |
|
| 2435 | + */ |
|
| 2436 | + public function set_customer_state( $value ) { |
|
| 2437 | + $this->set_state( $value ); |
|
| 2398 | 2438 | } |
| 2399 | 2439 | |
| 2400 | 2440 | /** |
| 2401 | - * Alias of self::set_country(). |
|
| 2402 | - * |
|
| 2403 | - * @since 1.0.19 |
|
| 2404 | - * @param string $value country. |
|
| 2405 | - */ |
|
| 2406 | - public function set_customer_country( $value ) { |
|
| 2407 | - $this->set_country( $value ); |
|
| 2441 | + * Set the customer's city. |
|
| 2442 | + * |
|
| 2443 | + * @since 1.0.19 |
|
| 2444 | + * @param string $value city. |
|
| 2445 | + */ |
|
| 2446 | + public function set_city( $value ) { |
|
| 2447 | + $this->set_prop( 'city', $value ); |
|
| 2408 | 2448 | } |
| 2409 | 2449 | |
| 2410 | 2450 | /** |
| 2411 | - * Set the customer's state. |
|
| 2412 | - * |
|
| 2413 | - * @since 1.0.19 |
|
| 2414 | - * @param string $value state. |
|
| 2415 | - */ |
|
| 2416 | - public function set_state( $value ) { |
|
| 2417 | - $this->set_prop( 'state', $value ); |
|
| 2451 | + * Alias of self::set_city(). |
|
| 2452 | + * |
|
| 2453 | + * @since 1.0.19 |
|
| 2454 | + * @param string $value city. |
|
| 2455 | + */ |
|
| 2456 | + public function set_user_city( $value ) { |
|
| 2457 | + $this->set_city( $value ); |
|
| 2418 | 2458 | } |
| 2419 | 2459 | |
| 2420 | 2460 | /** |
| 2421 | - * Alias of self::set_state(). |
|
| 2422 | - * |
|
| 2423 | - * @since 1.0.19 |
|
| 2424 | - * @param string $value state. |
|
| 2425 | - */ |
|
| 2426 | - public function set_user_state( $value ) { |
|
| 2427 | - $this->set_state( $value ); |
|
| 2461 | + * Alias of self::set_city(). |
|
| 2462 | + * |
|
| 2463 | + * @since 1.0.19 |
|
| 2464 | + * @param string $value city. |
|
| 2465 | + */ |
|
| 2466 | + public function set_customer_city( $value ) { |
|
| 2467 | + $this->set_city( $value ); |
|
| 2428 | 2468 | } |
| 2429 | 2469 | |
| 2430 | 2470 | /** |
| 2431 | - * Alias of self::set_state(). |
|
| 2432 | - * |
|
| 2433 | - * @since 1.0.19 |
|
| 2434 | - * @param string $value state. |
|
| 2435 | - */ |
|
| 2436 | - public function set_customer_state( $value ) { |
|
| 2437 | - $this->set_state( $value ); |
|
| 2471 | + * Set the customer's zip code. |
|
| 2472 | + * |
|
| 2473 | + * @since 1.0.19 |
|
| 2474 | + * @param string $value zip. |
|
| 2475 | + */ |
|
| 2476 | + public function set_zip( $value ) { |
|
| 2477 | + $this->set_prop( 'zip', $value ); |
|
| 2438 | 2478 | } |
| 2439 | 2479 | |
| 2440 | 2480 | /** |
| 2441 | - * Set the customer's city. |
|
| 2442 | - * |
|
| 2443 | - * @since 1.0.19 |
|
| 2444 | - * @param string $value city. |
|
| 2445 | - */ |
|
| 2446 | - public function set_city( $value ) { |
|
| 2447 | - $this->set_prop( 'city', $value ); |
|
| 2481 | + * Alias of self::set_zip(). |
|
| 2482 | + * |
|
| 2483 | + * @since 1.0.19 |
|
| 2484 | + * @param string $value zip. |
|
| 2485 | + */ |
|
| 2486 | + public function set_user_zip( $value ) { |
|
| 2487 | + $this->set_zip( $value ); |
|
| 2448 | 2488 | } |
| 2449 | 2489 | |
| 2450 | 2490 | /** |
| 2451 | - * Alias of self::set_city(). |
|
| 2452 | - * |
|
| 2453 | - * @since 1.0.19 |
|
| 2454 | - * @param string $value city. |
|
| 2455 | - */ |
|
| 2456 | - public function set_user_city( $value ) { |
|
| 2457 | - $this->set_city( $value ); |
|
| 2491 | + * Alias of self::set_zip(). |
|
| 2492 | + * |
|
| 2493 | + * @since 1.0.19 |
|
| 2494 | + * @param string $value zip. |
|
| 2495 | + */ |
|
| 2496 | + public function set_customer_zip( $value ) { |
|
| 2497 | + $this->set_zip( $value ); |
|
| 2458 | 2498 | } |
| 2459 | 2499 | |
| 2460 | 2500 | /** |
| 2461 | - * Alias of self::set_city(). |
|
| 2462 | - * |
|
| 2463 | - * @since 1.0.19 |
|
| 2464 | - * @param string $value city. |
|
| 2465 | - */ |
|
| 2466 | - public function set_customer_city( $value ) { |
|
| 2467 | - $this->set_city( $value ); |
|
| 2501 | + * Set the customer's company. |
|
| 2502 | + * |
|
| 2503 | + * @since 1.0.19 |
|
| 2504 | + * @param string $value company. |
|
| 2505 | + */ |
|
| 2506 | + public function set_company( $value ) { |
|
| 2507 | + $this->set_prop( 'company', $value ); |
|
| 2468 | 2508 | } |
| 2469 | 2509 | |
| 2470 | 2510 | /** |
| 2471 | - * Set the customer's zip code. |
|
| 2472 | - * |
|
| 2473 | - * @since 1.0.19 |
|
| 2474 | - * @param string $value zip. |
|
| 2475 | - */ |
|
| 2476 | - public function set_zip( $value ) { |
|
| 2477 | - $this->set_prop( 'zip', $value ); |
|
| 2511 | + * Alias of self::set_company(). |
|
| 2512 | + * |
|
| 2513 | + * @since 1.0.19 |
|
| 2514 | + * @param string $value company. |
|
| 2515 | + */ |
|
| 2516 | + public function set_user_company( $value ) { |
|
| 2517 | + $this->set_company( $value ); |
|
| 2478 | 2518 | } |
| 2479 | 2519 | |
| 2480 | 2520 | /** |
| 2481 | - * Alias of self::set_zip(). |
|
| 2482 | - * |
|
| 2483 | - * @since 1.0.19 |
|
| 2484 | - * @param string $value zip. |
|
| 2485 | - */ |
|
| 2486 | - public function set_user_zip( $value ) { |
|
| 2487 | - $this->set_zip( $value ); |
|
| 2521 | + * Alias of self::set_company(). |
|
| 2522 | + * |
|
| 2523 | + * @since 1.0.19 |
|
| 2524 | + * @param string $value company. |
|
| 2525 | + */ |
|
| 2526 | + public function set_customer_company( $value ) { |
|
| 2527 | + $this->set_company( $value ); |
|
| 2488 | 2528 | } |
| 2489 | 2529 | |
| 2490 | 2530 | /** |
| 2491 | - * Alias of self::set_zip(). |
|
| 2492 | - * |
|
| 2493 | - * @since 1.0.19 |
|
| 2494 | - * @param string $value zip. |
|
| 2495 | - */ |
|
| 2496 | - public function set_customer_zip( $value ) { |
|
| 2497 | - $this->set_zip( $value ); |
|
| 2531 | + * Set the customer's var number. |
|
| 2532 | + * |
|
| 2533 | + * @since 1.0.19 |
|
| 2534 | + * @param string $value var number. |
|
| 2535 | + */ |
|
| 2536 | + public function set_vat_number( $value ) { |
|
| 2537 | + $this->set_prop( 'vat_number', $value ); |
|
| 2498 | 2538 | } |
| 2499 | 2539 | |
| 2500 | 2540 | /** |
| 2501 | - * Set the customer's company. |
|
| 2502 | - * |
|
| 2503 | - * @since 1.0.19 |
|
| 2504 | - * @param string $value company. |
|
| 2505 | - */ |
|
| 2506 | - public function set_company( $value ) { |
|
| 2507 | - $this->set_prop( 'company', $value ); |
|
| 2541 | + * Alias of self::set_vat_number(). |
|
| 2542 | + * |
|
| 2543 | + * @since 1.0.19 |
|
| 2544 | + * @param string $value var number. |
|
| 2545 | + */ |
|
| 2546 | + public function set_user_vat_number( $value ) { |
|
| 2547 | + $this->set_vat_number( $value ); |
|
| 2508 | 2548 | } |
| 2509 | 2549 | |
| 2510 | 2550 | /** |
| 2511 | - * Alias of self::set_company(). |
|
| 2512 | - * |
|
| 2513 | - * @since 1.0.19 |
|
| 2514 | - * @param string $value company. |
|
| 2515 | - */ |
|
| 2516 | - public function set_user_company( $value ) { |
|
| 2517 | - $this->set_company( $value ); |
|
| 2551 | + * Alias of self::set_vat_number(). |
|
| 2552 | + * |
|
| 2553 | + * @since 1.0.19 |
|
| 2554 | + * @param string $value var number. |
|
| 2555 | + */ |
|
| 2556 | + public function set_customer_vat_number( $value ) { |
|
| 2557 | + $this->set_vat_number( $value ); |
|
| 2518 | 2558 | } |
| 2519 | 2559 | |
| 2520 | 2560 | /** |
| 2521 | - * Alias of self::set_company(). |
|
| 2522 | - * |
|
| 2523 | - * @since 1.0.19 |
|
| 2524 | - * @param string $value company. |
|
| 2525 | - */ |
|
| 2526 | - public function set_customer_company( $value ) { |
|
| 2527 | - $this->set_company( $value ); |
|
| 2561 | + * Set the customer's vat rate. |
|
| 2562 | + * |
|
| 2563 | + * @since 1.0.19 |
|
| 2564 | + * @param string $value var rate. |
|
| 2565 | + */ |
|
| 2566 | + public function set_vat_rate( $value ) { |
|
| 2567 | + $this->set_prop( 'vat_rate', $value ); |
|
| 2528 | 2568 | } |
| 2529 | 2569 | |
| 2530 | 2570 | /** |
| 2531 | - * Set the customer's var number. |
|
| 2532 | - * |
|
| 2533 | - * @since 1.0.19 |
|
| 2534 | - * @param string $value var number. |
|
| 2535 | - */ |
|
| 2536 | - public function set_vat_number( $value ) { |
|
| 2537 | - $this->set_prop( 'vat_number', $value ); |
|
| 2571 | + * Alias of self::set_vat_rate(). |
|
| 2572 | + * |
|
| 2573 | + * @since 1.0.19 |
|
| 2574 | + * @param string $value var number. |
|
| 2575 | + */ |
|
| 2576 | + public function set_user_vat_rate( $value ) { |
|
| 2577 | + $this->set_vat_rate( $value ); |
|
| 2538 | 2578 | } |
| 2539 | 2579 | |
| 2540 | 2580 | /** |
| 2541 | - * Alias of self::set_vat_number(). |
|
| 2542 | - * |
|
| 2543 | - * @since 1.0.19 |
|
| 2544 | - * @param string $value var number. |
|
| 2545 | - */ |
|
| 2546 | - public function set_user_vat_number( $value ) { |
|
| 2547 | - $this->set_vat_number( $value ); |
|
| 2581 | + * Alias of self::set_vat_rate(). |
|
| 2582 | + * |
|
| 2583 | + * @since 1.0.19 |
|
| 2584 | + * @param string $value var number. |
|
| 2585 | + */ |
|
| 2586 | + public function set_customer_vat_rate( $value ) { |
|
| 2587 | + $this->set_vat_rate( $value ); |
|
| 2548 | 2588 | } |
| 2549 | 2589 | |
| 2550 | 2590 | /** |
| 2551 | - * Alias of self::set_vat_number(). |
|
| 2552 | - * |
|
| 2553 | - * @since 1.0.19 |
|
| 2554 | - * @param string $value var number. |
|
| 2555 | - */ |
|
| 2556 | - public function set_customer_vat_number( $value ) { |
|
| 2557 | - $this->set_vat_number( $value ); |
|
| 2591 | + * Set the customer's address. |
|
| 2592 | + * |
|
| 2593 | + * @since 1.0.19 |
|
| 2594 | + * @param string $value address. |
|
| 2595 | + */ |
|
| 2596 | + public function set_address( $value ) { |
|
| 2597 | + $this->set_prop( 'address', $value ); |
|
| 2558 | 2598 | } |
| 2559 | 2599 | |
| 2560 | 2600 | /** |
| 2561 | - * Set the customer's vat rate. |
|
| 2562 | - * |
|
| 2563 | - * @since 1.0.19 |
|
| 2564 | - * @param string $value var rate. |
|
| 2565 | - */ |
|
| 2566 | - public function set_vat_rate( $value ) { |
|
| 2567 | - $this->set_prop( 'vat_rate', $value ); |
|
| 2601 | + * Alias of self::set_address(). |
|
| 2602 | + * |
|
| 2603 | + * @since 1.0.19 |
|
| 2604 | + * @param string $value address. |
|
| 2605 | + */ |
|
| 2606 | + public function set_user_address( $value ) { |
|
| 2607 | + $this->set_address( $value ); |
|
| 2568 | 2608 | } |
| 2569 | 2609 | |
| 2570 | 2610 | /** |
| 2571 | - * Alias of self::set_vat_rate(). |
|
| 2572 | - * |
|
| 2573 | - * @since 1.0.19 |
|
| 2574 | - * @param string $value var number. |
|
| 2575 | - */ |
|
| 2576 | - public function set_user_vat_rate( $value ) { |
|
| 2577 | - $this->set_vat_rate( $value ); |
|
| 2611 | + * Alias of self::set_address(). |
|
| 2612 | + * |
|
| 2613 | + * @since 1.0.19 |
|
| 2614 | + * @param string $value address. |
|
| 2615 | + */ |
|
| 2616 | + public function set_customer_address( $value ) { |
|
| 2617 | + $this->set_address( $value ); |
|
| 2578 | 2618 | } |
| 2579 | 2619 | |
| 2580 | 2620 | /** |
| 2581 | - * Alias of self::set_vat_rate(). |
|
| 2582 | - * |
|
| 2583 | - * @since 1.0.19 |
|
| 2584 | - * @param string $value var number. |
|
| 2585 | - */ |
|
| 2586 | - public function set_customer_vat_rate( $value ) { |
|
| 2587 | - $this->set_vat_rate( $value ); |
|
| 2621 | + * Set whether the customer has viewed the invoice or not. |
|
| 2622 | + * |
|
| 2623 | + * @since 1.0.19 |
|
| 2624 | + * @param int|bool $value confirmed. |
|
| 2625 | + */ |
|
| 2626 | + public function set_is_viewed( $value ) { |
|
| 2627 | + $this->set_prop( 'is_viewed', $value ); |
|
| 2588 | 2628 | } |
| 2589 | 2629 | |
| 2590 | 2630 | /** |
| 2591 | - * Set the customer's address. |
|
| 2592 | - * |
|
| 2593 | - * @since 1.0.19 |
|
| 2594 | - * @param string $value address. |
|
| 2595 | - */ |
|
| 2596 | - public function set_address( $value ) { |
|
| 2597 | - $this->set_prop( 'address', $value ); |
|
| 2631 | + * Set extra email recipients. |
|
| 2632 | + * |
|
| 2633 | + * @since 1.0.19 |
|
| 2634 | + * @param string $value email recipients. |
|
| 2635 | + */ |
|
| 2636 | + public function set_email_cc( $value ) { |
|
| 2637 | + $this->set_prop( 'email_cc', $value ); |
|
| 2598 | 2638 | } |
| 2599 | 2639 | |
| 2600 | 2640 | /** |
| 2601 | - * Alias of self::set_address(). |
|
| 2602 | - * |
|
| 2603 | - * @since 1.0.19 |
|
| 2604 | - * @param string $value address. |
|
| 2605 | - */ |
|
| 2606 | - public function set_user_address( $value ) { |
|
| 2607 | - $this->set_address( $value ); |
|
| 2641 | + * Set the invoice template. |
|
| 2642 | + * |
|
| 2643 | + * @since 1.0.19 |
|
| 2644 | + * @param string $value template. |
|
| 2645 | + */ |
|
| 2646 | + public function set_template( $value ) { |
|
| 2647 | + if ( in_array( $value, array( 'quantity', 'hours', 'amount' ) ) ) { |
|
| 2648 | + $this->set_prop( 'template', $value ); |
|
| 2649 | + } |
|
| 2608 | 2650 | } |
| 2609 | 2651 | |
| 2610 | 2652 | /** |
| 2611 | - * Alias of self::set_address(). |
|
| 2612 | - * |
|
| 2613 | - * @since 1.0.19 |
|
| 2614 | - * @param string $value address. |
|
| 2615 | - */ |
|
| 2616 | - public function set_customer_address( $value ) { |
|
| 2617 | - $this->set_address( $value ); |
|
| 2653 | + * Set the invoice source. |
|
| 2654 | + * |
|
| 2655 | + * @since 1.0.19 |
|
| 2656 | + * @param string $value email recipients. |
|
| 2657 | + */ |
|
| 2658 | + public function created_via( $value ) { |
|
| 2659 | + $this->set_prop( 'created_via', sanitize_text_field( $value ) ); |
|
| 2618 | 2660 | } |
| 2619 | 2661 | |
| 2620 | 2662 | /** |
| 2621 | - * Set whether the customer has viewed the invoice or not. |
|
| 2622 | - * |
|
| 2623 | - * @since 1.0.19 |
|
| 2624 | - * @param int|bool $value confirmed. |
|
| 2625 | - */ |
|
| 2626 | - public function set_is_viewed( $value ) { |
|
| 2627 | - $this->set_prop( 'is_viewed', $value ); |
|
| 2628 | - } |
|
| 2629 | - |
|
| 2630 | - /** |
|
| 2631 | - * Set extra email recipients. |
|
| 2632 | - * |
|
| 2633 | - * @since 1.0.19 |
|
| 2634 | - * @param string $value email recipients. |
|
| 2635 | - */ |
|
| 2636 | - public function set_email_cc( $value ) { |
|
| 2637 | - $this->set_prop( 'email_cc', $value ); |
|
| 2638 | - } |
|
| 2639 | - |
|
| 2640 | - /** |
|
| 2641 | - * Set the invoice template. |
|
| 2642 | - * |
|
| 2643 | - * @since 1.0.19 |
|
| 2644 | - * @param string $value template. |
|
| 2645 | - */ |
|
| 2646 | - public function set_template( $value ) { |
|
| 2647 | - if ( in_array( $value, array( 'quantity', 'hours', 'amount' ) ) ) { |
|
| 2648 | - $this->set_prop( 'template', $value ); |
|
| 2649 | - } |
|
| 2650 | - } |
|
| 2651 | - |
|
| 2652 | - /** |
|
| 2653 | - * Set the invoice source. |
|
| 2654 | - * |
|
| 2655 | - * @since 1.0.19 |
|
| 2656 | - * @param string $value email recipients. |
|
| 2657 | - */ |
|
| 2658 | - public function created_via( $value ) { |
|
| 2659 | - $this->set_prop( 'created_via', sanitize_text_field( $value ) ); |
|
| 2660 | - } |
|
| 2661 | - |
|
| 2662 | - /** |
|
| 2663 | - * Set the customer's address confirmed status. |
|
| 2664 | - * |
|
| 2665 | - * @since 1.0.19 |
|
| 2666 | - * @param int|bool $value confirmed. |
|
| 2667 | - */ |
|
| 2668 | - public function set_address_confirmed( $value ) { |
|
| 2669 | - $this->set_prop( 'address_confirmed', $value ); |
|
| 2663 | + * Set the customer's address confirmed status. |
|
| 2664 | + * |
|
| 2665 | + * @since 1.0.19 |
|
| 2666 | + * @param int|bool $value confirmed. |
|
| 2667 | + */ |
|
| 2668 | + public function set_address_confirmed( $value ) { |
|
| 2669 | + $this->set_prop( 'address_confirmed', $value ); |
|
| 2670 | 2670 | } |
| 2671 | 2671 | |
| 2672 | 2672 | /** |
| 2673 | - * Alias of self::set_address_confirmed(). |
|
| 2674 | - * |
|
| 2675 | - * @since 1.0.19 |
|
| 2676 | - * @param int|bool $value confirmed. |
|
| 2677 | - */ |
|
| 2678 | - public function set_user_address_confirmed( $value ) { |
|
| 2679 | - $this->set_address_confirmed( $value ); |
|
| 2673 | + * Alias of self::set_address_confirmed(). |
|
| 2674 | + * |
|
| 2675 | + * @since 1.0.19 |
|
| 2676 | + * @param int|bool $value confirmed. |
|
| 2677 | + */ |
|
| 2678 | + public function set_user_address_confirmed( $value ) { |
|
| 2679 | + $this->set_address_confirmed( $value ); |
|
| 2680 | 2680 | } |
| 2681 | 2681 | |
| 2682 | 2682 | /** |
| 2683 | - * Alias of self::set_address_confirmed(). |
|
| 2684 | - * |
|
| 2685 | - * @since 1.0.19 |
|
| 2686 | - * @param int|bool $value confirmed. |
|
| 2687 | - */ |
|
| 2688 | - public function set_customer_address_confirmed( $value ) { |
|
| 2689 | - $this->set_address_confirmed( $value ); |
|
| 2683 | + * Alias of self::set_address_confirmed(). |
|
| 2684 | + * |
|
| 2685 | + * @since 1.0.19 |
|
| 2686 | + * @param int|bool $value confirmed. |
|
| 2687 | + */ |
|
| 2688 | + public function set_customer_address_confirmed( $value ) { |
|
| 2689 | + $this->set_address_confirmed( $value ); |
|
| 2690 | 2690 | } |
| 2691 | 2691 | |
| 2692 | 2692 | /** |
| 2693 | - * Set the invoice sub total. |
|
| 2694 | - * |
|
| 2695 | - * @since 1.0.19 |
|
| 2696 | - * @param float $value sub total. |
|
| 2697 | - */ |
|
| 2698 | - public function set_subtotal( $value ) { |
|
| 2699 | - $this->set_prop( 'subtotal', $value ); |
|
| 2693 | + * Set the invoice sub total. |
|
| 2694 | + * |
|
| 2695 | + * @since 1.0.19 |
|
| 2696 | + * @param float $value sub total. |
|
| 2697 | + */ |
|
| 2698 | + public function set_subtotal( $value ) { |
|
| 2699 | + $this->set_prop( 'subtotal', $value ); |
|
| 2700 | 2700 | } |
| 2701 | 2701 | |
| 2702 | 2702 | /** |
| 2703 | - * Set the invoice discount amount. |
|
| 2704 | - * |
|
| 2705 | - * @since 1.0.19 |
|
| 2706 | - * @param float $value discount total. |
|
| 2707 | - */ |
|
| 2708 | - public function set_total_discount( $value ) { |
|
| 2709 | - $this->set_prop( 'total_discount', $value ); |
|
| 2703 | + * Set the invoice discount amount. |
|
| 2704 | + * |
|
| 2705 | + * @since 1.0.19 |
|
| 2706 | + * @param float $value discount total. |
|
| 2707 | + */ |
|
| 2708 | + public function set_total_discount( $value ) { |
|
| 2709 | + $this->set_prop( 'total_discount', $value ); |
|
| 2710 | 2710 | } |
| 2711 | 2711 | |
| 2712 | 2712 | /** |
| 2713 | - * Alias of self::set_total_discount(). |
|
| 2714 | - * |
|
| 2715 | - * @since 1.0.19 |
|
| 2716 | - * @param float $value discount total. |
|
| 2717 | - */ |
|
| 2718 | - public function set_discount( $value ) { |
|
| 2719 | - $this->set_total_discount( $value ); |
|
| 2713 | + * Alias of self::set_total_discount(). |
|
| 2714 | + * |
|
| 2715 | + * @since 1.0.19 |
|
| 2716 | + * @param float $value discount total. |
|
| 2717 | + */ |
|
| 2718 | + public function set_discount( $value ) { |
|
| 2719 | + $this->set_total_discount( $value ); |
|
| 2720 | 2720 | } |
| 2721 | 2721 | |
| 2722 | 2722 | /** |
| 2723 | - * Set the invoice tax amount. |
|
| 2724 | - * |
|
| 2725 | - * @since 1.0.19 |
|
| 2726 | - * @param float $value tax total. |
|
| 2727 | - */ |
|
| 2728 | - public function set_total_tax( $value ) { |
|
| 2729 | - $this->set_prop( 'total_tax', $value ); |
|
| 2723 | + * Set the invoice tax amount. |
|
| 2724 | + * |
|
| 2725 | + * @since 1.0.19 |
|
| 2726 | + * @param float $value tax total. |
|
| 2727 | + */ |
|
| 2728 | + public function set_total_tax( $value ) { |
|
| 2729 | + $this->set_prop( 'total_tax', $value ); |
|
| 2730 | 2730 | } |
| 2731 | 2731 | |
| 2732 | 2732 | /** |
| 2733 | - * Alias of self::set_total_tax(). |
|
| 2734 | - * |
|
| 2735 | - * @since 1.0.19 |
|
| 2736 | - * @param float $value tax total. |
|
| 2737 | - */ |
|
| 2738 | - public function set_tax_total( $value ) { |
|
| 2739 | - $this->set_total_tax( $value ); |
|
| 2733 | + * Alias of self::set_total_tax(). |
|
| 2734 | + * |
|
| 2735 | + * @since 1.0.19 |
|
| 2736 | + * @param float $value tax total. |
|
| 2737 | + */ |
|
| 2738 | + public function set_tax_total( $value ) { |
|
| 2739 | + $this->set_total_tax( $value ); |
|
| 2740 | 2740 | } |
| 2741 | 2741 | |
| 2742 | 2742 | /** |
| 2743 | - * Set the invoice fees amount. |
|
| 2744 | - * |
|
| 2745 | - * @since 1.0.19 |
|
| 2746 | - * @param float $value fees total. |
|
| 2747 | - */ |
|
| 2748 | - public function set_total_fees( $value ) { |
|
| 2749 | - $this->set_prop( 'total_fees', $value ); |
|
| 2743 | + * Set the invoice fees amount. |
|
| 2744 | + * |
|
| 2745 | + * @since 1.0.19 |
|
| 2746 | + * @param float $value fees total. |
|
| 2747 | + */ |
|
| 2748 | + public function set_total_fees( $value ) { |
|
| 2749 | + $this->set_prop( 'total_fees', $value ); |
|
| 2750 | 2750 | } |
| 2751 | 2751 | |
| 2752 | 2752 | /** |
| 2753 | - * Alias of self::set_total_fees(). |
|
| 2754 | - * |
|
| 2755 | - * @since 1.0.19 |
|
| 2756 | - * @param float $value fees total. |
|
| 2757 | - */ |
|
| 2758 | - public function set_fees_total( $value ) { |
|
| 2759 | - $this->set_total_fees( $value ); |
|
| 2753 | + * Alias of self::set_total_fees(). |
|
| 2754 | + * |
|
| 2755 | + * @since 1.0.19 |
|
| 2756 | + * @param float $value fees total. |
|
| 2757 | + */ |
|
| 2758 | + public function set_fees_total( $value ) { |
|
| 2759 | + $this->set_total_fees( $value ); |
|
| 2760 | 2760 | } |
| 2761 | 2761 | |
| 2762 | 2762 | /** |
| 2763 | - * Set the invoice fees. |
|
| 2764 | - * |
|
| 2765 | - * @since 1.0.19 |
|
| 2766 | - * @param array $value fees. |
|
| 2767 | - */ |
|
| 2768 | - public function set_fees( $value ) { |
|
| 2763 | + * Set the invoice fees. |
|
| 2764 | + * |
|
| 2765 | + * @since 1.0.19 |
|
| 2766 | + * @param array $value fees. |
|
| 2767 | + */ |
|
| 2768 | + public function set_fees( $value ) { |
|
| 2769 | 2769 | |
| 2770 | - if ( ! is_array( $value ) ) { |
|
| 2771 | - $value = array(); |
|
| 2772 | - } |
|
| 2770 | + if ( ! is_array( $value ) ) { |
|
| 2771 | + $value = array(); |
|
| 2772 | + } |
|
| 2773 | 2773 | |
| 2774 | - $this->set_prop( 'fees', $value ); |
|
| 2774 | + $this->set_prop( 'fees', $value ); |
|
| 2775 | 2775 | |
| 2776 | 2776 | } |
| 2777 | 2777 | |
| 2778 | 2778 | /** |
| 2779 | - * Set the invoice taxes. |
|
| 2780 | - * |
|
| 2781 | - * @since 1.0.19 |
|
| 2782 | - * @param array $value taxes. |
|
| 2783 | - */ |
|
| 2784 | - public function set_taxes( $value ) { |
|
| 2779 | + * Set the invoice taxes. |
|
| 2780 | + * |
|
| 2781 | + * @since 1.0.19 |
|
| 2782 | + * @param array $value taxes. |
|
| 2783 | + */ |
|
| 2784 | + public function set_taxes( $value ) { |
|
| 2785 | 2785 | |
| 2786 | - if ( ! is_array( $value ) ) { |
|
| 2787 | - $value = array(); |
|
| 2788 | - } |
|
| 2786 | + if ( ! is_array( $value ) ) { |
|
| 2787 | + $value = array(); |
|
| 2788 | + } |
|
| 2789 | 2789 | |
| 2790 | - $this->set_prop( 'taxes', $value ); |
|
| 2790 | + $this->set_prop( 'taxes', $value ); |
|
| 2791 | 2791 | |
| 2792 | 2792 | } |
| 2793 | 2793 | |
| 2794 | 2794 | /** |
| 2795 | - * Set the invoice discounts. |
|
| 2796 | - * |
|
| 2797 | - * @since 1.0.19 |
|
| 2798 | - * @param array $value discounts. |
|
| 2799 | - */ |
|
| 2800 | - public function set_discounts( $value ) { |
|
| 2795 | + * Set the invoice discounts. |
|
| 2796 | + * |
|
| 2797 | + * @since 1.0.19 |
|
| 2798 | + * @param array $value discounts. |
|
| 2799 | + */ |
|
| 2800 | + public function set_discounts( $value ) { |
|
| 2801 | 2801 | |
| 2802 | - if ( ! is_array( $value ) ) { |
|
| 2803 | - $value = array(); |
|
| 2804 | - } |
|
| 2802 | + if ( ! is_array( $value ) ) { |
|
| 2803 | + $value = array(); |
|
| 2804 | + } |
|
| 2805 | 2805 | |
| 2806 | - $this->set_prop( 'discounts', $value ); |
|
| 2806 | + $this->set_prop( 'discounts', $value ); |
|
| 2807 | 2807 | } |
| 2808 | 2808 | |
| 2809 | 2809 | /** |
| 2810 | - * Set the invoice items. |
|
| 2811 | - * |
|
| 2812 | - * @since 1.0.19 |
|
| 2813 | - * @param GetPaid_Form_Item[] $value items. |
|
| 2814 | - */ |
|
| 2815 | - public function set_items( $value ) { |
|
| 2810 | + * Set the invoice items. |
|
| 2811 | + * |
|
| 2812 | + * @since 1.0.19 |
|
| 2813 | + * @param GetPaid_Form_Item[] $value items. |
|
| 2814 | + */ |
|
| 2815 | + public function set_items( $value ) { |
|
| 2816 | 2816 | |
| 2817 | 2817 | // Remove existing items. |
| 2818 | 2818 | $this->set_prop( 'items', array() ); |
@@ -2829,95 +2829,95 @@ discard block |
||
| 2829 | 2829 | } |
| 2830 | 2830 | |
| 2831 | 2831 | /** |
| 2832 | - * Set the payment form. |
|
| 2833 | - * |
|
| 2834 | - * @since 1.0.19 |
|
| 2835 | - * @param int $value payment form. |
|
| 2836 | - */ |
|
| 2837 | - public function set_payment_form( $value ) { |
|
| 2838 | - $this->set_prop( 'payment_form', $value ); |
|
| 2832 | + * Set the payment form. |
|
| 2833 | + * |
|
| 2834 | + * @since 1.0.19 |
|
| 2835 | + * @param int $value payment form. |
|
| 2836 | + */ |
|
| 2837 | + public function set_payment_form( $value ) { |
|
| 2838 | + $this->set_prop( 'payment_form', $value ); |
|
| 2839 | 2839 | } |
| 2840 | 2840 | |
| 2841 | 2841 | /** |
| 2842 | - * Set the submission id. |
|
| 2843 | - * |
|
| 2844 | - * @since 1.0.19 |
|
| 2845 | - * @param string $value submission id. |
|
| 2846 | - */ |
|
| 2847 | - public function set_submission_id( $value ) { |
|
| 2848 | - $this->set_prop( 'submission_id', $value ); |
|
| 2842 | + * Set the submission id. |
|
| 2843 | + * |
|
| 2844 | + * @since 1.0.19 |
|
| 2845 | + * @param string $value submission id. |
|
| 2846 | + */ |
|
| 2847 | + public function set_submission_id( $value ) { |
|
| 2848 | + $this->set_prop( 'submission_id', $value ); |
|
| 2849 | 2849 | } |
| 2850 | 2850 | |
| 2851 | 2851 | /** |
| 2852 | - * Set the discount code. |
|
| 2853 | - * |
|
| 2854 | - * @since 1.0.19 |
|
| 2855 | - * @param string $value discount code. |
|
| 2856 | - */ |
|
| 2857 | - public function set_discount_code( $value ) { |
|
| 2858 | - $this->set_prop( 'discount_code', $value ); |
|
| 2852 | + * Set the discount code. |
|
| 2853 | + * |
|
| 2854 | + * @since 1.0.19 |
|
| 2855 | + * @param string $value discount code. |
|
| 2856 | + */ |
|
| 2857 | + public function set_discount_code( $value ) { |
|
| 2858 | + $this->set_prop( 'discount_code', $value ); |
|
| 2859 | 2859 | } |
| 2860 | 2860 | |
| 2861 | 2861 | /** |
| 2862 | - * Set the gateway. |
|
| 2863 | - * |
|
| 2864 | - * @since 1.0.19 |
|
| 2865 | - * @param string $value gateway. |
|
| 2866 | - */ |
|
| 2867 | - public function set_gateway( $value ) { |
|
| 2868 | - $this->set_prop( 'gateway', $value ); |
|
| 2862 | + * Set the gateway. |
|
| 2863 | + * |
|
| 2864 | + * @since 1.0.19 |
|
| 2865 | + * @param string $value gateway. |
|
| 2866 | + */ |
|
| 2867 | + public function set_gateway( $value ) { |
|
| 2868 | + $this->set_prop( 'gateway', $value ); |
|
| 2869 | 2869 | } |
| 2870 | 2870 | |
| 2871 | 2871 | /** |
| 2872 | - * Set the transaction id. |
|
| 2873 | - * |
|
| 2874 | - * @since 1.0.19 |
|
| 2875 | - * @param string $value transaction id. |
|
| 2876 | - */ |
|
| 2877 | - public function set_transaction_id( $value ) { |
|
| 2878 | - if ( ! empty( $value ) ) { |
|
| 2879 | - $this->set_prop( 'transaction_id', $value ); |
|
| 2880 | - } |
|
| 2872 | + * Set the transaction id. |
|
| 2873 | + * |
|
| 2874 | + * @since 1.0.19 |
|
| 2875 | + * @param string $value transaction id. |
|
| 2876 | + */ |
|
| 2877 | + public function set_transaction_id( $value ) { |
|
| 2878 | + if ( ! empty( $value ) ) { |
|
| 2879 | + $this->set_prop( 'transaction_id', $value ); |
|
| 2880 | + } |
|
| 2881 | 2881 | } |
| 2882 | 2882 | |
| 2883 | 2883 | /** |
| 2884 | - * Set the currency id. |
|
| 2885 | - * |
|
| 2886 | - * @since 1.0.19 |
|
| 2887 | - * @param string $value currency id. |
|
| 2888 | - */ |
|
| 2889 | - public function set_currency( $value ) { |
|
| 2890 | - $this->set_prop( 'currency', $value ); |
|
| 2884 | + * Set the currency id. |
|
| 2885 | + * |
|
| 2886 | + * @since 1.0.19 |
|
| 2887 | + * @param string $value currency id. |
|
| 2888 | + */ |
|
| 2889 | + public function set_currency( $value ) { |
|
| 2890 | + $this->set_prop( 'currency', $value ); |
|
| 2891 | 2891 | } |
| 2892 | 2892 | |
| 2893 | - /** |
|
| 2894 | - * Set whether to disable taxes. |
|
| 2895 | - * |
|
| 2896 | - * @since 1.0.19 |
|
| 2897 | - * @param bool $value value. |
|
| 2898 | - */ |
|
| 2899 | - public function set_disable_taxes( $value ) { |
|
| 2900 | - $this->set_prop( 'disable_taxes', (bool) $value ); |
|
| 2901 | - } |
|
| 2893 | + /** |
|
| 2894 | + * Set whether to disable taxes. |
|
| 2895 | + * |
|
| 2896 | + * @since 1.0.19 |
|
| 2897 | + * @param bool $value value. |
|
| 2898 | + */ |
|
| 2899 | + public function set_disable_taxes( $value ) { |
|
| 2900 | + $this->set_prop( 'disable_taxes', (bool) $value ); |
|
| 2901 | + } |
|
| 2902 | 2902 | |
| 2903 | 2903 | /** |
| 2904 | - * Set the subscription id. |
|
| 2905 | - * |
|
| 2906 | - * @since 1.0.19 |
|
| 2907 | - * @param string $value subscription id. |
|
| 2908 | - */ |
|
| 2909 | - public function set_subscription_id( $value ) { |
|
| 2910 | - $this->set_prop( 'subscription_id', $value ); |
|
| 2911 | - } |
|
| 2904 | + * Set the subscription id. |
|
| 2905 | + * |
|
| 2906 | + * @since 1.0.19 |
|
| 2907 | + * @param string $value subscription id. |
|
| 2908 | + */ |
|
| 2909 | + public function set_subscription_id( $value ) { |
|
| 2910 | + $this->set_prop( 'subscription_id', $value ); |
|
| 2911 | + } |
|
| 2912 | 2912 | |
| 2913 | - /** |
|
| 2914 | - * Set the remote subscription id. |
|
| 2915 | - * |
|
| 2916 | - * @since 1.0.19 |
|
| 2917 | - * @param string $value subscription id. |
|
| 2918 | - */ |
|
| 2919 | - public function set_remote_subscription_id( $value ) { |
|
| 2920 | - $this->set_prop( 'remote_subscription_id', $value ); |
|
| 2913 | + /** |
|
| 2914 | + * Set the remote subscription id. |
|
| 2915 | + * |
|
| 2916 | + * @since 1.0.19 |
|
| 2917 | + * @param string $value subscription id. |
|
| 2918 | + */ |
|
| 2919 | + public function set_remote_subscription_id( $value ) { |
|
| 2920 | + $this->set_prop( 'remote_subscription_id', $value ); |
|
| 2921 | 2921 | } |
| 2922 | 2922 | |
| 2923 | 2923 | /* |
@@ -2956,24 +2956,24 @@ discard block |
||
| 2956 | 2956 | */ |
| 2957 | 2957 | public function is_taxable() { |
| 2958 | 2958 | return ! $this->get_disable_taxes(); |
| 2959 | - } |
|
| 2959 | + } |
|
| 2960 | 2960 | |
| 2961 | - /** |
|
| 2962 | - * @deprecated |
|
| 2963 | - */ |
|
| 2964 | - public function has_vat() { |
|
| 2961 | + /** |
|
| 2962 | + * @deprecated |
|
| 2963 | + */ |
|
| 2964 | + public function has_vat() { |
|
| 2965 | 2965 | return $this->is_taxable(); |
| 2966 | - } |
|
| 2966 | + } |
|
| 2967 | 2967 | |
| 2968 | - /** |
|
| 2969 | - * Checks to see if the invoice requires payment. |
|
| 2970 | - */ |
|
| 2971 | - public function is_free() { |
|
| 2968 | + /** |
|
| 2969 | + * Checks to see if the invoice requires payment. |
|
| 2970 | + */ |
|
| 2971 | + public function is_free() { |
|
| 2972 | 2972 | $is_free = ( (float) wpinv_round_amount( $this->get_initial_total() ) == 0 ); |
| 2973 | 2973 | |
| 2974 | - if ( $this->is_recurring() && $this->get_recurring_total() > 0 ) { |
|
| 2975 | - $is_free = false; |
|
| 2976 | - } |
|
| 2974 | + if ( $this->is_recurring() && $this->get_recurring_total() > 0 ) { |
|
| 2975 | + $is_free = false; |
|
| 2976 | + } |
|
| 2977 | 2977 | |
| 2978 | 2978 | return apply_filters( 'wpinv_invoice_is_free', $is_free, $this ); |
| 2979 | 2979 | } |
@@ -2984,46 +2984,46 @@ discard block |
||
| 2984 | 2984 | public function is_paid() { |
| 2985 | 2985 | $is_paid = $this->has_status( array( 'publish', 'wpi-processing', 'wpi-renewal' ) ); |
| 2986 | 2986 | return apply_filters( 'wpinv_invoice_is_paid', $is_paid, $this ); |
| 2987 | - } |
|
| 2987 | + } |
|
| 2988 | 2988 | |
| 2989 | - /** |
|
| 2989 | + /** |
|
| 2990 | 2990 | * Checks if the invoice needs payment. |
| 2991 | 2991 | */ |
| 2992 | - public function needs_payment() { |
|
| 2993 | - $needs_payment = ! $this->is_paid() && ! $this->is_refunded() && ! $this->is_free(); |
|
| 2992 | + public function needs_payment() { |
|
| 2993 | + $needs_payment = ! $this->is_paid() && ! $this->is_refunded() && ! $this->is_free(); |
|
| 2994 | 2994 | return apply_filters( 'wpinv_needs_payment', $needs_payment, $this ); |
| 2995 | 2995 | } |
| 2996 | 2996 | |
| 2997 | - /** |
|
| 2997 | + /** |
|
| 2998 | 2998 | * Checks if the invoice is refunded. |
| 2999 | 2999 | */ |
| 3000 | - public function is_refunded() { |
|
| 3000 | + public function is_refunded() { |
|
| 3001 | 3001 | $is_refunded = $this->has_status( 'wpi-refunded' ); |
| 3002 | 3002 | return apply_filters( 'wpinv_invoice_is_refunded', $is_refunded, $this ); |
| 3003 | - } |
|
| 3003 | + } |
|
| 3004 | 3004 | |
| 3005 | - /** |
|
| 3005 | + /** |
|
| 3006 | 3006 | * Checks if the invoice is held. |
| 3007 | 3007 | */ |
| 3008 | - public function is_held() { |
|
| 3008 | + public function is_held() { |
|
| 3009 | 3009 | $is_held = $this->has_status( 'wpi-onhold' ); |
| 3010 | 3010 | return apply_filters( 'wpinv_invoice_is_held', $is_held, $this ); |
| 3011 | - } |
|
| 3011 | + } |
|
| 3012 | 3012 | |
| 3013 | - /** |
|
| 3013 | + /** |
|
| 3014 | 3014 | * Checks if the invoice is due. |
| 3015 | 3015 | */ |
| 3016 | - public function is_due() { |
|
| 3017 | - $due_date = $this->get_due_date(); |
|
| 3018 | - return empty( $due_date ) ? false : current_time( 'timestamp' ) > strtotime( $due_date ); |
|
| 3019 | - } |
|
| 3016 | + public function is_due() { |
|
| 3017 | + $due_date = $this->get_due_date(); |
|
| 3018 | + return empty( $due_date ) ? false : current_time( 'timestamp' ) > strtotime( $due_date ); |
|
| 3019 | + } |
|
| 3020 | 3020 | |
| 3021 | - /** |
|
| 3021 | + /** |
|
| 3022 | 3022 | * Checks if the invoice is draft. |
| 3023 | 3023 | */ |
| 3024 | - public function is_draft() { |
|
| 3024 | + public function is_draft() { |
|
| 3025 | 3025 | return $this->has_status( 'draft, auto-draft' ); |
| 3026 | - } |
|
| 3026 | + } |
|
| 3027 | 3027 | |
| 3028 | 3028 | /** |
| 3029 | 3029 | * Checks if the invoice has a given status. |
@@ -3031,9 +3031,9 @@ discard block |
||
| 3031 | 3031 | public function has_status( $status ) { |
| 3032 | 3032 | $status = wpinv_parse_list( $status ); |
| 3033 | 3033 | return apply_filters( 'wpinv_has_status', in_array( $this->get_status(), $status ), $status ); |
| 3034 | - } |
|
| 3034 | + } |
|
| 3035 | 3035 | |
| 3036 | - /** |
|
| 3036 | + /** |
|
| 3037 | 3037 | * Checks if the invoice is of a given type. |
| 3038 | 3038 | */ |
| 3039 | 3039 | public function is_type( $type ) { |
@@ -3056,25 +3056,25 @@ discard block |
||
| 3056 | 3056 | */ |
| 3057 | 3057 | public function has_free_trial() { |
| 3058 | 3058 | return $this->is_recurring() && 0 == $this->get_initial_total(); |
| 3059 | - } |
|
| 3059 | + } |
|
| 3060 | 3060 | |
| 3061 | - /** |
|
| 3061 | + /** |
|
| 3062 | 3062 | * @deprecated |
| 3063 | 3063 | */ |
| 3064 | 3064 | public function is_free_trial() { |
| 3065 | 3065 | $this->has_free_trial(); |
| 3066 | 3066 | } |
| 3067 | 3067 | |
| 3068 | - /** |
|
| 3068 | + /** |
|
| 3069 | 3069 | * Check if the initial payment if 0. |
| 3070 | 3070 | * |
| 3071 | 3071 | */ |
| 3072 | - public function is_initial_free() { |
|
| 3072 | + public function is_initial_free() { |
|
| 3073 | 3073 | $is_initial_free = ! ( (float) wpinv_round_amount( $this->get_initial_total() ) > 0 ); |
| 3074 | 3074 | return apply_filters( 'wpinv_invoice_is_initial_free', $is_initial_free, $this->get_cart_details(), $this ); |
| 3075 | 3075 | } |
| 3076 | 3076 | |
| 3077 | - /** |
|
| 3077 | + /** |
|
| 3078 | 3078 | * Check if the recurring item has a free trial. |
| 3079 | 3079 | * |
| 3080 | 3080 | */ |
@@ -3087,21 +3087,21 @@ discard block |
||
| 3087 | 3087 | |
| 3088 | 3088 | $item = $this->get_recurring( true ); |
| 3089 | 3089 | return $item->has_free_trial(); |
| 3090 | - } |
|
| 3090 | + } |
|
| 3091 | 3091 | |
| 3092 | - /** |
|
| 3092 | + /** |
|
| 3093 | 3093 | * Check if the free trial is a result of a discount. |
| 3094 | 3094 | */ |
| 3095 | 3095 | public function is_free_trial_from_discount() { |
| 3096 | - return $this->has_free_trial() && ! $this->item_has_free_trial(); |
|
| 3097 | - } |
|
| 3096 | + return $this->has_free_trial() && ! $this->item_has_free_trial(); |
|
| 3097 | + } |
|
| 3098 | 3098 | |
| 3099 | - /** |
|
| 3099 | + /** |
|
| 3100 | 3100 | * @deprecated |
| 3101 | 3101 | */ |
| 3102 | 3102 | public function discount_first_payment_only() { |
| 3103 | 3103 | |
| 3104 | - $discount = wpinv_get_discount_obj( $this->get_discount_code() ); |
|
| 3104 | + $discount = wpinv_get_discount_obj( $this->get_discount_code() ); |
|
| 3105 | 3105 | if ( ! $discount->exists() || ! $this->is_recurring() ) { |
| 3106 | 3106 | return true; |
| 3107 | 3107 | } |
@@ -3126,28 +3126,28 @@ discard block |
||
| 3126 | 3126 | */ |
| 3127 | 3127 | public function add_item( $item ) { |
| 3128 | 3128 | |
| 3129 | - if ( is_array( $item ) ) { |
|
| 3130 | - $item = $this->process_array_item( $item ); |
|
| 3131 | - } |
|
| 3129 | + if ( is_array( $item ) ) { |
|
| 3130 | + $item = $this->process_array_item( $item ); |
|
| 3131 | + } |
|
| 3132 | 3132 | |
| 3133 | - if ( is_numeric( $item ) ) { |
|
| 3134 | - $item = new GetPaid_Form_Item( $item ); |
|
| 3135 | - } |
|
| 3133 | + if ( is_numeric( $item ) ) { |
|
| 3134 | + $item = new GetPaid_Form_Item( $item ); |
|
| 3135 | + } |
|
| 3136 | 3136 | |
| 3137 | 3137 | // Make sure that it is available for purchase. |
| 3138 | - if ( $item->get_id() > 0 && ! $item->can_purchase() ) { |
|
| 3139 | - return new WP_Error( 'invalid_item', __( 'This item is not available for purchase', 'invoicing' ) ); |
|
| 3138 | + if ( $item->get_id() > 0 && ! $item->can_purchase() ) { |
|
| 3139 | + return new WP_Error( 'invalid_item', __( 'This item is not available for purchase', 'invoicing' ) ); |
|
| 3140 | 3140 | } |
| 3141 | 3141 | |
| 3142 | 3142 | // Do we have a recurring item? |
| 3143 | - if ( $item->is_recurring() ) { |
|
| 3143 | + if ( $item->is_recurring() ) { |
|
| 3144 | 3144 | |
| 3145 | - // An invoice can only contain one recurring item. |
|
| 3146 | - if ( ! empty( $this->recurring_item && $this->recurring_item != (int) $item->get_id() ) ) { |
|
| 3147 | - return new WP_Error( 'recurring_item', __( 'An invoice can only contain one recurring item', 'invoicing' ) ); |
|
| 3148 | - } |
|
| 3145 | + // An invoice can only contain one recurring item. |
|
| 3146 | + if ( ! empty( $this->recurring_item && $this->recurring_item != (int) $item->get_id() ) ) { |
|
| 3147 | + return new WP_Error( 'recurring_item', __( 'An invoice can only contain one recurring item', 'invoicing' ) ); |
|
| 3148 | + } |
|
| 3149 | 3149 | |
| 3150 | - $this->recurring_item = $item->get_id(); |
|
| 3150 | + $this->recurring_item = $item->get_id(); |
|
| 3151 | 3151 | } |
| 3152 | 3152 | |
| 3153 | 3153 | // Invoice id. |
@@ -3158,60 +3158,60 @@ discard block |
||
| 3158 | 3158 | $items[ (int) $item->get_id() ] = $item; |
| 3159 | 3159 | |
| 3160 | 3160 | $this->set_prop( 'items', $items ); |
| 3161 | - return true; |
|
| 3162 | - } |
|
| 3161 | + return true; |
|
| 3162 | + } |
|
| 3163 | 3163 | |
| 3164 | - /** |
|
| 3165 | - * Converts an array to an item. |
|
| 3166 | - * |
|
| 3167 | - * @since 1.0.19 |
|
| 3168 | - * @return GetPaid_Form_Item |
|
| 3169 | - */ |
|
| 3170 | - protected function process_array_item( $array ) { |
|
| 3164 | + /** |
|
| 3165 | + * Converts an array to an item. |
|
| 3166 | + * |
|
| 3167 | + * @since 1.0.19 |
|
| 3168 | + * @return GetPaid_Form_Item |
|
| 3169 | + */ |
|
| 3170 | + protected function process_array_item( $array ) { |
|
| 3171 | 3171 | |
| 3172 | - $item_id = isset( $array['item_id'] ) ? $array['item_id'] : 0; |
|
| 3173 | - $item = new GetPaid_Form_Item( $item_id ); |
|
| 3172 | + $item_id = isset( $array['item_id'] ) ? $array['item_id'] : 0; |
|
| 3173 | + $item = new GetPaid_Form_Item( $item_id ); |
|
| 3174 | 3174 | |
| 3175 | - // Set item data. |
|
| 3176 | - foreach ( array( 'name', 'price', 'description' ) as $key ) { |
|
| 3177 | - if ( isset( $array[ "item_$key" ] ) ) { |
|
| 3178 | - $method = "set_$key"; |
|
| 3179 | - $item->$method( $array[ "item_$key" ] ); |
|
| 3180 | - } |
|
| 3181 | - } |
|
| 3175 | + // Set item data. |
|
| 3176 | + foreach ( array( 'name', 'price', 'description' ) as $key ) { |
|
| 3177 | + if ( isset( $array[ "item_$key" ] ) ) { |
|
| 3178 | + $method = "set_$key"; |
|
| 3179 | + $item->$method( $array[ "item_$key" ] ); |
|
| 3180 | + } |
|
| 3181 | + } |
|
| 3182 | 3182 | |
| 3183 | - if ( isset( $array['quantity'] ) ) { |
|
| 3184 | - $item->set_quantity( $array['quantity'] ); |
|
| 3185 | - } |
|
| 3183 | + if ( isset( $array['quantity'] ) ) { |
|
| 3184 | + $item->set_quantity( $array['quantity'] ); |
|
| 3185 | + } |
|
| 3186 | 3186 | |
| 3187 | - // Set item meta. |
|
| 3188 | - if ( isset( $array['meta'] ) && is_array( $array['meta'] ) ) { |
|
| 3189 | - $item->set_item_meta( $array['meta'] ); |
|
| 3190 | - } |
|
| 3187 | + // Set item meta. |
|
| 3188 | + if ( isset( $array['meta'] ) && is_array( $array['meta'] ) ) { |
|
| 3189 | + $item->set_item_meta( $array['meta'] ); |
|
| 3190 | + } |
|
| 3191 | 3191 | |
| 3192 | - return $item; |
|
| 3192 | + return $item; |
|
| 3193 | 3193 | |
| 3194 | - } |
|
| 3194 | + } |
|
| 3195 | 3195 | |
| 3196 | 3196 | /** |
| 3197 | - * Retrieves a specific item. |
|
| 3198 | - * |
|
| 3199 | - * @since 1.0.19 |
|
| 3200 | - */ |
|
| 3201 | - public function get_item( $item_id ) { |
|
| 3202 | - $items = $this->get_items(); |
|
| 3203 | - $item_id = (int) $item_id; |
|
| 3204 | - return ( ! empty( $item_id ) && isset( $items[ $item_id ] ) ) ? $items[ $item_id ] : null; |
|
| 3197 | + * Retrieves a specific item. |
|
| 3198 | + * |
|
| 3199 | + * @since 1.0.19 |
|
| 3200 | + */ |
|
| 3201 | + public function get_item( $item_id ) { |
|
| 3202 | + $items = $this->get_items(); |
|
| 3203 | + $item_id = (int) $item_id; |
|
| 3204 | + return ( ! empty( $item_id ) && isset( $items[ $item_id ] ) ) ? $items[ $item_id ] : null; |
|
| 3205 | 3205 | } |
| 3206 | 3206 | |
| 3207 | 3207 | /** |
| 3208 | - * Removes a specific item. |
|
| 3209 | - * |
|
| 3210 | - * @since 1.0.19 |
|
| 3211 | - */ |
|
| 3212 | - public function remove_item( $item_id ) { |
|
| 3213 | - $items = $this->get_items(); |
|
| 3214 | - $item_id = (int) $item_id; |
|
| 3208 | + * Removes a specific item. |
|
| 3209 | + * |
|
| 3210 | + * @since 1.0.19 |
|
| 3211 | + */ |
|
| 3212 | + public function remove_item( $item_id ) { |
|
| 3213 | + $items = $this->get_items(); |
|
| 3214 | + $item_id = (int) $item_id; |
|
| 3215 | 3215 | |
| 3216 | 3216 | if ( $item_id == $this->recurring_item ) { |
| 3217 | 3217 | $this->recurring_item = null; |
@@ -3224,35 +3224,35 @@ discard block |
||
| 3224 | 3224 | } |
| 3225 | 3225 | |
| 3226 | 3226 | /** |
| 3227 | - * Adds a fee to the invoice. |
|
| 3228 | - * |
|
| 3229 | - * @param array $fee An array of fee details. name, initial_fee, and recurring_fee are required. |
|
| 3230 | - * @since 1.0.19 |
|
| 3231 | - */ |
|
| 3227 | + * Adds a fee to the invoice. |
|
| 3228 | + * |
|
| 3229 | + * @param array $fee An array of fee details. name, initial_fee, and recurring_fee are required. |
|
| 3230 | + * @since 1.0.19 |
|
| 3231 | + */ |
|
| 3232 | 3232 | public function add_fee( $fee ) { |
| 3233 | 3233 | |
| 3234 | - $fees = $this->get_fees(); |
|
| 3235 | - $fees[ $fee['name'] ] = $fee; |
|
| 3236 | - $this->set_prop( 'fees', $fees ); |
|
| 3234 | + $fees = $this->get_fees(); |
|
| 3235 | + $fees[ $fee['name'] ] = $fee; |
|
| 3236 | + $this->set_prop( 'fees', $fees ); |
|
| 3237 | 3237 | |
| 3238 | 3238 | } |
| 3239 | 3239 | |
| 3240 | 3240 | /** |
| 3241 | - * Retrieves a specific fee. |
|
| 3242 | - * |
|
| 3243 | - * @since 1.0.19 |
|
| 3244 | - */ |
|
| 3245 | - public function get_fee( $fee ) { |
|
| 3241 | + * Retrieves a specific fee. |
|
| 3242 | + * |
|
| 3243 | + * @since 1.0.19 |
|
| 3244 | + */ |
|
| 3245 | + public function get_fee( $fee ) { |
|
| 3246 | 3246 | $fees = $this->get_fees(); |
| 3247 | - return isset( $fees[ $fee ] ) ? $fees[ $fee ] : null; |
|
| 3247 | + return isset( $fees[ $fee ] ) ? $fees[ $fee ] : null; |
|
| 3248 | 3248 | } |
| 3249 | 3249 | |
| 3250 | 3250 | /** |
| 3251 | - * Removes a specific fee. |
|
| 3252 | - * |
|
| 3253 | - * @since 1.0.19 |
|
| 3254 | - */ |
|
| 3255 | - public function remove_fee( $fee ) { |
|
| 3251 | + * Removes a specific fee. |
|
| 3252 | + * |
|
| 3253 | + * @since 1.0.19 |
|
| 3254 | + */ |
|
| 3255 | + public function remove_fee( $fee ) { |
|
| 3256 | 3256 | $fees = $this->get_fees(); |
| 3257 | 3257 | if ( isset( $fees[ $fee ] ) ) { |
| 3258 | 3258 | unset( $fees[ $fee ] ); |
@@ -3260,43 +3260,43 @@ discard block |
||
| 3260 | 3260 | } |
| 3261 | 3261 | } |
| 3262 | 3262 | |
| 3263 | - /** |
|
| 3264 | - * Adds a discount to the invoice. |
|
| 3265 | - * |
|
| 3266 | - * @param array $discount An array of discount details. name, initial_discount, and recurring_discount are required. Include discount_code if the discount is from a discount code. |
|
| 3267 | - * @since 1.0.19 |
|
| 3268 | - */ |
|
| 3269 | - public function add_discount( $discount ) { |
|
| 3263 | + /** |
|
| 3264 | + * Adds a discount to the invoice. |
|
| 3265 | + * |
|
| 3266 | + * @param array $discount An array of discount details. name, initial_discount, and recurring_discount are required. Include discount_code if the discount is from a discount code. |
|
| 3267 | + * @since 1.0.19 |
|
| 3268 | + */ |
|
| 3269 | + public function add_discount( $discount ) { |
|
| 3270 | 3270 | |
| 3271 | - $discounts = $this->get_discounts(); |
|
| 3272 | - $discounts[ $discount['name'] ] = $discount; |
|
| 3273 | - $this->set_prop( 'discounts', $discounts ); |
|
| 3271 | + $discounts = $this->get_discounts(); |
|
| 3272 | + $discounts[ $discount['name'] ] = $discount; |
|
| 3273 | + $this->set_prop( 'discounts', $discounts ); |
|
| 3274 | 3274 | |
| 3275 | - } |
|
| 3275 | + } |
|
| 3276 | 3276 | |
| 3277 | 3277 | /** |
| 3278 | - * Retrieves a specific discount. |
|
| 3279 | - * |
|
| 3280 | - * @since 1.0.19 |
|
| 3281 | - * @return float |
|
| 3282 | - */ |
|
| 3283 | - public function get_discount( $discount = false ) { |
|
| 3278 | + * Retrieves a specific discount. |
|
| 3279 | + * |
|
| 3280 | + * @since 1.0.19 |
|
| 3281 | + * @return float |
|
| 3282 | + */ |
|
| 3283 | + public function get_discount( $discount = false ) { |
|
| 3284 | 3284 | |
| 3285 | - // Backwards compatibilty. |
|
| 3286 | - if ( empty( $discount ) ) { |
|
| 3287 | - return $this->get_total_discount(); |
|
| 3288 | - } |
|
| 3285 | + // Backwards compatibilty. |
|
| 3286 | + if ( empty( $discount ) ) { |
|
| 3287 | + return $this->get_total_discount(); |
|
| 3288 | + } |
|
| 3289 | 3289 | |
| 3290 | 3290 | $discounts = $this->get_discounts(); |
| 3291 | - return isset( $discounts[ $discount ] ) ? $discounts[ $discount ] : null; |
|
| 3291 | + return isset( $discounts[ $discount ] ) ? $discounts[ $discount ] : null; |
|
| 3292 | 3292 | } |
| 3293 | 3293 | |
| 3294 | 3294 | /** |
| 3295 | - * Removes a specific discount. |
|
| 3296 | - * |
|
| 3297 | - * @since 1.0.19 |
|
| 3298 | - */ |
|
| 3299 | - public function remove_discount( $discount ) { |
|
| 3295 | + * Removes a specific discount. |
|
| 3296 | + * |
|
| 3297 | + * @since 1.0.19 |
|
| 3298 | + */ |
|
| 3299 | + public function remove_discount( $discount ) { |
|
| 3300 | 3300 | $discounts = $this->get_discounts(); |
| 3301 | 3301 | if ( isset( $discounts[ $discount ] ) ) { |
| 3302 | 3302 | unset( $discounts[ $discount ] ); |
@@ -3313,34 +3313,34 @@ discard block |
||
| 3313 | 3313 | if ( $this->is_taxable() ) { |
| 3314 | 3314 | |
| 3315 | 3315 | $taxes = $this->get_taxes(); |
| 3316 | - $taxes[ $tax['name'] ] = $tax; |
|
| 3317 | - $this->set_prop( 'taxes', $tax ); |
|
| 3316 | + $taxes[ $tax['name'] ] = $tax; |
|
| 3317 | + $this->set_prop( 'taxes', $tax ); |
|
| 3318 | 3318 | |
| 3319 | 3319 | } |
| 3320 | 3320 | } |
| 3321 | 3321 | |
| 3322 | 3322 | /** |
| 3323 | - * Retrieves a specific tax. |
|
| 3324 | - * |
|
| 3325 | - * @since 1.0.19 |
|
| 3326 | - */ |
|
| 3327 | - public function get_tax( $tax = null ) { |
|
| 3323 | + * Retrieves a specific tax. |
|
| 3324 | + * |
|
| 3325 | + * @since 1.0.19 |
|
| 3326 | + */ |
|
| 3327 | + public function get_tax( $tax = null ) { |
|
| 3328 | 3328 | |
| 3329 | - // Backwards compatility. |
|
| 3330 | - if ( empty( $tax ) ) { |
|
| 3331 | - return $this->get_total_tax(); |
|
| 3332 | - } |
|
| 3329 | + // Backwards compatility. |
|
| 3330 | + if ( empty( $tax ) ) { |
|
| 3331 | + return $this->get_total_tax(); |
|
| 3332 | + } |
|
| 3333 | 3333 | |
| 3334 | 3334 | $taxes = $this->get_taxes(); |
| 3335 | - return isset( $taxes[ $tax ] ) ? $taxes[ $tax ] : null; |
|
| 3335 | + return isset( $taxes[ $tax ] ) ? $taxes[ $tax ] : null; |
|
| 3336 | 3336 | } |
| 3337 | 3337 | |
| 3338 | 3338 | /** |
| 3339 | - * Removes a specific tax. |
|
| 3340 | - * |
|
| 3341 | - * @since 1.0.19 |
|
| 3342 | - */ |
|
| 3343 | - public function remove_tax( $tax ) { |
|
| 3339 | + * Removes a specific tax. |
|
| 3340 | + * |
|
| 3341 | + * @since 1.0.19 |
|
| 3342 | + */ |
|
| 3343 | + public function remove_tax( $tax ) { |
|
| 3344 | 3344 | $taxes = $this->get_taxes(); |
| 3345 | 3345 | if ( isset( $taxes[ $tax ] ) ) { |
| 3346 | 3346 | unset( $taxes[ $tax ] ); |
@@ -3349,134 +3349,134 @@ discard block |
||
| 3349 | 3349 | } |
| 3350 | 3350 | |
| 3351 | 3351 | /** |
| 3352 | - * Recalculates the invoice subtotal. |
|
| 3353 | - * |
|
| 3354 | - * @since 1.0.19 |
|
| 3355 | - * @return float The recalculated subtotal |
|
| 3356 | - */ |
|
| 3357 | - public function recalculate_subtotal() { |
|
| 3352 | + * Recalculates the invoice subtotal. |
|
| 3353 | + * |
|
| 3354 | + * @since 1.0.19 |
|
| 3355 | + * @return float The recalculated subtotal |
|
| 3356 | + */ |
|
| 3357 | + public function recalculate_subtotal() { |
|
| 3358 | 3358 | $items = $this->get_items(); |
| 3359 | - $subtotal = 0; |
|
| 3360 | - $recurring = 0; |
|
| 3359 | + $subtotal = 0; |
|
| 3360 | + $recurring = 0; |
|
| 3361 | 3361 | |
| 3362 | 3362 | foreach ( $items as $item ) { |
| 3363 | - $subtotal += $item->get_sub_total(); |
|
| 3364 | - $recurring += $item->get_recurring_sub_total(); |
|
| 3363 | + $subtotal += $item->get_sub_total(); |
|
| 3364 | + $recurring += $item->get_recurring_sub_total(); |
|
| 3365 | 3365 | } |
| 3366 | 3366 | |
| 3367 | - $current = $this->is_renewal() ? $recurring : $subtotal; |
|
| 3368 | - $this->set_subtotal( $current ); |
|
| 3367 | + $current = $this->is_renewal() ? $recurring : $subtotal; |
|
| 3368 | + $this->set_subtotal( $current ); |
|
| 3369 | 3369 | |
| 3370 | - $this->totals['subtotal'] = array( |
|
| 3371 | - 'initial' => $subtotal, |
|
| 3372 | - 'recurring' => $recurring, |
|
| 3373 | - ); |
|
| 3370 | + $this->totals['subtotal'] = array( |
|
| 3371 | + 'initial' => $subtotal, |
|
| 3372 | + 'recurring' => $recurring, |
|
| 3373 | + ); |
|
| 3374 | 3374 | |
| 3375 | 3375 | return $current; |
| 3376 | 3376 | } |
| 3377 | 3377 | |
| 3378 | 3378 | /** |
| 3379 | - * Recalculates the invoice discount total. |
|
| 3380 | - * |
|
| 3381 | - * @since 1.0.19 |
|
| 3382 | - * @return float The recalculated discount |
|
| 3383 | - */ |
|
| 3384 | - public function recalculate_total_discount() { |
|
| 3379 | + * Recalculates the invoice discount total. |
|
| 3380 | + * |
|
| 3381 | + * @since 1.0.19 |
|
| 3382 | + * @return float The recalculated discount |
|
| 3383 | + */ |
|
| 3384 | + public function recalculate_total_discount() { |
|
| 3385 | 3385 | $discounts = $this->get_discounts(); |
| 3386 | - $discount = 0; |
|
| 3387 | - $recurring = 0; |
|
| 3386 | + $discount = 0; |
|
| 3387 | + $recurring = 0; |
|
| 3388 | 3388 | |
| 3389 | 3389 | foreach ( $discounts as $data ) { |
| 3390 | - $discount += wpinv_sanitize_amount( $data['initial_discount'] ); |
|
| 3391 | - $recurring += wpinv_sanitize_amount( $data['recurring_discount'] ); |
|
| 3392 | - } |
|
| 3390 | + $discount += wpinv_sanitize_amount( $data['initial_discount'] ); |
|
| 3391 | + $recurring += wpinv_sanitize_amount( $data['recurring_discount'] ); |
|
| 3392 | + } |
|
| 3393 | 3393 | |
| 3394 | - $current = $this->is_renewal() ? $recurring : $discount; |
|
| 3394 | + $current = $this->is_renewal() ? $recurring : $discount; |
|
| 3395 | 3395 | |
| 3396 | - $this->set_total_discount( $current ); |
|
| 3396 | + $this->set_total_discount( $current ); |
|
| 3397 | 3397 | |
| 3398 | - $this->totals['discount'] = array( |
|
| 3399 | - 'initial' => $discount, |
|
| 3400 | - 'recurring' => $recurring, |
|
| 3401 | - ); |
|
| 3398 | + $this->totals['discount'] = array( |
|
| 3399 | + 'initial' => $discount, |
|
| 3400 | + 'recurring' => $recurring, |
|
| 3401 | + ); |
|
| 3402 | 3402 | |
| 3403 | - return $current; |
|
| 3403 | + return $current; |
|
| 3404 | 3404 | |
| 3405 | 3405 | } |
| 3406 | 3406 | |
| 3407 | 3407 | /** |
| 3408 | - * Recalculates the invoice tax total. |
|
| 3409 | - * |
|
| 3410 | - * @since 1.0.19 |
|
| 3411 | - * @return float The recalculated tax |
|
| 3412 | - */ |
|
| 3413 | - public function recalculate_total_tax() { |
|
| 3408 | + * Recalculates the invoice tax total. |
|
| 3409 | + * |
|
| 3410 | + * @since 1.0.19 |
|
| 3411 | + * @return float The recalculated tax |
|
| 3412 | + */ |
|
| 3413 | + public function recalculate_total_tax() { |
|
| 3414 | 3414 | $taxes = $this->get_taxes(); |
| 3415 | - $tax = 0; |
|
| 3416 | - $recurring = 0; |
|
| 3415 | + $tax = 0; |
|
| 3416 | + $recurring = 0; |
|
| 3417 | 3417 | |
| 3418 | 3418 | foreach ( $taxes as $data ) { |
| 3419 | - $tax += wpinv_sanitize_amount( $data['initial_tax'] ); |
|
| 3420 | - $recurring += wpinv_sanitize_amount( $data['recurring_tax'] ); |
|
| 3421 | - } |
|
| 3419 | + $tax += wpinv_sanitize_amount( $data['initial_tax'] ); |
|
| 3420 | + $recurring += wpinv_sanitize_amount( $data['recurring_tax'] ); |
|
| 3421 | + } |
|
| 3422 | 3422 | |
| 3423 | - $current = $this->is_renewal() ? $recurring : $tax; |
|
| 3424 | - $this->set_total_tax( $current ); |
|
| 3423 | + $current = $this->is_renewal() ? $recurring : $tax; |
|
| 3424 | + $this->set_total_tax( $current ); |
|
| 3425 | 3425 | |
| 3426 | - $this->totals['tax'] = array( |
|
| 3427 | - 'initial' => $tax, |
|
| 3428 | - 'recurring' => $recurring, |
|
| 3429 | - ); |
|
| 3426 | + $this->totals['tax'] = array( |
|
| 3427 | + 'initial' => $tax, |
|
| 3428 | + 'recurring' => $recurring, |
|
| 3429 | + ); |
|
| 3430 | 3430 | |
| 3431 | - return $current; |
|
| 3431 | + return $current; |
|
| 3432 | 3432 | |
| 3433 | 3433 | } |
| 3434 | 3434 | |
| 3435 | 3435 | /** |
| 3436 | - * Recalculates the invoice fees total. |
|
| 3437 | - * |
|
| 3438 | - * @since 1.0.19 |
|
| 3439 | - * @return float The recalculated fee |
|
| 3440 | - */ |
|
| 3441 | - public function recalculate_total_fees() { |
|
| 3442 | - $fees = $this->get_fees(); |
|
| 3443 | - $fee = 0; |
|
| 3444 | - $recurring = 0; |
|
| 3436 | + * Recalculates the invoice fees total. |
|
| 3437 | + * |
|
| 3438 | + * @since 1.0.19 |
|
| 3439 | + * @return float The recalculated fee |
|
| 3440 | + */ |
|
| 3441 | + public function recalculate_total_fees() { |
|
| 3442 | + $fees = $this->get_fees(); |
|
| 3443 | + $fee = 0; |
|
| 3444 | + $recurring = 0; |
|
| 3445 | 3445 | |
| 3446 | 3446 | foreach ( $fees as $data ) { |
| 3447 | - $fee += wpinv_sanitize_amount( $data['initial_fee'] ); |
|
| 3448 | - $recurring += wpinv_sanitize_amount( $data['recurring_fee'] ); |
|
| 3449 | - } |
|
| 3447 | + $fee += wpinv_sanitize_amount( $data['initial_fee'] ); |
|
| 3448 | + $recurring += wpinv_sanitize_amount( $data['recurring_fee'] ); |
|
| 3449 | + } |
|
| 3450 | 3450 | |
| 3451 | - $current = $this->is_renewal() ? $recurring : $fee; |
|
| 3452 | - $this->set_total_fees( $current ); |
|
| 3451 | + $current = $this->is_renewal() ? $recurring : $fee; |
|
| 3452 | + $this->set_total_fees( $current ); |
|
| 3453 | 3453 | |
| 3454 | - $this->totals['fee'] = array( |
|
| 3455 | - 'initial' => $fee, |
|
| 3456 | - 'recurring' => $recurring, |
|
| 3457 | - ); |
|
| 3454 | + $this->totals['fee'] = array( |
|
| 3455 | + 'initial' => $fee, |
|
| 3456 | + 'recurring' => $recurring, |
|
| 3457 | + ); |
|
| 3458 | 3458 | |
| 3459 | 3459 | $this->set_total_fees( $fee ); |
| 3460 | 3460 | return $current; |
| 3461 | 3461 | } |
| 3462 | 3462 | |
| 3463 | 3463 | /** |
| 3464 | - * Recalculates the invoice total. |
|
| 3465 | - * |
|
| 3466 | - * @since 1.0.19 |
|
| 3464 | + * Recalculates the invoice total. |
|
| 3465 | + * |
|
| 3466 | + * @since 1.0.19 |
|
| 3467 | 3467 | * @return float The invoice total |
| 3468 | - */ |
|
| 3469 | - public function recalculate_total() { |
|
| 3468 | + */ |
|
| 3469 | + public function recalculate_total() { |
|
| 3470 | 3470 | $this->recalculate_subtotal(); |
| 3471 | 3471 | $this->recalculate_total_fees(); |
| 3472 | 3472 | $this->recalculate_total_discount(); |
| 3473 | 3473 | $this->recalculate_total_tax(); |
| 3474 | - return $this->get_total(); |
|
| 3475 | - } |
|
| 3474 | + return $this->get_total(); |
|
| 3475 | + } |
|
| 3476 | 3476 | |
| 3477 | - /** |
|
| 3478 | - * @deprecated |
|
| 3479 | - */ |
|
| 3477 | + /** |
|
| 3478 | + * @deprecated |
|
| 3479 | + */ |
|
| 3480 | 3480 | public function recalculate_totals( $temp = false ) { |
| 3481 | 3481 | $this->update_items( $temp ); |
| 3482 | 3482 | $this->save( true ); |
@@ -3494,7 +3494,7 @@ discard block |
||
| 3494 | 3494 | * Adds a note to an invoice. |
| 3495 | 3495 | * |
| 3496 | 3496 | * @param string $note The note being added. |
| 3497 | - * @return int|false The new note's ID on success, false on failure. |
|
| 3497 | + * @return int|false The new note's ID on success, false on failure. |
|
| 3498 | 3498 | * |
| 3499 | 3499 | */ |
| 3500 | 3500 | public function add_note( $note = '', $customer_type = false, $added_by_user = false, $system = false ) { |
@@ -3504,21 +3504,21 @@ discard block |
||
| 3504 | 3504 | return false; |
| 3505 | 3505 | } |
| 3506 | 3506 | |
| 3507 | - $author = 'System'; |
|
| 3508 | - $author_email = '[email protected]'; |
|
| 3507 | + $author = 'System'; |
|
| 3508 | + $author_email = '[email protected]'; |
|
| 3509 | 3509 | |
| 3510 | - // If this is an admin comment or it has been added by the user. |
|
| 3511 | - if ( is_user_logged_in() && ( ! $system || $added_by_user ) ) { |
|
| 3512 | - $user = get_user_by( 'id', get_current_user_id() ); |
|
| 3510 | + // If this is an admin comment or it has been added by the user. |
|
| 3511 | + if ( is_user_logged_in() && ( ! $system || $added_by_user ) ) { |
|
| 3512 | + $user = get_user_by( 'id', get_current_user_id() ); |
|
| 3513 | 3513 | $author = $user->display_name; |
| 3514 | 3514 | $author_email = $user->user_email; |
| 3515 | - } |
|
| 3515 | + } |
|
| 3516 | 3516 | |
| 3517 | - return getpaid_notes()->add_invoice_note( $this, $note, $author, $author_email, $customer_type ); |
|
| 3517 | + return getpaid_notes()->add_invoice_note( $this, $note, $author, $author_email, $customer_type ); |
|
| 3518 | 3518 | |
| 3519 | - } |
|
| 3519 | + } |
|
| 3520 | 3520 | |
| 3521 | - /** |
|
| 3521 | + /** |
|
| 3522 | 3522 | * Generates a unique key for the invoice. |
| 3523 | 3523 | */ |
| 3524 | 3524 | public function generate_key( $string = '' ) { |
@@ -3538,113 +3538,113 @@ discard block |
||
| 3538 | 3538 | $number = wpinv_get_next_invoice_number( $this->get_post_type() ); |
| 3539 | 3539 | } |
| 3540 | 3540 | |
| 3541 | - return wpinv_format_invoice_number( $number, $this->get_post_type() ); |
|
| 3542 | - |
|
| 3543 | - } |
|
| 3544 | - |
|
| 3545 | - /** |
|
| 3546 | - * Handle the status transition. |
|
| 3547 | - */ |
|
| 3548 | - protected function status_transition() { |
|
| 3549 | - $status_transition = $this->status_transition; |
|
| 3550 | - |
|
| 3551 | - // Reset status transition variable. |
|
| 3552 | - $this->status_transition = false; |
|
| 3553 | - |
|
| 3554 | - if ( $status_transition ) { |
|
| 3555 | - try { |
|
| 3541 | + return wpinv_format_invoice_number( $number, $this->get_post_type() ); |
|
| 3556 | 3542 | |
| 3557 | - // Fire a hook for the status change. |
|
| 3558 | - do_action( 'getpaid_invoice_status_' . $status_transition['to'], $this, $status_transition ); |
|
| 3559 | - |
|
| 3560 | - // @deprecated this is deprecated and will be removed in the future. |
|
| 3561 | - do_action( 'wpinv_status_' . $status_transition['to'], $this->get_id(), $status_transition['from'] ); |
|
| 3562 | - |
|
| 3563 | - if ( ! empty( $status_transition['from'] ) ) { |
|
| 3564 | - |
|
| 3565 | - /* translators: 1: old invoice status 2: new invoice status */ |
|
| 3566 | - $transition_note = sprintf( __( 'Status changed from %1$s to %2$s.', 'invoicing' ), wpinv_status_nicename( $status_transition['from'], $this ), wpinv_status_nicename( $status_transition['to'], $this ) ); |
|
| 3567 | - |
|
| 3568 | - // Fire another hook. |
|
| 3569 | - do_action( 'getpaid_invoice_status_' . $status_transition['from'] . '_to_' . $status_transition['to'], $this ); |
|
| 3570 | - do_action( 'getpaid_invoice_status_changed', $this, $status_transition['from'], $status_transition['to'] ); |
|
| 3571 | - |
|
| 3572 | - // @deprecated this is deprecated and will be removed in the future. |
|
| 3573 | - do_action( 'wpinv_status_' . $status_transition['from'] . '_to_' . $status_transition['to'], $this->get_id(), $status_transition['from'] ); |
|
| 3574 | - |
|
| 3575 | - // Note the transition occurred. |
|
| 3576 | - $this->add_note( trim( $status_transition['note'] . ' ' . $transition_note ), false, $status_transition['manual'] ); |
|
| 3577 | - |
|
| 3578 | - // Work out if this was for a payment, and trigger a payment_status hook instead. |
|
| 3579 | - if ( |
|
| 3580 | - in_array( $status_transition['from'], array( 'wpi-cancelled', 'wpi-pending', 'wpi-failed', 'wpi-refunded', 'wpi-onhold' ), true ) |
|
| 3581 | - && in_array( $status_transition['to'], array( 'publish', 'wpi-processing', 'wpi-renewal' ), true ) |
|
| 3582 | - ) { |
|
| 3583 | - do_action( 'getpaid_invoice_payment_status_changed', $this, $status_transition ); |
|
| 3584 | - } |
|
| 3585 | - |
|
| 3586 | - // Work out if this was for a payment reversal, and trigger a payment_status_reversed hook instead. |
|
| 3587 | - if ( |
|
| 3588 | - in_array( $status_transition['from'], array( 'publish', 'wpi-processing', 'wpi-renewal' ), true ) |
|
| 3589 | - && in_array( $status_transition['to'], array( 'wpi-cancelled', 'wpi-pending', 'wpi-failed', 'wpi-refunded', 'wpi-onhold' ), true ) |
|
| 3590 | - ) { |
|
| 3591 | - do_action( 'getpaid_invoice_payment_status_reversed', $this, $status_transition ); |
|
| 3592 | - } |
|
| 3593 | - } else { |
|
| 3594 | - /* translators: %s: new invoice status */ |
|
| 3595 | - $transition_note = sprintf( __( 'Status set to %s.', 'invoicing' ), wpinv_status_nicename( $status_transition['to'], $this ) ); |
|
| 3596 | - |
|
| 3597 | - // Note the transition occurred. |
|
| 3598 | - $this->add_note( trim( $status_transition['note'] . ' ' . $transition_note ), 0, $status_transition['manual'] ); |
|
| 3543 | + } |
|
| 3599 | 3544 | |
| 3600 | - } |
|
| 3601 | - } catch ( Exception $e ) { |
|
| 3602 | - $this->add_note( __( 'Error during status transition.', 'invoicing' ) . ' ' . $e->getMessage() ); |
|
| 3603 | - } |
|
| 3604 | - } |
|
| 3605 | - } |
|
| 3545 | + /** |
|
| 3546 | + * Handle the status transition. |
|
| 3547 | + */ |
|
| 3548 | + protected function status_transition() { |
|
| 3549 | + $status_transition = $this->status_transition; |
|
| 3550 | + |
|
| 3551 | + // Reset status transition variable. |
|
| 3552 | + $this->status_transition = false; |
|
| 3553 | + |
|
| 3554 | + if ( $status_transition ) { |
|
| 3555 | + try { |
|
| 3556 | + |
|
| 3557 | + // Fire a hook for the status change. |
|
| 3558 | + do_action( 'getpaid_invoice_status_' . $status_transition['to'], $this, $status_transition ); |
|
| 3559 | + |
|
| 3560 | + // @deprecated this is deprecated and will be removed in the future. |
|
| 3561 | + do_action( 'wpinv_status_' . $status_transition['to'], $this->get_id(), $status_transition['from'] ); |
|
| 3562 | + |
|
| 3563 | + if ( ! empty( $status_transition['from'] ) ) { |
|
| 3564 | + |
|
| 3565 | + /* translators: 1: old invoice status 2: new invoice status */ |
|
| 3566 | + $transition_note = sprintf( __( 'Status changed from %1$s to %2$s.', 'invoicing' ), wpinv_status_nicename( $status_transition['from'], $this ), wpinv_status_nicename( $status_transition['to'], $this ) ); |
|
| 3567 | + |
|
| 3568 | + // Fire another hook. |
|
| 3569 | + do_action( 'getpaid_invoice_status_' . $status_transition['from'] . '_to_' . $status_transition['to'], $this ); |
|
| 3570 | + do_action( 'getpaid_invoice_status_changed', $this, $status_transition['from'], $status_transition['to'] ); |
|
| 3571 | + |
|
| 3572 | + // @deprecated this is deprecated and will be removed in the future. |
|
| 3573 | + do_action( 'wpinv_status_' . $status_transition['from'] . '_to_' . $status_transition['to'], $this->get_id(), $status_transition['from'] ); |
|
| 3574 | + |
|
| 3575 | + // Note the transition occurred. |
|
| 3576 | + $this->add_note( trim( $status_transition['note'] . ' ' . $transition_note ), false, $status_transition['manual'] ); |
|
| 3577 | + |
|
| 3578 | + // Work out if this was for a payment, and trigger a payment_status hook instead. |
|
| 3579 | + if ( |
|
| 3580 | + in_array( $status_transition['from'], array( 'wpi-cancelled', 'wpi-pending', 'wpi-failed', 'wpi-refunded', 'wpi-onhold' ), true ) |
|
| 3581 | + && in_array( $status_transition['to'], array( 'publish', 'wpi-processing', 'wpi-renewal' ), true ) |
|
| 3582 | + ) { |
|
| 3583 | + do_action( 'getpaid_invoice_payment_status_changed', $this, $status_transition ); |
|
| 3584 | + } |
|
| 3585 | + |
|
| 3586 | + // Work out if this was for a payment reversal, and trigger a payment_status_reversed hook instead. |
|
| 3587 | + if ( |
|
| 3588 | + in_array( $status_transition['from'], array( 'publish', 'wpi-processing', 'wpi-renewal' ), true ) |
|
| 3589 | + && in_array( $status_transition['to'], array( 'wpi-cancelled', 'wpi-pending', 'wpi-failed', 'wpi-refunded', 'wpi-onhold' ), true ) |
|
| 3590 | + ) { |
|
| 3591 | + do_action( 'getpaid_invoice_payment_status_reversed', $this, $status_transition ); |
|
| 3592 | + } |
|
| 3593 | + } else { |
|
| 3594 | + /* translators: %s: new invoice status */ |
|
| 3595 | + $transition_note = sprintf( __( 'Status set to %s.', 'invoicing' ), wpinv_status_nicename( $status_transition['to'], $this ) ); |
|
| 3596 | + |
|
| 3597 | + // Note the transition occurred. |
|
| 3598 | + $this->add_note( trim( $status_transition['note'] . ' ' . $transition_note ), 0, $status_transition['manual'] ); |
|
| 3599 | + |
|
| 3600 | + } |
|
| 3601 | + } catch ( Exception $e ) { |
|
| 3602 | + $this->add_note( __( 'Error during status transition.', 'invoicing' ) . ' ' . $e->getMessage() ); |
|
| 3603 | + } |
|
| 3604 | + } |
|
| 3605 | + } |
|
| 3606 | 3606 | |
| 3607 | - /** |
|
| 3608 | - * Updates an invoice status. |
|
| 3609 | - */ |
|
| 3610 | - public function update_status( $new_status = false, $note = '', $manual = false ) { |
|
| 3607 | + /** |
|
| 3608 | + * Updates an invoice status. |
|
| 3609 | + */ |
|
| 3610 | + public function update_status( $new_status = false, $note = '', $manual = false ) { |
|
| 3611 | 3611 | |
| 3612 | - // Fires before updating a status. |
|
| 3613 | - do_action( 'wpinv_before_invoice_status_change', $this->get_id(), $new_status, $this->get_status( 'edit' ) ); |
|
| 3612 | + // Fires before updating a status. |
|
| 3613 | + do_action( 'wpinv_before_invoice_status_change', $this->get_id(), $new_status, $this->get_status( 'edit' ) ); |
|
| 3614 | 3614 | |
| 3615 | - // Update the status. |
|
| 3616 | - $this->set_status( $new_status, $note, $manual ); |
|
| 3615 | + // Update the status. |
|
| 3616 | + $this->set_status( $new_status, $note, $manual ); |
|
| 3617 | 3617 | |
| 3618 | - // Save the order. |
|
| 3619 | - return $this->save(); |
|
| 3618 | + // Save the order. |
|
| 3619 | + return $this->save(); |
|
| 3620 | 3620 | |
| 3621 | - } |
|
| 3621 | + } |
|
| 3622 | 3622 | |
| 3623 | - /** |
|
| 3624 | - * @deprecated |
|
| 3625 | - */ |
|
| 3626 | - public function refresh_item_ids() { |
|
| 3623 | + /** |
|
| 3624 | + * @deprecated |
|
| 3625 | + */ |
|
| 3626 | + public function refresh_item_ids() { |
|
| 3627 | 3627 | $item_ids = implode( ',', array_unique( array_keys( $this->get_items() ) ) ); |
| 3628 | 3628 | update_post_meta( $this->get_id(), '_wpinv_item_ids', $item_ids ); |
| 3629 | - } |
|
| 3629 | + } |
|
| 3630 | 3630 | |
| 3631 | - /** |
|
| 3632 | - * @deprecated |
|
| 3633 | - */ |
|
| 3634 | - public function update_items( $temp = false ) { |
|
| 3631 | + /** |
|
| 3632 | + * @deprecated |
|
| 3633 | + */ |
|
| 3634 | + public function update_items( $temp = false ) { |
|
| 3635 | 3635 | |
| 3636 | - $this->set_items( $this->get_items() ); |
|
| 3636 | + $this->set_items( $this->get_items() ); |
|
| 3637 | 3637 | |
| 3638 | - if ( ! $temp ) { |
|
| 3639 | - $this->save(); |
|
| 3640 | - } |
|
| 3638 | + if ( ! $temp ) { |
|
| 3639 | + $this->save(); |
|
| 3640 | + } |
|
| 3641 | 3641 | |
| 3642 | 3642 | return $this; |
| 3643 | - } |
|
| 3643 | + } |
|
| 3644 | 3644 | |
| 3645 | - /** |
|
| 3646 | - * @deprecated |
|
| 3647 | - */ |
|
| 3645 | + /** |
|
| 3646 | + * @deprecated |
|
| 3647 | + */ |
|
| 3648 | 3648 | public function validate_discount() { |
| 3649 | 3649 | |
| 3650 | 3650 | $discount_code = $this->get_discount_code(); |
@@ -3660,97 +3660,97 @@ discard block |
||
| 3660 | 3660 | |
| 3661 | 3661 | } |
| 3662 | 3662 | |
| 3663 | - /** |
|
| 3664 | - * Refunds an invoice. |
|
| 3665 | - */ |
|
| 3663 | + /** |
|
| 3664 | + * Refunds an invoice. |
|
| 3665 | + */ |
|
| 3666 | 3666 | public function refund() { |
| 3667 | - $this->set_status( 'wpi-refunded' ); |
|
| 3667 | + $this->set_status( 'wpi-refunded' ); |
|
| 3668 | 3668 | $this->save(); |
| 3669 | - } |
|
| 3669 | + } |
|
| 3670 | 3670 | |
| 3671 | - /** |
|
| 3672 | - * Marks an invoice as paid. |
|
| 3673 | - * |
|
| 3674 | - * @param string $transaction_id |
|
| 3675 | - */ |
|
| 3671 | + /** |
|
| 3672 | + * Marks an invoice as paid. |
|
| 3673 | + * |
|
| 3674 | + * @param string $transaction_id |
|
| 3675 | + */ |
|
| 3676 | 3676 | public function mark_paid( $transaction_id = null, $note = '' ) { |
| 3677 | 3677 | |
| 3678 | - // Set the transaction id. |
|
| 3679 | - if ( empty( $transaction_id ) ) { |
|
| 3680 | - $transaction_id = $this->generate_key('trans_'); |
|
| 3681 | - } |
|
| 3678 | + // Set the transaction id. |
|
| 3679 | + if ( empty( $transaction_id ) ) { |
|
| 3680 | + $transaction_id = $this->generate_key('trans_'); |
|
| 3681 | + } |
|
| 3682 | 3682 | |
| 3683 | - if ( ! $this->get_transaction_id() ) { |
|
| 3684 | - $this->set_transaction_id( $transaction_id ); |
|
| 3685 | - } |
|
| 3683 | + if ( ! $this->get_transaction_id() ) { |
|
| 3684 | + $this->set_transaction_id( $transaction_id ); |
|
| 3685 | + } |
|
| 3686 | 3686 | |
| 3687 | - if ( $this->is_paid() && 'wpi-processing' != $this->get_status() ) { |
|
| 3688 | - return $this->save(); |
|
| 3689 | - } |
|
| 3687 | + if ( $this->is_paid() && 'wpi-processing' != $this->get_status() ) { |
|
| 3688 | + return $this->save(); |
|
| 3689 | + } |
|
| 3690 | 3690 | |
| 3691 | - // Set the completed date. |
|
| 3692 | - $this->set_date_completed( current_time( 'mysql' ) ); |
|
| 3691 | + // Set the completed date. |
|
| 3692 | + $this->set_date_completed( current_time( 'mysql' ) ); |
|
| 3693 | 3693 | |
| 3694 | - // Set the new status. |
|
| 3695 | - if ( $this->is_renewal() ) { |
|
| 3694 | + // Set the new status. |
|
| 3695 | + if ( $this->is_renewal() ) { |
|
| 3696 | 3696 | |
| 3697 | - $_note = sprintf( |
|
| 3698 | - __( 'Renewed via %s', 'invoicing' ), |
|
| 3699 | - $this->get_gateway_title() . empty( $note ) ? '' : " ($note)" |
|
| 3700 | - ); |
|
| 3697 | + $_note = sprintf( |
|
| 3698 | + __( 'Renewed via %s', 'invoicing' ), |
|
| 3699 | + $this->get_gateway_title() . empty( $note ) ? '' : " ($note)" |
|
| 3700 | + ); |
|
| 3701 | 3701 | |
| 3702 | - if ( 'none' == $this->get_gateway() ) { |
|
| 3703 | - $_note = $note; |
|
| 3704 | - } |
|
| 3702 | + if ( 'none' == $this->get_gateway() ) { |
|
| 3703 | + $_note = $note; |
|
| 3704 | + } |
|
| 3705 | 3705 | |
| 3706 | - $this->set_status( 'wpi-renewal', $_note ); |
|
| 3706 | + $this->set_status( 'wpi-renewal', $_note ); |
|
| 3707 | 3707 | |
| 3708 | - } else { |
|
| 3708 | + } else { |
|
| 3709 | 3709 | |
| 3710 | - $_note = sprintf( |
|
| 3711 | - __( 'Paid via %s', 'invoicing' ), |
|
| 3712 | - $this->get_gateway_title() . empty( $note ) ? '' : " ($note)" |
|
| 3713 | - ); |
|
| 3710 | + $_note = sprintf( |
|
| 3711 | + __( 'Paid via %s', 'invoicing' ), |
|
| 3712 | + $this->get_gateway_title() . empty( $note ) ? '' : " ($note)" |
|
| 3713 | + ); |
|
| 3714 | 3714 | |
| 3715 | - if ( 'none' == $this->get_gateway() ) { |
|
| 3716 | - $_note = $note; |
|
| 3717 | - } |
|
| 3715 | + if ( 'none' == $this->get_gateway() ) { |
|
| 3716 | + $_note = $note; |
|
| 3717 | + } |
|
| 3718 | 3718 | |
| 3719 | - $this->set_status( 'publish',$_note ); |
|
| 3719 | + $this->set_status( 'publish',$_note ); |
|
| 3720 | 3720 | |
| 3721 | - } |
|
| 3721 | + } |
|
| 3722 | 3722 | |
| 3723 | - // Set checkout mode. |
|
| 3724 | - $mode = wpinv_is_test_mode( $this->get_gateway() ) ? 'test' : 'live'; |
|
| 3725 | - $this->set_mode( $mode ); |
|
| 3723 | + // Set checkout mode. |
|
| 3724 | + $mode = wpinv_is_test_mode( $this->get_gateway() ) ? 'test' : 'live'; |
|
| 3725 | + $this->set_mode( $mode ); |
|
| 3726 | 3726 | |
| 3727 | - // Save the invoice. |
|
| 3727 | + // Save the invoice. |
|
| 3728 | 3728 | $this->save(); |
| 3729 | - } |
|
| 3730 | - |
|
| 3731 | - |
|
| 3732 | - /** |
|
| 3733 | - * Save data to the database. |
|
| 3734 | - * |
|
| 3735 | - * @since 1.0.19 |
|
| 3736 | - * @return int invoice ID |
|
| 3737 | - */ |
|
| 3738 | - public function save() { |
|
| 3739 | - $this->maybe_set_date_paid(); |
|
| 3740 | - $this->maybe_set_key(); |
|
| 3741 | - parent::save(); |
|
| 3742 | - $this->clear_cache(); |
|
| 3743 | - $this->status_transition(); |
|
| 3744 | - return $this->get_id(); |
|
| 3745 | - } |
|
| 3746 | - |
|
| 3747 | - /** |
|
| 3729 | + } |
|
| 3730 | + |
|
| 3731 | + |
|
| 3732 | + /** |
|
| 3733 | + * Save data to the database. |
|
| 3734 | + * |
|
| 3735 | + * @since 1.0.19 |
|
| 3736 | + * @return int invoice ID |
|
| 3737 | + */ |
|
| 3738 | + public function save() { |
|
| 3739 | + $this->maybe_set_date_paid(); |
|
| 3740 | + $this->maybe_set_key(); |
|
| 3741 | + parent::save(); |
|
| 3742 | + $this->clear_cache(); |
|
| 3743 | + $this->status_transition(); |
|
| 3744 | + return $this->get_id(); |
|
| 3745 | + } |
|
| 3746 | + |
|
| 3747 | + /** |
|
| 3748 | 3748 | * Clears the subscription's cache. |
| 3749 | 3749 | */ |
| 3750 | 3750 | public function clear_cache() { |
| 3751 | - wp_cache_delete( $this->get_key(), 'getpaid_invoice_keys_to_invoice_ids' ); |
|
| 3752 | - wp_cache_delete( $this->get_number(), 'getpaid_invoice_numbers_to_invoice_ids' ); |
|
| 3753 | - wp_cache_delete( $this->get_transaction_id(), 'getpaid_invoice_transaction_ids_to_invoice_ids' ); |
|
| 3754 | - } |
|
| 3751 | + wp_cache_delete( $this->get_key(), 'getpaid_invoice_keys_to_invoice_ids' ); |
|
| 3752 | + wp_cache_delete( $this->get_number(), 'getpaid_invoice_numbers_to_invoice_ids' ); |
|
| 3753 | + wp_cache_delete( $this->get_transaction_id(), 'getpaid_invoice_transaction_ids_to_invoice_ids' ); |
|
| 3754 | + } |
|
| 3755 | 3755 | |
| 3756 | 3756 | } |
@@ -63,8 +63,8 @@ discard block |
||
| 63 | 63 | 'getpaid-nonce' |
| 64 | 64 | ) |
| 65 | 65 | ); |
| 66 | - $anchor = __( 'Deactivate', 'invoicing' ); |
|
| 67 | - $title = esc_attr__( 'Are you sure you want to deactivate this discount?', 'invoicing' ); |
|
| 66 | + $anchor = __( 'Deactivate', 'invoicing' ); |
|
| 67 | + $title = esc_attr__( 'Are you sure you want to deactivate this discount?', 'invoicing' ); |
|
| 68 | 68 | $row_actions['deactivate'] = "<a href='$url' onclick='return confirm(\"$title\")'>$anchor</a>"; |
| 69 | 69 | |
| 70 | 70 | } else if( in_array( strtolower( $discount->post_status ), array( 'pending', 'draft' ) ) ) { |
@@ -81,8 +81,8 @@ discard block |
||
| 81 | 81 | 'getpaid-nonce' |
| 82 | 82 | ) |
| 83 | 83 | ); |
| 84 | - $anchor = __( 'Activate', 'invoicing' ); |
|
| 85 | - $title = esc_attr__( 'Are you sure you want to activate this discount?', 'invoicing' ); |
|
| 84 | + $anchor = __( 'Activate', 'invoicing' ); |
|
| 85 | + $title = esc_attr__( 'Are you sure you want to activate this discount?', 'invoicing' ); |
|
| 86 | 86 | $row_actions['activate'] = "<a href='$url' onclick='return confirm(\"$title\")'>$anchor</a>"; |
| 87 | 87 | |
| 88 | 88 | } |
@@ -99,8 +99,8 @@ discard block |
||
| 99 | 99 | 'getpaid-nonce' |
| 100 | 100 | ) |
| 101 | 101 | ); |
| 102 | - $anchor = __( 'Delete', 'invoicing' ); |
|
| 103 | - $title = esc_attr__( 'Are you sure you want to delete this discount?', 'invoicing' ); |
|
| 102 | + $anchor = __( 'Delete', 'invoicing' ); |
|
| 103 | + $title = esc_attr__( 'Are you sure you want to delete this discount?', 'invoicing' ); |
|
| 104 | 104 | $row_actions['delete'] = "<a href='$url' onclick='return confirm(\"$title\")'>$anchor</a>"; |
| 105 | 105 | |
| 106 | 106 | $row_actions = apply_filters( 'wpinv_discount_row_actions', $row_actions, $discount ); |
@@ -13,617 +13,617 @@ discard block |
||
| 13 | 13 | class GetPaid_Post_Types_Admin { |
| 14 | 14 | |
| 15 | 15 | /** |
| 16 | - * Hook in methods. |
|
| 17 | - */ |
|
| 18 | - public static function init() { |
|
| 19 | - |
|
| 20 | - // Init metaboxes. |
|
| 21 | - GetPaid_Metaboxes::init(); |
|
| 22 | - |
|
| 23 | - // Filter the post updated messages. |
|
| 24 | - add_filter( 'post_updated_messages', 'GetPaid_Post_Types_Admin::post_updated_messages' ); |
|
| 25 | - |
|
| 26 | - // Filter post actions. |
|
| 27 | - add_filter( 'post_row_actions', 'GetPaid_Post_Types_Admin::post_row_actions', 10, 2 ); |
|
| 28 | - |
|
| 29 | - // Invoice table columns. |
|
| 30 | - add_filter( 'manage_wpi_invoice_posts_columns', array( __CLASS__, 'invoice_columns' ), 100 ); |
|
| 31 | - add_action( 'manage_wpi_invoice_posts_custom_column', array( __CLASS__, 'display_invoice_columns' ), 10, 2 ); |
|
| 32 | - |
|
| 33 | - // Items table columns. |
|
| 34 | - add_filter( 'manage_wpi_item_posts_columns', array( __CLASS__, 'item_columns' ), 100 ); |
|
| 35 | - add_filter( 'manage_edit-wpi_item_sortable_columns', array( __CLASS__, 'sortable_item_columns' ), 20 ); |
|
| 36 | - add_action( 'manage_wpi_item_posts_custom_column', array( __CLASS__, 'display_item_columns' ), 10, 2 ); |
|
| 37 | - add_action( 'restrict_manage_posts', array( __CLASS__, 'add_item_filters' ), 100 ); |
|
| 38 | - add_action( 'parse_query', array( __CLASS__, 'filter_item_query' ), 100 ); |
|
| 39 | - add_action( 'request', array( __CLASS__, 'reorder_items' ), 100 ); |
|
| 40 | - |
|
| 41 | - // Payment forms columns. |
|
| 42 | - add_filter( 'manage_wpi_payment_form_posts_columns', array( __CLASS__, 'payment_form_columns' ), 100 ); |
|
| 43 | - add_action( 'manage_wpi_payment_form_posts_custom_column', array( __CLASS__, 'display_payment_form_columns' ), 10, 2 ); |
|
| 44 | - add_filter( 'display_post_states', array( __CLASS__, 'filter_payment_form_state' ), 10, 2 ); |
|
| 45 | - |
|
| 46 | - // Discount table columns. |
|
| 47 | - add_filter( 'manage_wpi_discount_posts_columns', array( __CLASS__, 'discount_columns' ), 100 ); |
|
| 48 | - add_filter( 'bulk_actions-edit-wpi_discount', '__return_empty_array', 100 ); |
|
| 49 | - |
|
| 50 | - // Deleting posts. |
|
| 51 | - add_action( 'delete_post', array( __CLASS__, 'delete_post' ) ); |
|
| 52 | - add_filter( 'display_post_states', array( __CLASS__, 'filter_discount_state' ), 10, 2 ); |
|
| 53 | - } |
|
| 54 | - |
|
| 55 | - /** |
|
| 56 | - * Post updated messages. |
|
| 57 | - */ |
|
| 58 | - public static function post_updated_messages( $messages ) { |
|
| 59 | - global $post; |
|
| 60 | - |
|
| 61 | - $messages['wpi_discount'] = array( |
|
| 62 | - 0 => '', |
|
| 63 | - 1 => __( 'Discount updated.', 'invoicing' ), |
|
| 64 | - 2 => __( 'Custom field updated.', 'invoicing' ), |
|
| 65 | - 3 => __( 'Custom field deleted.', 'invoicing' ), |
|
| 66 | - 4 => __( 'Discount updated.', 'invoicing' ), |
|
| 67 | - 5 => isset( $_GET['revision'] ) ? wp_sprintf( __( 'Discount restored to revision from %s', 'invoicing' ), wp_post_revision_title( (int) $_GET['revision'], false ) ) : false, |
|
| 68 | - 6 => __( 'Discount updated.', 'invoicing' ), |
|
| 69 | - 7 => __( 'Discount saved.', 'invoicing' ), |
|
| 70 | - 8 => __( 'Discount submitted.', 'invoicing' ), |
|
| 71 | - 9 => wp_sprintf( __( 'Discount scheduled for: <strong>%1$s</strong>.', 'invoicing' ), date_i18n( __( 'M j, Y @ G:i', 'invoicing' ), strtotime( $post->post_date ) ) ), |
|
| 72 | - 10 => __( 'Discount draft updated.', 'invoicing' ), |
|
| 73 | - ); |
|
| 74 | - |
|
| 75 | - $messages['wpi_payment_form'] = array( |
|
| 76 | - 0 => '', |
|
| 77 | - 1 => __( 'Payment Form updated.', 'invoicing' ), |
|
| 78 | - 2 => __( 'Custom field updated.', 'invoicing' ), |
|
| 79 | - 3 => __( 'Custom field deleted.', 'invoicing' ), |
|
| 80 | - 4 => __( 'Payment Form updated.', 'invoicing' ), |
|
| 81 | - 5 => isset( $_GET['revision'] ) ? wp_sprintf( __( 'Payment Form restored to revision from %s', 'invoicing' ), wp_post_revision_title( (int) $_GET['revision'], false ) ) : false, |
|
| 82 | - 6 => __( 'Payment Form updated.', 'invoicing' ), |
|
| 83 | - 7 => __( 'Payment Form saved.', 'invoicing' ), |
|
| 84 | - 8 => __( 'Payment Form submitted.', 'invoicing' ), |
|
| 85 | - 9 => wp_sprintf( __( 'Payment Form scheduled for: <strong>%1$s</strong>.', 'invoicing' ), date_i18n( __( 'M j, Y @ G:i', 'invoicing' ), strtotime( $post->post_date ) ) ), |
|
| 86 | - 10 => __( 'Payment Form draft updated.', 'invoicing' ), |
|
| 87 | - ); |
|
| 88 | - |
|
| 89 | - return $messages; |
|
| 90 | - |
|
| 91 | - } |
|
| 92 | - |
|
| 93 | - /** |
|
| 94 | - * Post row actions. |
|
| 95 | - */ |
|
| 96 | - public static function post_row_actions( $actions, $post ) { |
|
| 97 | - |
|
| 98 | - $post = get_post( $post ); |
|
| 99 | - |
|
| 100 | - // We do not want to edit the default payment form. |
|
| 101 | - if ( 'wpi_payment_form' == $post->post_type && $post->ID == wpinv_get_default_payment_form() ) { |
|
| 102 | - unset( $actions['trash'] ); |
|
| 103 | - unset( $actions['inline hide-if-no-js'] ); |
|
| 104 | - } |
|
| 105 | - |
|
| 106 | - return $actions; |
|
| 107 | - } |
|
| 108 | - |
|
| 109 | - /** |
|
| 110 | - * Returns an array of invoice table columns. |
|
| 111 | - */ |
|
| 112 | - public static function invoice_columns( $columns ) { |
|
| 113 | - |
|
| 114 | - $columns = array( |
|
| 115 | - 'cb' => $columns['cb'], |
|
| 116 | - 'number' => __( 'Invoice', 'invoicing' ), |
|
| 117 | - 'customer' => __( 'Customer', 'invoicing' ), |
|
| 118 | - 'invoice_date' => __( 'Date', 'invoicing' ), |
|
| 119 | - 'amount' => __( 'Amount', 'invoicing' ), |
|
| 120 | - 'recurring' => __( 'Recurring', 'invoicing' ), |
|
| 121 | - 'status' => __( 'Status', 'invoicing' ), |
|
| 122 | - 'wpi_actions' => __( 'Actions', 'invoicing' ), |
|
| 123 | - ); |
|
| 124 | - |
|
| 125 | - return apply_filters( 'wpi_invoice_table_columns', $columns ); |
|
| 126 | - } |
|
| 127 | - |
|
| 128 | - /** |
|
| 129 | - * Displays invoice table columns. |
|
| 130 | - */ |
|
| 131 | - public static function display_invoice_columns( $column_name, $post_id ) { |
|
| 132 | - |
|
| 133 | - $invoice = new WPInv_Invoice( $post_id ); |
|
| 134 | - |
|
| 135 | - switch ( $column_name ) { |
|
| 136 | - |
|
| 137 | - case 'invoice_date' : |
|
| 138 | - $date_time = esc_attr( $invoice->get_created_date() ); |
|
| 139 | - $date = getpaid_format_date_value( $date_time ); |
|
| 140 | - echo "<span title='$date_time'>$date</span>"; |
|
| 141 | - break; |
|
| 142 | - |
|
| 143 | - case 'amount' : |
|
| 144 | - |
|
| 145 | - $amount = $invoice->get_total(); |
|
| 146 | - $formated_amount = wpinv_price( wpinv_format_amount( $amount ), $invoice->get_currency() ); |
|
| 147 | - |
|
| 148 | - if ( $invoice->is_refunded() ) { |
|
| 149 | - $refunded_amount = wpinv_price( wpinv_format_amount( 0 ), $invoice->get_currency() ); |
|
| 150 | - echo "<del>$formated_amount</del> <ins>$refunded_amount</ins>"; |
|
| 151 | - } else { |
|
| 152 | - |
|
| 153 | - $discount = $invoice->get_total_discount(); |
|
| 154 | - |
|
| 155 | - if ( ! empty( $discount ) ) { |
|
| 156 | - $new_amount = wpinv_price( wpinv_format_amount( $amount + $discount ), $invoice->get_currency() ); |
|
| 157 | - echo "<del>$new_amount</del> <ins>$formated_amount</ins>"; |
|
| 158 | - } else { |
|
| 159 | - echo $formated_amount; |
|
| 160 | - } |
|
| 161 | - |
|
| 162 | - } |
|
| 163 | - |
|
| 164 | - break; |
|
| 165 | - |
|
| 166 | - case 'status' : |
|
| 167 | - $status = sanitize_text_field( $invoice->get_status() ); |
|
| 168 | - $status_label = sanitize_text_field( $invoice->get_status_nicename() ); |
|
| 169 | - |
|
| 170 | - // If it is paid, show the gateway title. |
|
| 171 | - if ( $invoice->is_paid() ) { |
|
| 172 | - $gateway = sanitize_text_field( $invoice->get_gateway_title() ); |
|
| 173 | - $gateway = wp_sprintf( esc_attr__( 'Paid via %s', 'invoicing' ), $gateway ); |
|
| 16 | + * Hook in methods. |
|
| 17 | + */ |
|
| 18 | + public static function init() { |
|
| 174 | 19 | |
| 175 | - echo "<mark class='wpi-help-tip getpaid-invoice-status $status' title='$gateway'><span>$status_label</span></mark>"; |
|
| 176 | - } else { |
|
| 177 | - echo "<mark class='getpaid-invoice-status $status'><span>$status_label</span></mark>"; |
|
| 178 | - } |
|
| 20 | + // Init metaboxes. |
|
| 21 | + GetPaid_Metaboxes::init(); |
|
| 179 | 22 | |
| 180 | - // If it is not paid, display the overdue and view status. |
|
| 181 | - if ( ! $invoice->is_paid() && ! $invoice->is_refunded() ) { |
|
| 23 | + // Filter the post updated messages. |
|
| 24 | + add_filter( 'post_updated_messages', 'GetPaid_Post_Types_Admin::post_updated_messages' ); |
|
| 182 | 25 | |
| 183 | - // Invoice view status. |
|
| 184 | - if ( wpinv_is_invoice_viewed( $invoice->get_id() ) ) { |
|
| 185 | - echo ' <i class="fa fa-eye wpi-help-tip" title="'. esc_attr__( 'Viewed by Customer', 'invoicing' ).'"></i>'; |
|
| 186 | - } else { |
|
| 187 | - echo ' <i class="fa fa-eye-slash wpi-help-tip" title="'. esc_attr__( 'Not Viewed by Customer', 'invoicing' ).'"></i>'; |
|
| 188 | - } |
|
| 26 | + // Filter post actions. |
|
| 27 | + add_filter( 'post_row_actions', 'GetPaid_Post_Types_Admin::post_row_actions', 10, 2 ); |
|
| 189 | 28 | |
| 190 | - // Display the overview status. |
|
| 191 | - if ( wpinv_get_option( 'overdue_active' ) ) { |
|
| 192 | - $due_date = $invoice->get_due_date(); |
|
| 193 | - $fomatted = getpaid_format_date( $due_date ); |
|
| 29 | + // Invoice table columns. |
|
| 30 | + add_filter( 'manage_wpi_invoice_posts_columns', array( __CLASS__, 'invoice_columns' ), 100 ); |
|
| 31 | + add_action( 'manage_wpi_invoice_posts_custom_column', array( __CLASS__, 'display_invoice_columns' ), 10, 2 ); |
|
| 194 | 32 | |
| 195 | - if ( ! empty( $fomatted ) ) { |
|
| 196 | - $date = wp_sprintf( __( 'Due %s', 'invoicing' ), $fomatted ); |
|
| 197 | - echo "<p class='description' style='color: #888;' title='$due_date'>$fomatted</p>"; |
|
| 198 | - } |
|
| 199 | - } |
|
| 33 | + // Items table columns. |
|
| 34 | + add_filter( 'manage_wpi_item_posts_columns', array( __CLASS__, 'item_columns' ), 100 ); |
|
| 35 | + add_filter( 'manage_edit-wpi_item_sortable_columns', array( __CLASS__, 'sortable_item_columns' ), 20 ); |
|
| 36 | + add_action( 'manage_wpi_item_posts_custom_column', array( __CLASS__, 'display_item_columns' ), 10, 2 ); |
|
| 37 | + add_action( 'restrict_manage_posts', array( __CLASS__, 'add_item_filters' ), 100 ); |
|
| 38 | + add_action( 'parse_query', array( __CLASS__, 'filter_item_query' ), 100 ); |
|
| 39 | + add_action( 'request', array( __CLASS__, 'reorder_items' ), 100 ); |
|
| 200 | 40 | |
| 201 | - } |
|
| 41 | + // Payment forms columns. |
|
| 42 | + add_filter( 'manage_wpi_payment_form_posts_columns', array( __CLASS__, 'payment_form_columns' ), 100 ); |
|
| 43 | + add_action( 'manage_wpi_payment_form_posts_custom_column', array( __CLASS__, 'display_payment_form_columns' ), 10, 2 ); |
|
| 44 | + add_filter( 'display_post_states', array( __CLASS__, 'filter_payment_form_state' ), 10, 2 ); |
|
| 202 | 45 | |
| 203 | - break; |
|
| 46 | + // Discount table columns. |
|
| 47 | + add_filter( 'manage_wpi_discount_posts_columns', array( __CLASS__, 'discount_columns' ), 100 ); |
|
| 48 | + add_filter( 'bulk_actions-edit-wpi_discount', '__return_empty_array', 100 ); |
|
| 204 | 49 | |
| 205 | - case 'recurring': |
|
| 50 | + // Deleting posts. |
|
| 51 | + add_action( 'delete_post', array( __CLASS__, 'delete_post' ) ); |
|
| 52 | + add_filter( 'display_post_states', array( __CLASS__, 'filter_discount_state' ), 10, 2 ); |
|
| 53 | + } |
|
| 206 | 54 | |
| 207 | - if ( $invoice->is_recurring() ) { |
|
| 208 | - echo '<i class="fa fa-check" style="color:#43850a;"></i>'; |
|
| 209 | - } else { |
|
| 210 | - echo '<i class="fa fa-times" style="color:#616161;"></i>'; |
|
| 211 | - } |
|
| 212 | - break; |
|
| 55 | + /** |
|
| 56 | + * Post updated messages. |
|
| 57 | + */ |
|
| 58 | + public static function post_updated_messages( $messages ) { |
|
| 59 | + global $post; |
|
| 60 | + |
|
| 61 | + $messages['wpi_discount'] = array( |
|
| 62 | + 0 => '', |
|
| 63 | + 1 => __( 'Discount updated.', 'invoicing' ), |
|
| 64 | + 2 => __( 'Custom field updated.', 'invoicing' ), |
|
| 65 | + 3 => __( 'Custom field deleted.', 'invoicing' ), |
|
| 66 | + 4 => __( 'Discount updated.', 'invoicing' ), |
|
| 67 | + 5 => isset( $_GET['revision'] ) ? wp_sprintf( __( 'Discount restored to revision from %s', 'invoicing' ), wp_post_revision_title( (int) $_GET['revision'], false ) ) : false, |
|
| 68 | + 6 => __( 'Discount updated.', 'invoicing' ), |
|
| 69 | + 7 => __( 'Discount saved.', 'invoicing' ), |
|
| 70 | + 8 => __( 'Discount submitted.', 'invoicing' ), |
|
| 71 | + 9 => wp_sprintf( __( 'Discount scheduled for: <strong>%1$s</strong>.', 'invoicing' ), date_i18n( __( 'M j, Y @ G:i', 'invoicing' ), strtotime( $post->post_date ) ) ), |
|
| 72 | + 10 => __( 'Discount draft updated.', 'invoicing' ), |
|
| 73 | + ); |
|
| 74 | + |
|
| 75 | + $messages['wpi_payment_form'] = array( |
|
| 76 | + 0 => '', |
|
| 77 | + 1 => __( 'Payment Form updated.', 'invoicing' ), |
|
| 78 | + 2 => __( 'Custom field updated.', 'invoicing' ), |
|
| 79 | + 3 => __( 'Custom field deleted.', 'invoicing' ), |
|
| 80 | + 4 => __( 'Payment Form updated.', 'invoicing' ), |
|
| 81 | + 5 => isset( $_GET['revision'] ) ? wp_sprintf( __( 'Payment Form restored to revision from %s', 'invoicing' ), wp_post_revision_title( (int) $_GET['revision'], false ) ) : false, |
|
| 82 | + 6 => __( 'Payment Form updated.', 'invoicing' ), |
|
| 83 | + 7 => __( 'Payment Form saved.', 'invoicing' ), |
|
| 84 | + 8 => __( 'Payment Form submitted.', 'invoicing' ), |
|
| 85 | + 9 => wp_sprintf( __( 'Payment Form scheduled for: <strong>%1$s</strong>.', 'invoicing' ), date_i18n( __( 'M j, Y @ G:i', 'invoicing' ), strtotime( $post->post_date ) ) ), |
|
| 86 | + 10 => __( 'Payment Form draft updated.', 'invoicing' ), |
|
| 87 | + ); |
|
| 88 | + |
|
| 89 | + return $messages; |
|
| 90 | + |
|
| 91 | + } |
|
| 92 | + |
|
| 93 | + /** |
|
| 94 | + * Post row actions. |
|
| 95 | + */ |
|
| 96 | + public static function post_row_actions( $actions, $post ) { |
|
| 97 | + |
|
| 98 | + $post = get_post( $post ); |
|
| 99 | + |
|
| 100 | + // We do not want to edit the default payment form. |
|
| 101 | + if ( 'wpi_payment_form' == $post->post_type && $post->ID == wpinv_get_default_payment_form() ) { |
|
| 102 | + unset( $actions['trash'] ); |
|
| 103 | + unset( $actions['inline hide-if-no-js'] ); |
|
| 104 | + } |
|
| 105 | + |
|
| 106 | + return $actions; |
|
| 107 | + } |
|
| 108 | + |
|
| 109 | + /** |
|
| 110 | + * Returns an array of invoice table columns. |
|
| 111 | + */ |
|
| 112 | + public static function invoice_columns( $columns ) { |
|
| 113 | + |
|
| 114 | + $columns = array( |
|
| 115 | + 'cb' => $columns['cb'], |
|
| 116 | + 'number' => __( 'Invoice', 'invoicing' ), |
|
| 117 | + 'customer' => __( 'Customer', 'invoicing' ), |
|
| 118 | + 'invoice_date' => __( 'Date', 'invoicing' ), |
|
| 119 | + 'amount' => __( 'Amount', 'invoicing' ), |
|
| 120 | + 'recurring' => __( 'Recurring', 'invoicing' ), |
|
| 121 | + 'status' => __( 'Status', 'invoicing' ), |
|
| 122 | + 'wpi_actions' => __( 'Actions', 'invoicing' ), |
|
| 123 | + ); |
|
| 124 | + |
|
| 125 | + return apply_filters( 'wpi_invoice_table_columns', $columns ); |
|
| 126 | + } |
|
| 127 | + |
|
| 128 | + /** |
|
| 129 | + * Displays invoice table columns. |
|
| 130 | + */ |
|
| 131 | + public static function display_invoice_columns( $column_name, $post_id ) { |
|
| 132 | + |
|
| 133 | + $invoice = new WPInv_Invoice( $post_id ); |
|
| 134 | + |
|
| 135 | + switch ( $column_name ) { |
|
| 136 | + |
|
| 137 | + case 'invoice_date' : |
|
| 138 | + $date_time = esc_attr( $invoice->get_created_date() ); |
|
| 139 | + $date = getpaid_format_date_value( $date_time ); |
|
| 140 | + echo "<span title='$date_time'>$date</span>"; |
|
| 141 | + break; |
|
| 142 | + |
|
| 143 | + case 'amount' : |
|
| 144 | + |
|
| 145 | + $amount = $invoice->get_total(); |
|
| 146 | + $formated_amount = wpinv_price( wpinv_format_amount( $amount ), $invoice->get_currency() ); |
|
| 147 | + |
|
| 148 | + if ( $invoice->is_refunded() ) { |
|
| 149 | + $refunded_amount = wpinv_price( wpinv_format_amount( 0 ), $invoice->get_currency() ); |
|
| 150 | + echo "<del>$formated_amount</del> <ins>$refunded_amount</ins>"; |
|
| 151 | + } else { |
|
| 152 | + |
|
| 153 | + $discount = $invoice->get_total_discount(); |
|
| 154 | + |
|
| 155 | + if ( ! empty( $discount ) ) { |
|
| 156 | + $new_amount = wpinv_price( wpinv_format_amount( $amount + $discount ), $invoice->get_currency() ); |
|
| 157 | + echo "<del>$new_amount</del> <ins>$formated_amount</ins>"; |
|
| 158 | + } else { |
|
| 159 | + echo $formated_amount; |
|
| 160 | + } |
|
| 161 | + |
|
| 162 | + } |
|
| 163 | + |
|
| 164 | + break; |
|
| 165 | + |
|
| 166 | + case 'status' : |
|
| 167 | + $status = sanitize_text_field( $invoice->get_status() ); |
|
| 168 | + $status_label = sanitize_text_field( $invoice->get_status_nicename() ); |
|
| 169 | + |
|
| 170 | + // If it is paid, show the gateway title. |
|
| 171 | + if ( $invoice->is_paid() ) { |
|
| 172 | + $gateway = sanitize_text_field( $invoice->get_gateway_title() ); |
|
| 173 | + $gateway = wp_sprintf( esc_attr__( 'Paid via %s', 'invoicing' ), $gateway ); |
|
| 213 | 174 | |
| 214 | - case 'number' : |
|
| 175 | + echo "<mark class='wpi-help-tip getpaid-invoice-status $status' title='$gateway'><span>$status_label</span></mark>"; |
|
| 176 | + } else { |
|
| 177 | + echo "<mark class='getpaid-invoice-status $status'><span>$status_label</span></mark>"; |
|
| 178 | + } |
|
| 215 | 179 | |
| 216 | - $edit_link = esc_url( get_edit_post_link( $invoice->get_id() ) ); |
|
| 217 | - $invoice_number = sanitize_text_field( $invoice->get_number() ); |
|
| 218 | - $invoice_details = esc_attr__( 'View Invoice Details', 'invoicing' ); |
|
| 180 | + // If it is not paid, display the overdue and view status. |
|
| 181 | + if ( ! $invoice->is_paid() && ! $invoice->is_refunded() ) { |
|
| 219 | 182 | |
| 220 | - echo "<a href='$edit_link' title='$invoice_details'><strong>$invoice_number</strong></a>"; |
|
| 183 | + // Invoice view status. |
|
| 184 | + if ( wpinv_is_invoice_viewed( $invoice->get_id() ) ) { |
|
| 185 | + echo ' <i class="fa fa-eye wpi-help-tip" title="'. esc_attr__( 'Viewed by Customer', 'invoicing' ).'"></i>'; |
|
| 186 | + } else { |
|
| 187 | + echo ' <i class="fa fa-eye-slash wpi-help-tip" title="'. esc_attr__( 'Not Viewed by Customer', 'invoicing' ).'"></i>'; |
|
| 188 | + } |
|
| 221 | 189 | |
| 222 | - break; |
|
| 190 | + // Display the overview status. |
|
| 191 | + if ( wpinv_get_option( 'overdue_active' ) ) { |
|
| 192 | + $due_date = $invoice->get_due_date(); |
|
| 193 | + $fomatted = getpaid_format_date( $due_date ); |
|
| 223 | 194 | |
| 224 | - case 'customer' : |
|
| 195 | + if ( ! empty( $fomatted ) ) { |
|
| 196 | + $date = wp_sprintf( __( 'Due %s', 'invoicing' ), $fomatted ); |
|
| 197 | + echo "<p class='description' style='color: #888;' title='$due_date'>$fomatted</p>"; |
|
| 198 | + } |
|
| 199 | + } |
|
| 200 | + |
|
| 201 | + } |
|
| 202 | + |
|
| 203 | + break; |
|
| 204 | + |
|
| 205 | + case 'recurring': |
|
| 206 | + |
|
| 207 | + if ( $invoice->is_recurring() ) { |
|
| 208 | + echo '<i class="fa fa-check" style="color:#43850a;"></i>'; |
|
| 209 | + } else { |
|
| 210 | + echo '<i class="fa fa-times" style="color:#616161;"></i>'; |
|
| 211 | + } |
|
| 212 | + break; |
|
| 213 | + |
|
| 214 | + case 'number' : |
|
| 215 | + |
|
| 216 | + $edit_link = esc_url( get_edit_post_link( $invoice->get_id() ) ); |
|
| 217 | + $invoice_number = sanitize_text_field( $invoice->get_number() ); |
|
| 218 | + $invoice_details = esc_attr__( 'View Invoice Details', 'invoicing' ); |
|
| 219 | + |
|
| 220 | + echo "<a href='$edit_link' title='$invoice_details'><strong>$invoice_number</strong></a>"; |
|
| 221 | + |
|
| 222 | + break; |
|
| 223 | + |
|
| 224 | + case 'customer' : |
|
| 225 | 225 | |
| 226 | - $customer_name = $invoice->get_user_full_name(); |
|
| 226 | + $customer_name = $invoice->get_user_full_name(); |
|
| 227 | 227 | |
| 228 | - if ( empty( $customer_name ) ) { |
|
| 229 | - $customer_name = $invoice->get_email(); |
|
| 230 | - } |
|
| 228 | + if ( empty( $customer_name ) ) { |
|
| 229 | + $customer_name = $invoice->get_email(); |
|
| 230 | + } |
|
| 231 | 231 | |
| 232 | - if ( ! empty( $customer_name ) ) { |
|
| 233 | - $customer_details = esc_attr__( 'View Customer Details', 'invoicing' ); |
|
| 234 | - $view_link = esc_url( add_query_arg( 'user_id', $invoice->get_user_id(), admin_url( 'user-edit.php' ) ) ); |
|
| 235 | - echo "<a href='$view_link' title='$customer_details'><span>$customer_name</span></a>"; |
|
| 236 | - } else { |
|
| 237 | - echo '<div>—</div>'; |
|
| 238 | - } |
|
| 232 | + if ( ! empty( $customer_name ) ) { |
|
| 233 | + $customer_details = esc_attr__( 'View Customer Details', 'invoicing' ); |
|
| 234 | + $view_link = esc_url( add_query_arg( 'user_id', $invoice->get_user_id(), admin_url( 'user-edit.php' ) ) ); |
|
| 235 | + echo "<a href='$view_link' title='$customer_details'><span>$customer_name</span></a>"; |
|
| 236 | + } else { |
|
| 237 | + echo '<div>—</div>'; |
|
| 238 | + } |
|
| 239 | + |
|
| 240 | + break; |
|
| 241 | + |
|
| 242 | + case 'wpi_actions' : |
|
| 243 | + |
|
| 244 | + if ( $invoice->is_draft() ) { |
|
| 245 | + return; |
|
| 246 | + } |
|
| 247 | + |
|
| 248 | + $url = esc_url( $invoice->get_view_url() ); |
|
| 249 | + $print = esc_attr__( 'Print invoice', 'invoicing' ); |
|
| 250 | + echo " <a href='$url' title='$print' target='_blank' style='color:#757575'><i class='fa fa-print' style='font-size: 1.4em;'></i></a>"; |
|
| 251 | + |
|
| 252 | + $url = esc_url( |
|
| 253 | + wp_nonce_url( |
|
| 254 | + add_query_arg( |
|
| 255 | + array( |
|
| 256 | + 'getpaid-admin-action' => 'send_invoice', |
|
| 257 | + 'invoice_id' => $invoice->get_id() |
|
| 258 | + ) |
|
| 259 | + ), |
|
| 260 | + 'getpaid-nonce', |
|
| 261 | + 'getpaid-nonce' |
|
| 262 | + ) |
|
| 263 | + ); |
|
| 264 | + |
|
| 265 | + $send = esc_attr__( 'Send invoice to customer', 'invoicing' ); |
|
| 266 | + echo " <a href='$url' title='$send' style='color:#757575'><i class='fa fa-envelope' style='font-size: 1.4em;'></i></a>"; |
|
| 267 | + |
|
| 268 | + break; |
|
| 269 | + } |
|
| 239 | 270 | |
| 240 | - break; |
|
| 271 | + } |
|
| 241 | 272 | |
| 242 | - case 'wpi_actions' : |
|
| 243 | - |
|
| 244 | - if ( $invoice->is_draft() ) { |
|
| 245 | - return; |
|
| 246 | - } |
|
| 247 | - |
|
| 248 | - $url = esc_url( $invoice->get_view_url() ); |
|
| 249 | - $print = esc_attr__( 'Print invoice', 'invoicing' ); |
|
| 250 | - echo " <a href='$url' title='$print' target='_blank' style='color:#757575'><i class='fa fa-print' style='font-size: 1.4em;'></i></a>"; |
|
| 273 | + /** |
|
| 274 | + * Returns an array of payment forms table columns. |
|
| 275 | + */ |
|
| 276 | + public static function payment_form_columns( $columns ) { |
|
| 251 | 277 | |
| 252 | - $url = esc_url( |
|
| 253 | - wp_nonce_url( |
|
| 254 | - add_query_arg( |
|
| 255 | - array( |
|
| 256 | - 'getpaid-admin-action' => 'send_invoice', |
|
| 257 | - 'invoice_id' => $invoice->get_id() |
|
| 258 | - ) |
|
| 259 | - ), |
|
| 260 | - 'getpaid-nonce', |
|
| 261 | - 'getpaid-nonce' |
|
| 262 | - ) |
|
| 263 | - ); |
|
| 278 | + $columns = array( |
|
| 279 | + 'cb' => $columns['cb'], |
|
| 280 | + 'title' => __( 'Name', 'invoicing' ), |
|
| 281 | + 'shortcode' => __( 'Shortcode', 'invoicing' ), |
|
| 282 | + 'earnings' => __( 'Revenue', 'invoicing' ), |
|
| 283 | + 'refunds' => __( 'Refunded', 'invoicing' ), |
|
| 284 | + 'items' => __( 'Items', 'invoicing' ), |
|
| 285 | + 'date' => __( 'Date', 'invoicing' ), |
|
| 286 | + ); |
|
| 264 | 287 | |
| 265 | - $send = esc_attr__( 'Send invoice to customer', 'invoicing' ); |
|
| 266 | - echo " <a href='$url' title='$send' style='color:#757575'><i class='fa fa-envelope' style='font-size: 1.4em;'></i></a>"; |
|
| 288 | + return apply_filters( 'wpi_payment_form_table_columns', $columns ); |
|
| 267 | 289 | |
| 268 | - break; |
|
| 269 | - } |
|
| 290 | + } |
|
| 270 | 291 | |
| 271 | - } |
|
| 292 | + /** |
|
| 293 | + * Displays payment form table columns. |
|
| 294 | + */ |
|
| 295 | + public static function display_payment_form_columns( $column_name, $post_id ) { |
|
| 272 | 296 | |
| 273 | - /** |
|
| 274 | - * Returns an array of payment forms table columns. |
|
| 275 | - */ |
|
| 276 | - public static function payment_form_columns( $columns ) { |
|
| 297 | + // Retrieve the payment form. |
|
| 298 | + $form = new GetPaid_Payment_Form( $post_id ); |
|
| 277 | 299 | |
| 278 | - $columns = array( |
|
| 279 | - 'cb' => $columns['cb'], |
|
| 280 | - 'title' => __( 'Name', 'invoicing' ), |
|
| 281 | - 'shortcode' => __( 'Shortcode', 'invoicing' ), |
|
| 282 | - 'earnings' => __( 'Revenue', 'invoicing' ), |
|
| 283 | - 'refunds' => __( 'Refunded', 'invoicing' ), |
|
| 284 | - 'items' => __( 'Items', 'invoicing' ), |
|
| 285 | - 'date' => __( 'Date', 'invoicing' ), |
|
| 286 | - ); |
|
| 300 | + switch ( $column_name ) { |
|
| 287 | 301 | |
| 288 | - return apply_filters( 'wpi_payment_form_table_columns', $columns ); |
|
| 302 | + case 'earnings' : |
|
| 303 | + echo wpinv_price( wpinv_format_amount( $form->get_earned() ) ); |
|
| 304 | + break; |
|
| 289 | 305 | |
| 290 | - } |
|
| 306 | + case 'refunds' : |
|
| 307 | + echo wpinv_price( wpinv_format_amount( $form->get_refunded() ) ); |
|
| 308 | + break; |
|
| 291 | 309 | |
| 292 | - /** |
|
| 293 | - * Displays payment form table columns. |
|
| 294 | - */ |
|
| 295 | - public static function display_payment_form_columns( $column_name, $post_id ) { |
|
| 310 | + case 'refunds' : |
|
| 311 | + echo wpinv_price( wpinv_format_amount( $form->get_refunded() ) ); |
|
| 312 | + break; |
|
| 296 | 313 | |
| 297 | - // Retrieve the payment form. |
|
| 298 | - $form = new GetPaid_Payment_Form( $post_id ); |
|
| 314 | + case 'shortcode' : |
|
| 299 | 315 | |
| 300 | - switch ( $column_name ) { |
|
| 316 | + if ( $form->is_default() ) { |
|
| 317 | + echo '—'; |
|
| 318 | + } else { |
|
| 319 | + echo '<input onClick="this.select()" type="text" value="[getpaid form=' . esc_attr( $form->get_id() ) . ']" style="width: 100%;" readonly/>'; |
|
| 320 | + } |
|
| 301 | 321 | |
| 302 | - case 'earnings' : |
|
| 303 | - echo wpinv_price( wpinv_format_amount( $form->get_earned() ) ); |
|
| 304 | - break; |
|
| 322 | + break; |
|
| 305 | 323 | |
| 306 | - case 'refunds' : |
|
| 307 | - echo wpinv_price( wpinv_format_amount( $form->get_refunded() ) ); |
|
| 308 | - break; |
|
| 324 | + case 'items' : |
|
| 309 | 325 | |
| 310 | - case 'refunds' : |
|
| 311 | - echo wpinv_price( wpinv_format_amount( $form->get_refunded() ) ); |
|
| 312 | - break; |
|
| 326 | + $items = $form->get_items(); |
|
| 313 | 327 | |
| 314 | - case 'shortcode' : |
|
| 328 | + if ( $form->is_default() || empty( $items ) ) { |
|
| 329 | + echo '—'; |
|
| 330 | + return; |
|
| 331 | + } |
|
| 315 | 332 | |
| 316 | - if ( $form->is_default() ) { |
|
| 317 | - echo '—'; |
|
| 318 | - } else { |
|
| 319 | - echo '<input onClick="this.select()" type="text" value="[getpaid form=' . esc_attr( $form->get_id() ) . ']" style="width: 100%;" readonly/>'; |
|
| 320 | - } |
|
| 333 | + $_items = array(); |
|
| 321 | 334 | |
| 322 | - break; |
|
| 335 | + foreach ( $items as $item ) { |
|
| 336 | + $url = $item->get_edit_url(); |
|
| 323 | 337 | |
| 324 | - case 'items' : |
|
| 338 | + if ( empty( $url ) ) { |
|
| 339 | + $_items[] = sanitize_text_field( $item->get_name() ); |
|
| 340 | + } else { |
|
| 341 | + $_items[] = sprintf( |
|
| 342 | + '<a href="%s">%s</a>', |
|
| 343 | + esc_url( $url ), |
|
| 344 | + sanitize_text_field( $item->get_name() ) |
|
| 345 | + ); |
|
| 346 | + } |
|
| 325 | 347 | |
| 326 | - $items = $form->get_items(); |
|
| 348 | + } |
|
| 327 | 349 | |
| 328 | - if ( $form->is_default() || empty( $items ) ) { |
|
| 329 | - echo '—'; |
|
| 330 | - return; |
|
| 331 | - } |
|
| 350 | + echo implode( '<br>', $_items ); |
|
| 332 | 351 | |
| 333 | - $_items = array(); |
|
| 352 | + break; |
|
| 334 | 353 | |
| 335 | - foreach ( $items as $item ) { |
|
| 336 | - $url = $item->get_edit_url(); |
|
| 354 | + } |
|
| 337 | 355 | |
| 338 | - if ( empty( $url ) ) { |
|
| 339 | - $_items[] = sanitize_text_field( $item->get_name() ); |
|
| 340 | - } else { |
|
| 341 | - $_items[] = sprintf( |
|
| 342 | - '<a href="%s">%s</a>', |
|
| 343 | - esc_url( $url ), |
|
| 344 | - sanitize_text_field( $item->get_name() ) |
|
| 345 | - ); |
|
| 346 | - } |
|
| 356 | + } |
|
| 347 | 357 | |
| 348 | - } |
|
| 358 | + /** |
|
| 359 | + * Filters post states. |
|
| 360 | + */ |
|
| 361 | + public static function filter_payment_form_state( $post_states, $post ) { |
|
| 349 | 362 | |
| 350 | - echo implode( '<br>', $_items ); |
|
| 363 | + if ( 'wpi_payment_form' == $post->post_type && wpinv_get_default_payment_form() == $post->ID ) { |
|
| 364 | + $post_states[ 'default_form' ] = __( 'Default Payment Form', 'invoicing' ); |
|
| 365 | + } |
|
| 366 | + |
|
| 367 | + return $post_states; |
|
| 351 | 368 | |
| 352 | - break; |
|
| 369 | + } |
|
| 353 | 370 | |
| 354 | - } |
|
| 371 | + /** |
|
| 372 | + * Returns an array of coupon table columns. |
|
| 373 | + */ |
|
| 374 | + public static function discount_columns( $columns ) { |
|
| 375 | + |
|
| 376 | + $columns = array( |
|
| 377 | + 'cb' => $columns['cb'], |
|
| 378 | + 'title' => __( 'Name', 'invoicing' ), |
|
| 379 | + 'code' => __( 'Code', 'invoicing' ), |
|
| 380 | + 'amount' => __( 'Amount', 'invoicing' ), |
|
| 381 | + 'usage' => __( 'Usage / Limit', 'invoicing' ), |
|
| 382 | + 'start_date' => __( 'Start Date', 'invoicing' ), |
|
| 383 | + 'expiry_date' => __( 'Expiry Date', 'invoicing' ), |
|
| 384 | + ); |
|
| 385 | + |
|
| 386 | + return apply_filters( 'wpi_discount_table_columns', $columns ); |
|
| 387 | + } |
|
| 355 | 388 | |
| 356 | - } |
|
| 389 | + /** |
|
| 390 | + * Filters post states. |
|
| 391 | + */ |
|
| 392 | + public static function filter_discount_state( $post_states, $post ) { |
|
| 357 | 393 | |
| 358 | - /** |
|
| 359 | - * Filters post states. |
|
| 360 | - */ |
|
| 361 | - public static function filter_payment_form_state( $post_states, $post ) { |
|
| 394 | + if ( 'wpi_discount' == $post->post_type ) { |
|
| 362 | 395 | |
| 363 | - if ( 'wpi_payment_form' == $post->post_type && wpinv_get_default_payment_form() == $post->ID ) { |
|
| 364 | - $post_states[ 'default_form' ] = __( 'Default Payment Form', 'invoicing' ); |
|
| 365 | - } |
|
| 366 | - |
|
| 367 | - return $post_states; |
|
| 396 | + $discount = new WPInv_Discount( $post ); |
|
| 368 | 397 | |
| 369 | - } |
|
| 398 | + $status = $discount->is_expired() ? 'expired' : $discount->get_status(); |
|
| 370 | 399 | |
| 371 | - /** |
|
| 372 | - * Returns an array of coupon table columns. |
|
| 373 | - */ |
|
| 374 | - public static function discount_columns( $columns ) { |
|
| 400 | + if ( $status != 'publish' ) { |
|
| 401 | + return array( |
|
| 402 | + 'discount_status' => wpinv_discount_status( $status ), |
|
| 403 | + ); |
|
| 404 | + } |
|
| 375 | 405 | |
| 376 | - $columns = array( |
|
| 377 | - 'cb' => $columns['cb'], |
|
| 378 | - 'title' => __( 'Name', 'invoicing' ), |
|
| 379 | - 'code' => __( 'Code', 'invoicing' ), |
|
| 380 | - 'amount' => __( 'Amount', 'invoicing' ), |
|
| 381 | - 'usage' => __( 'Usage / Limit', 'invoicing' ), |
|
| 382 | - 'start_date' => __( 'Start Date', 'invoicing' ), |
|
| 383 | - 'expiry_date' => __( 'Expiry Date', 'invoicing' ), |
|
| 384 | - ); |
|
| 406 | + return array(); |
|
| 385 | 407 | |
| 386 | - return apply_filters( 'wpi_discount_table_columns', $columns ); |
|
| 387 | - } |
|
| 408 | + } |
|
| 388 | 409 | |
| 389 | - /** |
|
| 390 | - * Filters post states. |
|
| 391 | - */ |
|
| 392 | - public static function filter_discount_state( $post_states, $post ) { |
|
| 410 | + return $post_states; |
|
| 393 | 411 | |
| 394 | - if ( 'wpi_discount' == $post->post_type ) { |
|
| 412 | + } |
|
| 395 | 413 | |
| 396 | - $discount = new WPInv_Discount( $post ); |
|
| 414 | + /** |
|
| 415 | + * Returns an array of items table columns. |
|
| 416 | + */ |
|
| 417 | + public static function item_columns( $columns ) { |
|
| 418 | + global $wpinv_euvat; |
|
| 419 | + |
|
| 420 | + $columns = array( |
|
| 421 | + 'cb' => $columns['cb'], |
|
| 422 | + 'title' => __( 'Name', 'invoicing' ), |
|
| 423 | + 'price' => __( 'Price', 'invoicing' ), |
|
| 424 | + 'vat_rule' => __( 'VAT rule', 'invoicing' ), |
|
| 425 | + 'vat_class' => __( 'VAT class', 'invoicing' ), |
|
| 426 | + 'type' => __( 'Type', 'invoicing' ), |
|
| 427 | + 'shortcode' => __( 'Shortcode', 'invoicing' ), |
|
| 428 | + ); |
|
| 429 | + |
|
| 430 | + if ( ! $wpinv_euvat->allow_vat_rules() ) { |
|
| 431 | + unset( $columns['vat_rule'] ); |
|
| 432 | + } |
|
| 397 | 433 | |
| 398 | - $status = $discount->is_expired() ? 'expired' : $discount->get_status(); |
|
| 434 | + if ( ! $wpinv_euvat->allow_vat_classes() ) { |
|
| 435 | + unset( $columns['vat_class'] ); |
|
| 436 | + } |
|
| 399 | 437 | |
| 400 | - if ( $status != 'publish' ) { |
|
| 401 | - return array( |
|
| 402 | - 'discount_status' => wpinv_discount_status( $status ), |
|
| 403 | - ); |
|
| 404 | - } |
|
| 438 | + return apply_filters( 'wpi_item_table_columns', $columns ); |
|
| 439 | + } |
|
| 405 | 440 | |
| 406 | - return array(); |
|
| 441 | + /** |
|
| 442 | + * Returns an array of sortable items table columns. |
|
| 443 | + */ |
|
| 444 | + public static function sortable_item_columns( $columns ) { |
|
| 445 | + |
|
| 446 | + return array_merge( |
|
| 447 | + $columns, |
|
| 448 | + array( |
|
| 449 | + 'price' => 'price', |
|
| 450 | + 'vat_rule' => 'vat_rule', |
|
| 451 | + 'vat_class' => 'vat_class', |
|
| 452 | + 'type' => 'type', |
|
| 453 | + ) |
|
| 454 | + ); |
|
| 455 | + |
|
| 456 | + } |
|
| 407 | 457 | |
| 408 | - } |
|
| 458 | + /** |
|
| 459 | + * Displays items table columns. |
|
| 460 | + */ |
|
| 461 | + public static function display_item_columns( $column_name, $post_id ) { |
|
| 462 | + global $wpinv_euvat; |
|
| 409 | 463 | |
| 410 | - return $post_states; |
|
| 464 | + $item = new WPInv_Item( $post_id ); |
|
| 411 | 465 | |
| 412 | - } |
|
| 466 | + switch ( $column_name ) { |
|
| 413 | 467 | |
| 414 | - /** |
|
| 415 | - * Returns an array of items table columns. |
|
| 416 | - */ |
|
| 417 | - public static function item_columns( $columns ) { |
|
| 418 | - global $wpinv_euvat; |
|
| 468 | + case 'price' : |
|
| 419 | 469 | |
| 420 | - $columns = array( |
|
| 421 | - 'cb' => $columns['cb'], |
|
| 422 | - 'title' => __( 'Name', 'invoicing' ), |
|
| 423 | - 'price' => __( 'Price', 'invoicing' ), |
|
| 424 | - 'vat_rule' => __( 'VAT rule', 'invoicing' ), |
|
| 425 | - 'vat_class' => __( 'VAT class', 'invoicing' ), |
|
| 426 | - 'type' => __( 'Type', 'invoicing' ), |
|
| 427 | - 'shortcode' => __( 'Shortcode', 'invoicing' ), |
|
| 428 | - ); |
|
| 470 | + if ( ! $item->is_recurring() ) { |
|
| 471 | + echo $item->get_the_price(); |
|
| 472 | + break; |
|
| 473 | + } |
|
| 429 | 474 | |
| 430 | - if ( ! $wpinv_euvat->allow_vat_rules() ) { |
|
| 431 | - unset( $columns['vat_rule'] ); |
|
| 432 | - } |
|
| 475 | + $price = wp_sprintf( |
|
| 476 | + __( '%s / %s', 'invoicing' ), |
|
| 477 | + $item->get_the_price(), |
|
| 478 | + getpaid_get_subscription_period_label( $item->get_recurring_period(), $item->get_recurring_interval(), '' ) |
|
| 479 | + ); |
|
| 433 | 480 | |
| 434 | - if ( ! $wpinv_euvat->allow_vat_classes() ) { |
|
| 435 | - unset( $columns['vat_class'] ); |
|
| 436 | - } |
|
| 481 | + if ( $item->get_the_price() == $item->get_the_initial_price() ) { |
|
| 482 | + echo $price; |
|
| 483 | + break; |
|
| 484 | + } |
|
| 437 | 485 | |
| 438 | - return apply_filters( 'wpi_item_table_columns', $columns ); |
|
| 439 | - } |
|
| 486 | + echo $item->get_the_initial_price(); |
|
| 440 | 487 | |
| 441 | - /** |
|
| 442 | - * Returns an array of sortable items table columns. |
|
| 443 | - */ |
|
| 444 | - public static function sortable_item_columns( $columns ) { |
|
| 488 | + echo '<span class="meta">' . wp_sprintf( __( 'then %s', 'invoicing' ), $price ) .'</span>'; |
|
| 489 | + break; |
|
| 445 | 490 | |
| 446 | - return array_merge( |
|
| 447 | - $columns, |
|
| 448 | - array( |
|
| 449 | - 'price' => 'price', |
|
| 450 | - 'vat_rule' => 'vat_rule', |
|
| 451 | - 'vat_class' => 'vat_class', |
|
| 452 | - 'type' => 'type', |
|
| 453 | - ) |
|
| 454 | - ); |
|
| 491 | + case 'vat_rule' : |
|
| 492 | + echo $wpinv_euvat->item_rule_label( $item->get_id() ); |
|
| 493 | + break; |
|
| 455 | 494 | |
| 456 | - } |
|
| 495 | + case 'vat_class' : |
|
| 496 | + echo $wpinv_euvat->item_class_label( $item->get_id() ); |
|
| 497 | + break; |
|
| 457 | 498 | |
| 458 | - /** |
|
| 459 | - * Displays items table columns. |
|
| 460 | - */ |
|
| 461 | - public static function display_item_columns( $column_name, $post_id ) { |
|
| 462 | - global $wpinv_euvat; |
|
| 499 | + case 'shortcode' : |
|
| 500 | + echo '<input onClick="this.select()" type="text" value="[getpaid item=' . esc_attr( $item->get_id() ) . ' button=\'Buy Now\']" style="width: 100%;" readonly/>'; |
|
| 501 | + break; |
|
| 463 | 502 | |
| 464 | - $item = new WPInv_Item( $post_id ); |
|
| 503 | + case 'type' : |
|
| 504 | + echo wpinv_item_type( $item->get_id() ) . '<span class="meta">' . $item->get_custom_singular_name() . '</span>'; |
|
| 505 | + break; |
|
| 465 | 506 | |
| 466 | - switch ( $column_name ) { |
|
| 507 | + } |
|
| 467 | 508 | |
| 468 | - case 'price' : |
|
| 509 | + } |
|
| 469 | 510 | |
| 470 | - if ( ! $item->is_recurring() ) { |
|
| 471 | - echo $item->get_the_price(); |
|
| 472 | - break; |
|
| 473 | - } |
|
| 511 | + /** |
|
| 512 | + * Lets users filter items using taxes. |
|
| 513 | + */ |
|
| 514 | + public static function add_item_filters( $post_type ) { |
|
| 515 | + $wpinv_euvat = getpaid_tax(); |
|
| 516 | + |
|
| 517 | + // Abort if we're not dealing with items. |
|
| 518 | + if ( $post_type != 'wpi_item' ) { |
|
| 519 | + return; |
|
| 520 | + } |
|
| 521 | + |
|
| 522 | + // Filter by vat rules. |
|
| 523 | + if ( $wpinv_euvat->allow_vat_rules() ) { |
|
| 524 | + |
|
| 525 | + // Sanitize selected vat rule. |
|
| 526 | + $vat_rule = ''; |
|
| 527 | + $vat_rules = $wpinv_euvat->get_rules(); |
|
| 528 | + if ( isset( $_GET['vat_rule'] ) ) { |
|
| 529 | + $vat_rule = $_GET['vat_rule']; |
|
| 530 | + } |
|
| 531 | + |
|
| 532 | + // Filter by VAT rule. |
|
| 533 | + echo wpinv_html_select( |
|
| 534 | + array( |
|
| 535 | + 'options' => array_merge( |
|
| 536 | + array( |
|
| 537 | + '' => __( 'All VAT rules', 'invoicing' ) |
|
| 538 | + ), |
|
| 539 | + $vat_rules |
|
| 540 | + ), |
|
| 541 | + 'name' => 'vat_rule', |
|
| 542 | + 'id' => 'vat_rule', |
|
| 543 | + 'selected' => in_array( $vat_rule, array_keys( $vat_rules ) ) ? $vat_rule : '', |
|
| 544 | + 'show_option_all' => false, |
|
| 545 | + 'show_option_none' => false, |
|
| 546 | + 'class' => 'gdmbx2-text-medium', |
|
| 547 | + ) |
|
| 548 | + ); |
|
| 549 | + |
|
| 550 | + // Filter by VAT class. |
|
| 551 | + } |
|
| 474 | 552 | |
| 475 | - $price = wp_sprintf( |
|
| 476 | - __( '%s / %s', 'invoicing' ), |
|
| 477 | - $item->get_the_price(), |
|
| 478 | - getpaid_get_subscription_period_label( $item->get_recurring_period(), $item->get_recurring_interval(), '' ) |
|
| 479 | - ); |
|
| 553 | + // Filter by vat class. |
|
| 554 | + if ( $wpinv_euvat->allow_vat_classes() ) { |
|
| 555 | + |
|
| 556 | + // Sanitize selected vat rule. |
|
| 557 | + $vat_class = ''; |
|
| 558 | + $vat_classes = $wpinv_euvat->get_all_classes(); |
|
| 559 | + if ( isset( $_GET['vat_class'] ) ) { |
|
| 560 | + $vat_class = $_GET['vat_class']; |
|
| 561 | + } |
|
| 562 | + |
|
| 563 | + echo wpinv_html_select( |
|
| 564 | + array( |
|
| 565 | + 'options' => array_merge( |
|
| 566 | + array( |
|
| 567 | + '' => __( 'All VAT classes', 'invoicing' ) |
|
| 568 | + ), |
|
| 569 | + $vat_classes |
|
| 570 | + ), |
|
| 571 | + 'name' => 'vat_class', |
|
| 572 | + 'id' => 'vat_class', |
|
| 573 | + 'selected' => in_array( $vat_class, array_keys( $vat_classes ) ) ? $vat_class : '', |
|
| 574 | + 'show_option_all' => false, |
|
| 575 | + 'show_option_none' => false, |
|
| 576 | + 'class' => 'gdmbx2-text-medium', |
|
| 577 | + ) |
|
| 578 | + ); |
|
| 480 | 579 | |
| 481 | - if ( $item->get_the_price() == $item->get_the_initial_price() ) { |
|
| 482 | - echo $price; |
|
| 483 | - break; |
|
| 484 | - } |
|
| 580 | + } |
|
| 485 | 581 | |
| 486 | - echo $item->get_the_initial_price(); |
|
| 582 | + // Filter by item type. |
|
| 583 | + $type = ''; |
|
| 584 | + if ( isset( $_GET['type'] ) ) { |
|
| 585 | + $type = $_GET['type']; |
|
| 586 | + } |
|
| 487 | 587 | |
| 488 | - echo '<span class="meta">' . wp_sprintf( __( 'then %s', 'invoicing' ), $price ) .'</span>'; |
|
| 489 | - break; |
|
| 588 | + echo wpinv_html_select( |
|
| 589 | + array( |
|
| 590 | + 'options' => array_merge( |
|
| 591 | + array( |
|
| 592 | + '' => __( 'All item types', 'invoicing' ) |
|
| 593 | + ), |
|
| 594 | + wpinv_get_item_types() |
|
| 595 | + ), |
|
| 596 | + 'name' => 'type', |
|
| 597 | + 'id' => 'type', |
|
| 598 | + 'selected' => in_array( $type, wpinv_item_types() ) ? $type : '', |
|
| 599 | + 'show_option_all' => false, |
|
| 600 | + 'show_option_none' => false, |
|
| 601 | + 'class' => 'gdmbx2-text-medium', |
|
| 602 | + ) |
|
| 603 | + ); |
|
| 604 | + |
|
| 605 | + } |
|
| 490 | 606 | |
| 491 | - case 'vat_rule' : |
|
| 492 | - echo $wpinv_euvat->item_rule_label( $item->get_id() ); |
|
| 493 | - break; |
|
| 607 | + /** |
|
| 608 | + * Filters the item query. |
|
| 609 | + */ |
|
| 610 | + public static function filter_item_query( $query ) { |
|
| 494 | 611 | |
| 495 | - case 'vat_class' : |
|
| 496 | - echo $wpinv_euvat->item_class_label( $item->get_id() ); |
|
| 497 | - break; |
|
| 612 | + // modify the query only if it admin and main query. |
|
| 613 | + if ( ! ( is_admin() && $query->is_main_query() ) ){ |
|
| 614 | + return $query; |
|
| 615 | + } |
|
| 498 | 616 | |
| 499 | - case 'shortcode' : |
|
| 500 | - echo '<input onClick="this.select()" type="text" value="[getpaid item=' . esc_attr( $item->get_id() ) . ' button=\'Buy Now\']" style="width: 100%;" readonly/>'; |
|
| 501 | - break; |
|
| 617 | + // we want to modify the query for our items. |
|
| 618 | + if ( 'wpi_item' != $query->query['post_type'] ){ |
|
| 619 | + return $query; |
|
| 620 | + } |
|
| 502 | 621 | |
| 503 | - case 'type' : |
|
| 504 | - echo wpinv_item_type( $item->get_id() ) . '<span class="meta">' . $item->get_custom_singular_name() . '</span>'; |
|
| 505 | - break; |
|
| 622 | + if ( empty( $query->query_vars['meta_query'] ) ) { |
|
| 623 | + $query->query_vars['meta_query'] = array(); |
|
| 624 | + } |
|
| 506 | 625 | |
| 507 | - } |
|
| 508 | - |
|
| 509 | - } |
|
| 510 | - |
|
| 511 | - /** |
|
| 512 | - * Lets users filter items using taxes. |
|
| 513 | - */ |
|
| 514 | - public static function add_item_filters( $post_type ) { |
|
| 515 | - $wpinv_euvat = getpaid_tax(); |
|
| 516 | - |
|
| 517 | - // Abort if we're not dealing with items. |
|
| 518 | - if ( $post_type != 'wpi_item' ) { |
|
| 519 | - return; |
|
| 520 | - } |
|
| 521 | - |
|
| 522 | - // Filter by vat rules. |
|
| 523 | - if ( $wpinv_euvat->allow_vat_rules() ) { |
|
| 524 | - |
|
| 525 | - // Sanitize selected vat rule. |
|
| 526 | - $vat_rule = ''; |
|
| 527 | - $vat_rules = $wpinv_euvat->get_rules(); |
|
| 528 | - if ( isset( $_GET['vat_rule'] ) ) { |
|
| 529 | - $vat_rule = $_GET['vat_rule']; |
|
| 530 | - } |
|
| 531 | - |
|
| 532 | - // Filter by VAT rule. |
|
| 533 | - echo wpinv_html_select( |
|
| 534 | - array( |
|
| 535 | - 'options' => array_merge( |
|
| 536 | - array( |
|
| 537 | - '' => __( 'All VAT rules', 'invoicing' ) |
|
| 538 | - ), |
|
| 539 | - $vat_rules |
|
| 540 | - ), |
|
| 541 | - 'name' => 'vat_rule', |
|
| 542 | - 'id' => 'vat_rule', |
|
| 543 | - 'selected' => in_array( $vat_rule, array_keys( $vat_rules ) ) ? $vat_rule : '', |
|
| 544 | - 'show_option_all' => false, |
|
| 545 | - 'show_option_none' => false, |
|
| 546 | - 'class' => 'gdmbx2-text-medium', |
|
| 547 | - ) |
|
| 548 | - ); |
|
| 549 | - |
|
| 550 | - // Filter by VAT class. |
|
| 551 | - } |
|
| 552 | - |
|
| 553 | - // Filter by vat class. |
|
| 554 | - if ( $wpinv_euvat->allow_vat_classes() ) { |
|
| 555 | - |
|
| 556 | - // Sanitize selected vat rule. |
|
| 557 | - $vat_class = ''; |
|
| 558 | - $vat_classes = $wpinv_euvat->get_all_classes(); |
|
| 559 | - if ( isset( $_GET['vat_class'] ) ) { |
|
| 560 | - $vat_class = $_GET['vat_class']; |
|
| 561 | - } |
|
| 562 | - |
|
| 563 | - echo wpinv_html_select( |
|
| 564 | - array( |
|
| 565 | - 'options' => array_merge( |
|
| 566 | - array( |
|
| 567 | - '' => __( 'All VAT classes', 'invoicing' ) |
|
| 568 | - ), |
|
| 569 | - $vat_classes |
|
| 570 | - ), |
|
| 571 | - 'name' => 'vat_class', |
|
| 572 | - 'id' => 'vat_class', |
|
| 573 | - 'selected' => in_array( $vat_class, array_keys( $vat_classes ) ) ? $vat_class : '', |
|
| 574 | - 'show_option_all' => false, |
|
| 575 | - 'show_option_none' => false, |
|
| 576 | - 'class' => 'gdmbx2-text-medium', |
|
| 577 | - ) |
|
| 578 | - ); |
|
| 579 | - |
|
| 580 | - } |
|
| 581 | - |
|
| 582 | - // Filter by item type. |
|
| 583 | - $type = ''; |
|
| 584 | - if ( isset( $_GET['type'] ) ) { |
|
| 585 | - $type = $_GET['type']; |
|
| 586 | - } |
|
| 587 | - |
|
| 588 | - echo wpinv_html_select( |
|
| 589 | - array( |
|
| 590 | - 'options' => array_merge( |
|
| 591 | - array( |
|
| 592 | - '' => __( 'All item types', 'invoicing' ) |
|
| 593 | - ), |
|
| 594 | - wpinv_get_item_types() |
|
| 595 | - ), |
|
| 596 | - 'name' => 'type', |
|
| 597 | - 'id' => 'type', |
|
| 598 | - 'selected' => in_array( $type, wpinv_item_types() ) ? $type : '', |
|
| 599 | - 'show_option_all' => false, |
|
| 600 | - 'show_option_none' => false, |
|
| 601 | - 'class' => 'gdmbx2-text-medium', |
|
| 602 | - ) |
|
| 603 | - ); |
|
| 604 | - |
|
| 605 | - } |
|
| 606 | - |
|
| 607 | - /** |
|
| 608 | - * Filters the item query. |
|
| 609 | - */ |
|
| 610 | - public static function filter_item_query( $query ) { |
|
| 611 | - |
|
| 612 | - // modify the query only if it admin and main query. |
|
| 613 | - if ( ! ( is_admin() && $query->is_main_query() ) ){ |
|
| 614 | - return $query; |
|
| 615 | - } |
|
| 616 | - |
|
| 617 | - // we want to modify the query for our items. |
|
| 618 | - if ( 'wpi_item' != $query->query['post_type'] ){ |
|
| 619 | - return $query; |
|
| 620 | - } |
|
| 621 | - |
|
| 622 | - if ( empty( $query->query_vars['meta_query'] ) ) { |
|
| 623 | - $query->query_vars['meta_query'] = array(); |
|
| 624 | - } |
|
| 625 | - |
|
| 626 | - // Filter vat rule type |
|
| 626 | + // Filter vat rule type |
|
| 627 | 627 | if ( ! empty( $_GET['vat_rule'] ) ) { |
| 628 | 628 | $query->query_vars['meta_query'][] = array( |
| 629 | 629 | 'key' => '_wpinv_vat_rule', |
@@ -648,94 +648,94 @@ discard block |
||
| 648 | 648 | 'value' => sanitize_text_field( $_GET['type'] ), |
| 649 | 649 | 'compare' => '=' |
| 650 | 650 | ); |
| 651 | - } |
|
| 652 | - |
|
| 653 | - } |
|
| 654 | - |
|
| 655 | - /** |
|
| 656 | - * Reorders items. |
|
| 657 | - */ |
|
| 658 | - public static function reorder_items( $vars ) { |
|
| 659 | - global $typenow; |
|
| 660 | - |
|
| 661 | - if ( 'wpi_item' !== $typenow || empty( $vars['orderby'] ) ) { |
|
| 662 | - return $vars; |
|
| 663 | - } |
|
| 664 | - |
|
| 665 | - // By item type. |
|
| 666 | - if ( 'type' == $vars['orderby'] ) { |
|
| 667 | - return array_merge( |
|
| 668 | - $vars, |
|
| 669 | - array( |
|
| 670 | - 'meta_key' => '_wpinv_type', |
|
| 671 | - 'orderby' => 'meta_value' |
|
| 672 | - ) |
|
| 673 | - ); |
|
| 674 | - } |
|
| 675 | - |
|
| 676 | - // By vat class. |
|
| 677 | - if ( 'vat_class' == $vars['orderby'] ) { |
|
| 678 | - return array_merge( |
|
| 679 | - $vars, |
|
| 680 | - array( |
|
| 681 | - 'meta_key' => '_wpinv_vat_class', |
|
| 682 | - 'orderby' => 'meta_value' |
|
| 683 | - ) |
|
| 684 | - ); |
|
| 685 | - } |
|
| 686 | - |
|
| 687 | - // By vat rule. |
|
| 688 | - if ( 'vat_rule' == $vars['orderby'] ) { |
|
| 689 | - return array_merge( |
|
| 690 | - $vars, |
|
| 691 | - array( |
|
| 692 | - 'meta_key' => '_wpinv_vat_rule', |
|
| 693 | - 'orderby' => 'meta_value' |
|
| 694 | - ) |
|
| 695 | - ); |
|
| 696 | - } |
|
| 697 | - |
|
| 698 | - // By price. |
|
| 699 | - if ( 'price' == $vars['orderby'] ) { |
|
| 700 | - return array_merge( |
|
| 701 | - $vars, |
|
| 702 | - array( |
|
| 703 | - 'meta_key' => '_wpinv_price', |
|
| 704 | - 'orderby' => 'meta_value_num' |
|
| 705 | - ) |
|
| 706 | - ); |
|
| 707 | - } |
|
| 708 | - |
|
| 709 | - return $vars; |
|
| 710 | - |
|
| 711 | - } |
|
| 712 | - |
|
| 713 | - /** |
|
| 714 | - * Fired when deleting a post. |
|
| 715 | - */ |
|
| 716 | - public static function delete_post( $post_id ) { |
|
| 717 | - |
|
| 718 | - switch ( get_post_type( $post_id ) ) { |
|
| 719 | - |
|
| 720 | - case 'wpi_item' : |
|
| 721 | - do_action( "getpaid_before_delete_item", new WPInv_Item( $post_id ) ); |
|
| 722 | - break; |
|
| 723 | - |
|
| 724 | - case 'wpi_payment_form' : |
|
| 725 | - do_action( "getpaid_before_delete_payment_form", new GetPaid_Payment_Form( $post_id ) ); |
|
| 726 | - break; |
|
| 727 | - |
|
| 728 | - case 'wpi_discount' : |
|
| 729 | - do_action( "getpaid_before_delete_discount", new WPInv_Discount( $post_id ) ); |
|
| 730 | - break; |
|
| 731 | - |
|
| 732 | - case 'wpi_invoice' : |
|
| 733 | - $invoice = new WPInv_Invoice( $post_id ); |
|
| 734 | - do_action( "getpaid_before_delete_invoice", $invoice ); |
|
| 735 | - $invoice->get_data_store()->delete_items( $invoice ); |
|
| 736 | - $invoice->get_data_store()->delete_special_fields( $invoice ); |
|
| 737 | - break; |
|
| 738 | - } |
|
| 739 | - } |
|
| 651 | + } |
|
| 652 | + |
|
| 653 | + } |
|
| 654 | + |
|
| 655 | + /** |
|
| 656 | + * Reorders items. |
|
| 657 | + */ |
|
| 658 | + public static function reorder_items( $vars ) { |
|
| 659 | + global $typenow; |
|
| 660 | + |
|
| 661 | + if ( 'wpi_item' !== $typenow || empty( $vars['orderby'] ) ) { |
|
| 662 | + return $vars; |
|
| 663 | + } |
|
| 664 | + |
|
| 665 | + // By item type. |
|
| 666 | + if ( 'type' == $vars['orderby'] ) { |
|
| 667 | + return array_merge( |
|
| 668 | + $vars, |
|
| 669 | + array( |
|
| 670 | + 'meta_key' => '_wpinv_type', |
|
| 671 | + 'orderby' => 'meta_value' |
|
| 672 | + ) |
|
| 673 | + ); |
|
| 674 | + } |
|
| 675 | + |
|
| 676 | + // By vat class. |
|
| 677 | + if ( 'vat_class' == $vars['orderby'] ) { |
|
| 678 | + return array_merge( |
|
| 679 | + $vars, |
|
| 680 | + array( |
|
| 681 | + 'meta_key' => '_wpinv_vat_class', |
|
| 682 | + 'orderby' => 'meta_value' |
|
| 683 | + ) |
|
| 684 | + ); |
|
| 685 | + } |
|
| 686 | + |
|
| 687 | + // By vat rule. |
|
| 688 | + if ( 'vat_rule' == $vars['orderby'] ) { |
|
| 689 | + return array_merge( |
|
| 690 | + $vars, |
|
| 691 | + array( |
|
| 692 | + 'meta_key' => '_wpinv_vat_rule', |
|
| 693 | + 'orderby' => 'meta_value' |
|
| 694 | + ) |
|
| 695 | + ); |
|
| 696 | + } |
|
| 697 | + |
|
| 698 | + // By price. |
|
| 699 | + if ( 'price' == $vars['orderby'] ) { |
|
| 700 | + return array_merge( |
|
| 701 | + $vars, |
|
| 702 | + array( |
|
| 703 | + 'meta_key' => '_wpinv_price', |
|
| 704 | + 'orderby' => 'meta_value_num' |
|
| 705 | + ) |
|
| 706 | + ); |
|
| 707 | + } |
|
| 708 | + |
|
| 709 | + return $vars; |
|
| 710 | + |
|
| 711 | + } |
|
| 712 | + |
|
| 713 | + /** |
|
| 714 | + * Fired when deleting a post. |
|
| 715 | + */ |
|
| 716 | + public static function delete_post( $post_id ) { |
|
| 717 | + |
|
| 718 | + switch ( get_post_type( $post_id ) ) { |
|
| 719 | + |
|
| 720 | + case 'wpi_item' : |
|
| 721 | + do_action( "getpaid_before_delete_item", new WPInv_Item( $post_id ) ); |
|
| 722 | + break; |
|
| 723 | + |
|
| 724 | + case 'wpi_payment_form' : |
|
| 725 | + do_action( "getpaid_before_delete_payment_form", new GetPaid_Payment_Form( $post_id ) ); |
|
| 726 | + break; |
|
| 727 | + |
|
| 728 | + case 'wpi_discount' : |
|
| 729 | + do_action( "getpaid_before_delete_discount", new WPInv_Discount( $post_id ) ); |
|
| 730 | + break; |
|
| 731 | + |
|
| 732 | + case 'wpi_invoice' : |
|
| 733 | + $invoice = new WPInv_Invoice( $post_id ); |
|
| 734 | + do_action( "getpaid_before_delete_invoice", $invoice ); |
|
| 735 | + $invoice->get_data_store()->delete_items( $invoice ); |
|
| 736 | + $invoice->get_data_store()->delete_special_fields( $invoice ); |
|
| 737 | + break; |
|
| 738 | + } |
|
| 739 | + } |
|
| 740 | 740 | |
| 741 | 741 | } |
@@ -15,30 +15,30 @@ discard block |
||
| 15 | 15 | */ |
| 16 | 16 | class WPInv_Discount extends GetPaid_Data { |
| 17 | 17 | |
| 18 | - /** |
|
| 19 | - * Which data store to load. |
|
| 20 | - * |
|
| 21 | - * @var string |
|
| 22 | - */ |
|
| 18 | + /** |
|
| 19 | + * Which data store to load. |
|
| 20 | + * |
|
| 21 | + * @var string |
|
| 22 | + */ |
|
| 23 | 23 | protected $data_store_name = 'discount'; |
| 24 | 24 | |
| 25 | 25 | /** |
| 26 | - * This is the name of this object type. |
|
| 27 | - * |
|
| 28 | - * @var string |
|
| 29 | - */ |
|
| 30 | - protected $object_type = 'discount'; |
|
| 31 | - |
|
| 32 | - /** |
|
| 33 | - * Discount Data array. This is the core item data exposed in APIs. |
|
| 34 | - * |
|
| 35 | - * @since 1.0.19 |
|
| 36 | - * @var array |
|
| 37 | - */ |
|
| 38 | - protected $data = array( |
|
| 39 | - 'status' => 'draft', |
|
| 40 | - 'version' => '', |
|
| 41 | - 'date_created' => null, |
|
| 26 | + * This is the name of this object type. |
|
| 27 | + * |
|
| 28 | + * @var string |
|
| 29 | + */ |
|
| 30 | + protected $object_type = 'discount'; |
|
| 31 | + |
|
| 32 | + /** |
|
| 33 | + * Discount Data array. This is the core item data exposed in APIs. |
|
| 34 | + * |
|
| 35 | + * @since 1.0.19 |
|
| 36 | + * @var array |
|
| 37 | + */ |
|
| 38 | + protected $data = array( |
|
| 39 | + 'status' => 'draft', |
|
| 40 | + 'version' => '', |
|
| 41 | + 'date_created' => null, |
|
| 42 | 42 | 'date_modified' => null, |
| 43 | 43 | 'name' => 'no-name', |
| 44 | 44 | 'description' => '', |
@@ -58,144 +58,144 @@ discard block |
||
| 58 | 58 | 'amount' => null, |
| 59 | 59 | ); |
| 60 | 60 | |
| 61 | - /** |
|
| 62 | - * Stores meta in cache for future reads. |
|
| 63 | - * |
|
| 64 | - * A group must be set to to enable caching. |
|
| 65 | - * |
|
| 66 | - * @var string |
|
| 67 | - */ |
|
| 68 | - protected $cache_group = 'getpaid_discounts'; |
|
| 61 | + /** |
|
| 62 | + * Stores meta in cache for future reads. |
|
| 63 | + * |
|
| 64 | + * A group must be set to to enable caching. |
|
| 65 | + * |
|
| 66 | + * @var string |
|
| 67 | + */ |
|
| 68 | + protected $cache_group = 'getpaid_discounts'; |
|
| 69 | 69 | |
| 70 | 70 | /** |
| 71 | 71 | * Stores a reference to the original WP_Post object |
| 72 | 72 | * |
| 73 | 73 | * @var WP_Post |
| 74 | 74 | */ |
| 75 | - protected $post = null; |
|
| 76 | - |
|
| 77 | - /** |
|
| 78 | - * Get the discount if ID is passed, otherwise the discount is new and empty. |
|
| 79 | - * |
|
| 80 | - * @param int|array|string|WPInv_Discount|WP_Post $discount discount data, object, ID or code. |
|
| 81 | - */ |
|
| 82 | - public function __construct( $discount = 0 ) { |
|
| 83 | - parent::__construct( $discount ); |
|
| 84 | - |
|
| 85 | - if ( is_numeric( $discount ) && 'wpi_discount' === get_post_type( $discount ) ) { |
|
| 86 | - $this->set_id( $discount ); |
|
| 87 | - } elseif ( $discount instanceof self ) { |
|
| 88 | - $this->set_id( $discount->get_id() ); |
|
| 89 | - } elseif ( ! empty( $discount->ID ) ) { |
|
| 90 | - $this->set_id( $discount->ID ); |
|
| 91 | - } elseif ( is_array( $discount ) ) { |
|
| 92 | - $this->set_props( $discount ); |
|
| 93 | - |
|
| 94 | - if ( isset( $discount['ID'] ) ) { |
|
| 95 | - $this->set_id( $discount['ID'] ); |
|
| 96 | - } |
|
| 97 | - |
|
| 98 | - } elseif ( is_scalar( $discount ) && $discount = self::get_discount_id_by_code( $discount ) ) { |
|
| 99 | - $this->set_id( $discount ); |
|
| 100 | - } else { |
|
| 101 | - $this->set_object_read( true ); |
|
| 102 | - } |
|
| 75 | + protected $post = null; |
|
| 76 | + |
|
| 77 | + /** |
|
| 78 | + * Get the discount if ID is passed, otherwise the discount is new and empty. |
|
| 79 | + * |
|
| 80 | + * @param int|array|string|WPInv_Discount|WP_Post $discount discount data, object, ID or code. |
|
| 81 | + */ |
|
| 82 | + public function __construct( $discount = 0 ) { |
|
| 83 | + parent::__construct( $discount ); |
|
| 84 | + |
|
| 85 | + if ( is_numeric( $discount ) && 'wpi_discount' === get_post_type( $discount ) ) { |
|
| 86 | + $this->set_id( $discount ); |
|
| 87 | + } elseif ( $discount instanceof self ) { |
|
| 88 | + $this->set_id( $discount->get_id() ); |
|
| 89 | + } elseif ( ! empty( $discount->ID ) ) { |
|
| 90 | + $this->set_id( $discount->ID ); |
|
| 91 | + } elseif ( is_array( $discount ) ) { |
|
| 92 | + $this->set_props( $discount ); |
|
| 93 | + |
|
| 94 | + if ( isset( $discount['ID'] ) ) { |
|
| 95 | + $this->set_id( $discount['ID'] ); |
|
| 96 | + } |
|
| 97 | + |
|
| 98 | + } elseif ( is_scalar( $discount ) && $discount = self::get_discount_id_by_code( $discount ) ) { |
|
| 99 | + $this->set_id( $discount ); |
|
| 100 | + } else { |
|
| 101 | + $this->set_object_read( true ); |
|
| 102 | + } |
|
| 103 | 103 | |
| 104 | 104 | // Load the datastore. |
| 105 | - $this->data_store = GetPaid_Data_Store::load( $this->data_store_name ); |
|
| 105 | + $this->data_store = GetPaid_Data_Store::load( $this->data_store_name ); |
|
| 106 | 106 | |
| 107 | - if ( $this->get_id() > 0 ) { |
|
| 107 | + if ( $this->get_id() > 0 ) { |
|
| 108 | 108 | $this->post = get_post( $this->get_id() ); |
| 109 | 109 | $this->ID = $this->get_id(); |
| 110 | - $this->data_store->read( $this ); |
|
| 110 | + $this->data_store->read( $this ); |
|
| 111 | + } |
|
| 112 | + |
|
| 113 | + } |
|
| 114 | + |
|
| 115 | + /** |
|
| 116 | + * Fetch a discount from the db/cache |
|
| 117 | + * |
|
| 118 | + * |
|
| 119 | + * @static |
|
| 120 | + * @param string $field The field to query against: 'ID', 'discount_code' |
|
| 121 | + * @param string|int $value The field value |
|
| 122 | + * @deprecated |
|
| 123 | + * @since 1.0.15 |
|
| 124 | + * @return array|bool array of discount details on success. False otherwise. |
|
| 125 | + */ |
|
| 126 | + public static function get_data_by( $field, $value ) { |
|
| 127 | + |
|
| 128 | + if ( 'id' == strtolower( $field ) ) { |
|
| 129 | + // Make sure the value is numeric to avoid casting objects, for example, |
|
| 130 | + // to int 1. |
|
| 131 | + if ( ! is_numeric( $value ) ) |
|
| 132 | + return false; |
|
| 133 | + $value = intval( $value ); |
|
| 134 | + if ( $value < 1 ) |
|
| 135 | + return false; |
|
| 136 | + } |
|
| 137 | + |
|
| 138 | + if ( ! $value || ! is_string( $field ) ) { |
|
| 139 | + return false; |
|
| 140 | + } |
|
| 141 | + |
|
| 142 | + $field = trim( $field ); |
|
| 143 | + |
|
| 144 | + // prepare query args |
|
| 145 | + switch ( strtolower( $field ) ) { |
|
| 146 | + case 'id': |
|
| 147 | + $discount_id = $value; |
|
| 148 | + $args = array( 'include' => array( $value ) ); |
|
| 149 | + break; |
|
| 150 | + case 'discount_code': |
|
| 151 | + case 'code': |
|
| 152 | + $value = trim( $value ); |
|
| 153 | + $discount_id = wp_cache_get( $value, 'WPInv_Discount_Codes' ); |
|
| 154 | + $args = array( 'meta_key' => '_wpi_discount_code', 'meta_value' => $value ); |
|
| 155 | + break; |
|
| 156 | + case 'name': |
|
| 157 | + $discount_id = 0; |
|
| 158 | + $args = array( 'name' => trim( $value ) ); |
|
| 159 | + break; |
|
| 160 | + default: |
|
| 161 | + $args = apply_filters( "wpinv_discount_get_data_by_{$field}_args", null, $value ); |
|
| 162 | + if ( ! is_array( $args ) ) { |
|
| 163 | + return apply_filters( "wpinv_discount_get_data_by_$field", false, $value ); |
|
| 164 | + } |
|
| 165 | + |
|
| 166 | + } |
|
| 167 | + |
|
| 168 | + // Check if there is a cached value. |
|
| 169 | + if ( ! empty( $discount_id ) && $discount = wp_cache_get( (int) $discount_id, 'WPInv_Discounts' ) ) { |
|
| 170 | + return $discount; |
|
| 171 | + } |
|
| 172 | + |
|
| 173 | + $args = array_merge( |
|
| 174 | + $args, |
|
| 175 | + array( |
|
| 176 | + 'post_type' => 'wpi_discount', |
|
| 177 | + 'posts_per_page' => 1, |
|
| 178 | + 'post_status' => array( 'publish', 'pending', 'draft', 'expired' ) |
|
| 179 | + ) |
|
| 180 | + ); |
|
| 181 | + |
|
| 182 | + $discount = get_posts( $args ); |
|
| 183 | + |
|
| 184 | + if( empty( $discount ) ) { |
|
| 185 | + return false; |
|
| 111 | 186 | } |
| 112 | 187 | |
| 113 | - } |
|
| 114 | - |
|
| 115 | - /** |
|
| 116 | - * Fetch a discount from the db/cache |
|
| 117 | - * |
|
| 118 | - * |
|
| 119 | - * @static |
|
| 120 | - * @param string $field The field to query against: 'ID', 'discount_code' |
|
| 121 | - * @param string|int $value The field value |
|
| 122 | - * @deprecated |
|
| 123 | - * @since 1.0.15 |
|
| 124 | - * @return array|bool array of discount details on success. False otherwise. |
|
| 125 | - */ |
|
| 126 | - public static function get_data_by( $field, $value ) { |
|
| 127 | - |
|
| 128 | - if ( 'id' == strtolower( $field ) ) { |
|
| 129 | - // Make sure the value is numeric to avoid casting objects, for example, |
|
| 130 | - // to int 1. |
|
| 131 | - if ( ! is_numeric( $value ) ) |
|
| 132 | - return false; |
|
| 133 | - $value = intval( $value ); |
|
| 134 | - if ( $value < 1 ) |
|
| 135 | - return false; |
|
| 136 | - } |
|
| 137 | - |
|
| 138 | - if ( ! $value || ! is_string( $field ) ) { |
|
| 139 | - return false; |
|
| 140 | - } |
|
| 141 | - |
|
| 142 | - $field = trim( $field ); |
|
| 143 | - |
|
| 144 | - // prepare query args |
|
| 145 | - switch ( strtolower( $field ) ) { |
|
| 146 | - case 'id': |
|
| 147 | - $discount_id = $value; |
|
| 148 | - $args = array( 'include' => array( $value ) ); |
|
| 149 | - break; |
|
| 150 | - case 'discount_code': |
|
| 151 | - case 'code': |
|
| 152 | - $value = trim( $value ); |
|
| 153 | - $discount_id = wp_cache_get( $value, 'WPInv_Discount_Codes' ); |
|
| 154 | - $args = array( 'meta_key' => '_wpi_discount_code', 'meta_value' => $value ); |
|
| 155 | - break; |
|
| 156 | - case 'name': |
|
| 157 | - $discount_id = 0; |
|
| 158 | - $args = array( 'name' => trim( $value ) ); |
|
| 159 | - break; |
|
| 160 | - default: |
|
| 161 | - $args = apply_filters( "wpinv_discount_get_data_by_{$field}_args", null, $value ); |
|
| 162 | - if ( ! is_array( $args ) ) { |
|
| 163 | - return apply_filters( "wpinv_discount_get_data_by_$field", false, $value ); |
|
| 164 | - } |
|
| 165 | - |
|
| 166 | - } |
|
| 167 | - |
|
| 168 | - // Check if there is a cached value. |
|
| 169 | - if ( ! empty( $discount_id ) && $discount = wp_cache_get( (int) $discount_id, 'WPInv_Discounts' ) ) { |
|
| 170 | - return $discount; |
|
| 171 | - } |
|
| 172 | - |
|
| 173 | - $args = array_merge( |
|
| 174 | - $args, |
|
| 175 | - array( |
|
| 176 | - 'post_type' => 'wpi_discount', |
|
| 177 | - 'posts_per_page' => 1, |
|
| 178 | - 'post_status' => array( 'publish', 'pending', 'draft', 'expired' ) |
|
| 179 | - ) |
|
| 180 | - ); |
|
| 181 | - |
|
| 182 | - $discount = get_posts( $args ); |
|
| 183 | - |
|
| 184 | - if( empty( $discount ) ) { |
|
| 185 | - return false; |
|
| 186 | - } |
|
| 187 | - |
|
| 188 | - $discount = $discount[0]; |
|
| 189 | - |
|
| 190 | - // Prepare the return data. |
|
| 191 | - $return = array( |
|
| 188 | + $discount = $discount[0]; |
|
| 189 | + |
|
| 190 | + // Prepare the return data. |
|
| 191 | + $return = array( |
|
| 192 | 192 | 'ID' => $discount->ID, |
| 193 | 193 | 'code' => get_post_meta( $discount->ID, '_wpi_discount_code', true ), |
| 194 | 194 | 'amount' => get_post_meta( $discount->ID, '_wpi_discount_amount', true ), |
| 195 | 195 | 'date_created' => $discount->post_date, |
| 196 | - 'date_modified' => $discount->post_modified, |
|
| 197 | - 'status' => $discount->post_status, |
|
| 198 | - 'start' => get_post_meta( $discount->ID, '_wpi_discount_start', true ), |
|
| 196 | + 'date_modified' => $discount->post_modified, |
|
| 197 | + 'status' => $discount->post_status, |
|
| 198 | + 'start' => get_post_meta( $discount->ID, '_wpi_discount_start', true ), |
|
| 199 | 199 | 'expiration' => get_post_meta( $discount->ID, '_wpi_discount_expiration', true ), |
| 200 | 200 | 'type' => get_post_meta( $discount->ID, '_wpi_discount_type', true ), |
| 201 | 201 | 'description' => $discount->post_excerpt, |
@@ -209,77 +209,77 @@ discard block |
||
| 209 | 209 | 'max_total' => get_post_meta( $discount->ID, '_wpi_discount_max_total', true ), |
| 210 | 210 | ); |
| 211 | 211 | |
| 212 | - $return = apply_filters( 'wpinv_discount_properties', $return ); |
|
| 213 | - |
|
| 214 | - // Update the cache with our data |
|
| 215 | - wp_cache_add( $discount->ID, $return, 'WPInv_Discounts' ); |
|
| 216 | - wp_cache_add( $return['code'], $discount->ID, 'WPInv_Discount_Codes' ); |
|
| 217 | - |
|
| 218 | - return $return; |
|
| 219 | - } |
|
| 220 | - |
|
| 221 | - /** |
|
| 222 | - * Given a discount code, it returns a discount id. |
|
| 223 | - * |
|
| 224 | - * |
|
| 225 | - * @static |
|
| 226 | - * @param string $discount_code |
|
| 227 | - * @since 1.0.15 |
|
| 228 | - * @return int |
|
| 229 | - */ |
|
| 230 | - public static function get_discount_id_by_code( $discount_code ) { |
|
| 231 | - |
|
| 232 | - // Trim the code. |
|
| 233 | - $discount_code = trim( $discount_code ); |
|
| 234 | - |
|
| 235 | - // Ensure a value has been passed. |
|
| 236 | - if ( empty( $discount_code ) ) { |
|
| 237 | - return 0; |
|
| 238 | - } |
|
| 239 | - |
|
| 240 | - // Maybe retrieve from the cache. |
|
| 241 | - $discount_id = wp_cache_get( $discount_code, 'getpaid_discount_codes' ); |
|
| 242 | - if ( ! empty( $discount_id ) ) { |
|
| 243 | - return $discount_id; |
|
| 244 | - } |
|
| 245 | - |
|
| 246 | - // Fetch the first discount codes. |
|
| 247 | - $discounts = get_posts( |
|
| 248 | - array( |
|
| 249 | - 'meta_key' => '_wpi_discount_code', |
|
| 250 | - 'meta_value' => $discount_code, |
|
| 251 | - 'post_type' => 'wpi_discount', |
|
| 252 | - 'posts_per_page' => 1, |
|
| 253 | - 'post_status' => array( 'publish', 'pending', 'draft', 'expired' ), |
|
| 254 | - 'fields' => 'ids', |
|
| 255 | - ) |
|
| 256 | - ); |
|
| 257 | - |
|
| 258 | - if ( empty( $discounts ) ) { |
|
| 259 | - return 0; |
|
| 260 | - } |
|
| 261 | - |
|
| 262 | - $discount_id = $discounts[0]; |
|
| 263 | - |
|
| 264 | - // Update the cache with our data |
|
| 265 | - wp_cache_add( get_post_meta( $discount_id, '_wpi_discount_code', true ), $discount_id, 'getpaid_discount_codes' ); |
|
| 266 | - |
|
| 267 | - return $discount_id; |
|
| 268 | - } |
|
| 269 | - |
|
| 270 | - /** |
|
| 271 | - * Magic method for checking the existence of a certain custom field. |
|
| 272 | - * |
|
| 273 | - * @since 1.0.15 |
|
| 274 | - * @access public |
|
| 275 | - * |
|
| 276 | - * @return bool Whether the given discount field is set. |
|
| 277 | - */ |
|
| 278 | - public function __isset( $key ){ |
|
| 279 | - return isset( $this->data[$key] ) || method_exists( $this, "get_$key"); |
|
| 280 | - } |
|
| 281 | - |
|
| 282 | - /* |
|
| 212 | + $return = apply_filters( 'wpinv_discount_properties', $return ); |
|
| 213 | + |
|
| 214 | + // Update the cache with our data |
|
| 215 | + wp_cache_add( $discount->ID, $return, 'WPInv_Discounts' ); |
|
| 216 | + wp_cache_add( $return['code'], $discount->ID, 'WPInv_Discount_Codes' ); |
|
| 217 | + |
|
| 218 | + return $return; |
|
| 219 | + } |
|
| 220 | + |
|
| 221 | + /** |
|
| 222 | + * Given a discount code, it returns a discount id. |
|
| 223 | + * |
|
| 224 | + * |
|
| 225 | + * @static |
|
| 226 | + * @param string $discount_code |
|
| 227 | + * @since 1.0.15 |
|
| 228 | + * @return int |
|
| 229 | + */ |
|
| 230 | + public static function get_discount_id_by_code( $discount_code ) { |
|
| 231 | + |
|
| 232 | + // Trim the code. |
|
| 233 | + $discount_code = trim( $discount_code ); |
|
| 234 | + |
|
| 235 | + // Ensure a value has been passed. |
|
| 236 | + if ( empty( $discount_code ) ) { |
|
| 237 | + return 0; |
|
| 238 | + } |
|
| 239 | + |
|
| 240 | + // Maybe retrieve from the cache. |
|
| 241 | + $discount_id = wp_cache_get( $discount_code, 'getpaid_discount_codes' ); |
|
| 242 | + if ( ! empty( $discount_id ) ) { |
|
| 243 | + return $discount_id; |
|
| 244 | + } |
|
| 245 | + |
|
| 246 | + // Fetch the first discount codes. |
|
| 247 | + $discounts = get_posts( |
|
| 248 | + array( |
|
| 249 | + 'meta_key' => '_wpi_discount_code', |
|
| 250 | + 'meta_value' => $discount_code, |
|
| 251 | + 'post_type' => 'wpi_discount', |
|
| 252 | + 'posts_per_page' => 1, |
|
| 253 | + 'post_status' => array( 'publish', 'pending', 'draft', 'expired' ), |
|
| 254 | + 'fields' => 'ids', |
|
| 255 | + ) |
|
| 256 | + ); |
|
| 257 | + |
|
| 258 | + if ( empty( $discounts ) ) { |
|
| 259 | + return 0; |
|
| 260 | + } |
|
| 261 | + |
|
| 262 | + $discount_id = $discounts[0]; |
|
| 263 | + |
|
| 264 | + // Update the cache with our data |
|
| 265 | + wp_cache_add( get_post_meta( $discount_id, '_wpi_discount_code', true ), $discount_id, 'getpaid_discount_codes' ); |
|
| 266 | + |
|
| 267 | + return $discount_id; |
|
| 268 | + } |
|
| 269 | + |
|
| 270 | + /** |
|
| 271 | + * Magic method for checking the existence of a certain custom field. |
|
| 272 | + * |
|
| 273 | + * @since 1.0.15 |
|
| 274 | + * @access public |
|
| 275 | + * |
|
| 276 | + * @return bool Whether the given discount field is set. |
|
| 277 | + */ |
|
| 278 | + public function __isset( $key ){ |
|
| 279 | + return isset( $this->data[$key] ) || method_exists( $this, "get_$key"); |
|
| 280 | + } |
|
| 281 | + |
|
| 282 | + /* |
|
| 283 | 283 | |-------------------------------------------------------------------------- |
| 284 | 284 | | CRUD methods |
| 285 | 285 | |-------------------------------------------------------------------------- |
@@ -294,430 +294,430 @@ discard block |
||
| 294 | 294 | |-------------------------------------------------------------------------- |
| 295 | 295 | */ |
| 296 | 296 | |
| 297 | - /** |
|
| 298 | - * Get discount status. |
|
| 299 | - * |
|
| 300 | - * @since 1.0.19 |
|
| 301 | - * @param string $context View or edit context. |
|
| 302 | - * @return string |
|
| 303 | - */ |
|
| 304 | - public function get_status( $context = 'view' ) { |
|
| 305 | - return $this->get_prop( 'status', $context ); |
|
| 297 | + /** |
|
| 298 | + * Get discount status. |
|
| 299 | + * |
|
| 300 | + * @since 1.0.19 |
|
| 301 | + * @param string $context View or edit context. |
|
| 302 | + * @return string |
|
| 303 | + */ |
|
| 304 | + public function get_status( $context = 'view' ) { |
|
| 305 | + return $this->get_prop( 'status', $context ); |
|
| 306 | 306 | } |
| 307 | 307 | |
| 308 | 308 | /** |
| 309 | - * Get plugin version when the discount was created. |
|
| 310 | - * |
|
| 311 | - * @since 1.0.19 |
|
| 312 | - * @param string $context View or edit context. |
|
| 313 | - * @return string |
|
| 314 | - */ |
|
| 315 | - public function get_version( $context = 'view' ) { |
|
| 316 | - return $this->get_prop( 'version', $context ); |
|
| 309 | + * Get plugin version when the discount was created. |
|
| 310 | + * |
|
| 311 | + * @since 1.0.19 |
|
| 312 | + * @param string $context View or edit context. |
|
| 313 | + * @return string |
|
| 314 | + */ |
|
| 315 | + public function get_version( $context = 'view' ) { |
|
| 316 | + return $this->get_prop( 'version', $context ); |
|
| 317 | 317 | } |
| 318 | 318 | |
| 319 | 319 | /** |
| 320 | - * Get date when the discount was created. |
|
| 321 | - * |
|
| 322 | - * @since 1.0.19 |
|
| 323 | - * @param string $context View or edit context. |
|
| 324 | - * @return string |
|
| 325 | - */ |
|
| 326 | - public function get_date_created( $context = 'view' ) { |
|
| 327 | - return $this->get_prop( 'date_created', $context ); |
|
| 320 | + * Get date when the discount was created. |
|
| 321 | + * |
|
| 322 | + * @since 1.0.19 |
|
| 323 | + * @param string $context View or edit context. |
|
| 324 | + * @return string |
|
| 325 | + */ |
|
| 326 | + public function get_date_created( $context = 'view' ) { |
|
| 327 | + return $this->get_prop( 'date_created', $context ); |
|
| 328 | 328 | } |
| 329 | 329 | |
| 330 | 330 | /** |
| 331 | - * Get GMT date when the discount was created. |
|
| 332 | - * |
|
| 333 | - * @since 1.0.19 |
|
| 334 | - * @param string $context View or edit context. |
|
| 335 | - * @return string |
|
| 336 | - */ |
|
| 337 | - public function get_date_created_gmt( $context = 'view' ) { |
|
| 331 | + * Get GMT date when the discount was created. |
|
| 332 | + * |
|
| 333 | + * @since 1.0.19 |
|
| 334 | + * @param string $context View or edit context. |
|
| 335 | + * @return string |
|
| 336 | + */ |
|
| 337 | + public function get_date_created_gmt( $context = 'view' ) { |
|
| 338 | 338 | $date = $this->get_date_created( $context ); |
| 339 | 339 | |
| 340 | 340 | if ( $date ) { |
| 341 | 341 | $date = get_gmt_from_date( $date ); |
| 342 | 342 | } |
| 343 | - return $date; |
|
| 343 | + return $date; |
|
| 344 | 344 | } |
| 345 | 345 | |
| 346 | 346 | /** |
| 347 | - * Get date when the discount was last modified. |
|
| 348 | - * |
|
| 349 | - * @since 1.0.19 |
|
| 350 | - * @param string $context View or edit context. |
|
| 351 | - * @return string |
|
| 352 | - */ |
|
| 353 | - public function get_date_modified( $context = 'view' ) { |
|
| 354 | - return $this->get_prop( 'date_modified', $context ); |
|
| 347 | + * Get date when the discount was last modified. |
|
| 348 | + * |
|
| 349 | + * @since 1.0.19 |
|
| 350 | + * @param string $context View or edit context. |
|
| 351 | + * @return string |
|
| 352 | + */ |
|
| 353 | + public function get_date_modified( $context = 'view' ) { |
|
| 354 | + return $this->get_prop( 'date_modified', $context ); |
|
| 355 | 355 | } |
| 356 | 356 | |
| 357 | 357 | /** |
| 358 | - * Get GMT date when the discount was last modified. |
|
| 359 | - * |
|
| 360 | - * @since 1.0.19 |
|
| 361 | - * @param string $context View or edit context. |
|
| 362 | - * @return string |
|
| 363 | - */ |
|
| 364 | - public function get_date_modified_gmt( $context = 'view' ) { |
|
| 358 | + * Get GMT date when the discount was last modified. |
|
| 359 | + * |
|
| 360 | + * @since 1.0.19 |
|
| 361 | + * @param string $context View or edit context. |
|
| 362 | + * @return string |
|
| 363 | + */ |
|
| 364 | + public function get_date_modified_gmt( $context = 'view' ) { |
|
| 365 | 365 | $date = $this->get_date_modified( $context ); |
| 366 | 366 | |
| 367 | 367 | if ( $date ) { |
| 368 | 368 | $date = get_gmt_from_date( $date ); |
| 369 | 369 | } |
| 370 | - return $date; |
|
| 370 | + return $date; |
|
| 371 | 371 | } |
| 372 | 372 | |
| 373 | 373 | /** |
| 374 | - * Get the discount name. |
|
| 375 | - * |
|
| 376 | - * @since 1.0.19 |
|
| 377 | - * @param string $context View or edit context. |
|
| 378 | - * @return string |
|
| 379 | - */ |
|
| 380 | - public function get_name( $context = 'view' ) { |
|
| 381 | - return $this->get_prop( 'name', $context ); |
|
| 374 | + * Get the discount name. |
|
| 375 | + * |
|
| 376 | + * @since 1.0.19 |
|
| 377 | + * @param string $context View or edit context. |
|
| 378 | + * @return string |
|
| 379 | + */ |
|
| 380 | + public function get_name( $context = 'view' ) { |
|
| 381 | + return $this->get_prop( 'name', $context ); |
|
| 382 | 382 | } |
| 383 | 383 | |
| 384 | 384 | /** |
| 385 | - * Alias of self::get_name(). |
|
| 386 | - * |
|
| 387 | - * @since 1.0.19 |
|
| 388 | - * @param string $context View or edit context. |
|
| 389 | - * @return string |
|
| 390 | - */ |
|
| 391 | - public function get_title( $context = 'view' ) { |
|
| 392 | - return $this->get_name( $context ); |
|
| 385 | + * Alias of self::get_name(). |
|
| 386 | + * |
|
| 387 | + * @since 1.0.19 |
|
| 388 | + * @param string $context View or edit context. |
|
| 389 | + * @return string |
|
| 390 | + */ |
|
| 391 | + public function get_title( $context = 'view' ) { |
|
| 392 | + return $this->get_name( $context ); |
|
| 393 | 393 | } |
| 394 | 394 | |
| 395 | 395 | /** |
| 396 | - * Get the discount description. |
|
| 397 | - * |
|
| 398 | - * @since 1.0.19 |
|
| 399 | - * @param string $context View or edit context. |
|
| 400 | - * @return string |
|
| 401 | - */ |
|
| 402 | - public function get_description( $context = 'view' ) { |
|
| 403 | - return $this->get_prop( 'description', $context ); |
|
| 396 | + * Get the discount description. |
|
| 397 | + * |
|
| 398 | + * @since 1.0.19 |
|
| 399 | + * @param string $context View or edit context. |
|
| 400 | + * @return string |
|
| 401 | + */ |
|
| 402 | + public function get_description( $context = 'view' ) { |
|
| 403 | + return $this->get_prop( 'description', $context ); |
|
| 404 | 404 | } |
| 405 | 405 | |
| 406 | 406 | /** |
| 407 | - * Alias of self::get_description(). |
|
| 408 | - * |
|
| 409 | - * @since 1.0.19 |
|
| 410 | - * @param string $context View or edit context. |
|
| 411 | - * @return string |
|
| 412 | - */ |
|
| 413 | - public function get_excerpt( $context = 'view' ) { |
|
| 414 | - return $this->get_description( $context ); |
|
| 407 | + * Alias of self::get_description(). |
|
| 408 | + * |
|
| 409 | + * @since 1.0.19 |
|
| 410 | + * @param string $context View or edit context. |
|
| 411 | + * @return string |
|
| 412 | + */ |
|
| 413 | + public function get_excerpt( $context = 'view' ) { |
|
| 414 | + return $this->get_description( $context ); |
|
| 415 | 415 | } |
| 416 | 416 | |
| 417 | 417 | /** |
| 418 | - * Alias of self::get_description(). |
|
| 419 | - * |
|
| 420 | - * @since 1.0.19 |
|
| 421 | - * @param string $context View or edit context. |
|
| 422 | - * @return string |
|
| 423 | - */ |
|
| 424 | - public function get_summary( $context = 'view' ) { |
|
| 425 | - return $this->get_description( $context ); |
|
| 418 | + * Alias of self::get_description(). |
|
| 419 | + * |
|
| 420 | + * @since 1.0.19 |
|
| 421 | + * @param string $context View or edit context. |
|
| 422 | + * @return string |
|
| 423 | + */ |
|
| 424 | + public function get_summary( $context = 'view' ) { |
|
| 425 | + return $this->get_description( $context ); |
|
| 426 | 426 | } |
| 427 | 427 | |
| 428 | 428 | /** |
| 429 | - * Get the owner of the discount. |
|
| 430 | - * |
|
| 431 | - * @since 1.0.19 |
|
| 432 | - * @param string $context View or edit context. |
|
| 433 | - * @return string |
|
| 434 | - */ |
|
| 435 | - public function get_author( $context = 'view' ) { |
|
| 436 | - return (int) $this->get_prop( 'author', $context ); |
|
| 437 | - } |
|
| 429 | + * Get the owner of the discount. |
|
| 430 | + * |
|
| 431 | + * @since 1.0.19 |
|
| 432 | + * @param string $context View or edit context. |
|
| 433 | + * @return string |
|
| 434 | + */ |
|
| 435 | + public function get_author( $context = 'view' ) { |
|
| 436 | + return (int) $this->get_prop( 'author', $context ); |
|
| 437 | + } |
|
| 438 | 438 | |
| 439 | - /** |
|
| 440 | - * Get the discount code. |
|
| 441 | - * |
|
| 442 | - * @since 1.0.19 |
|
| 443 | - * @param string $context View or edit context. |
|
| 444 | - * @return string |
|
| 445 | - */ |
|
| 446 | - public function get_code( $context = 'view' ) { |
|
| 447 | - return $this->get_prop( 'code', $context ); |
|
| 448 | - } |
|
| 439 | + /** |
|
| 440 | + * Get the discount code. |
|
| 441 | + * |
|
| 442 | + * @since 1.0.19 |
|
| 443 | + * @param string $context View or edit context. |
|
| 444 | + * @return string |
|
| 445 | + */ |
|
| 446 | + public function get_code( $context = 'view' ) { |
|
| 447 | + return $this->get_prop( 'code', $context ); |
|
| 448 | + } |
|
| 449 | 449 | |
| 450 | - /** |
|
| 451 | - * Alias for self::get_code(). |
|
| 452 | - * |
|
| 453 | - * @since 1.0.19 |
|
| 454 | - * @param string $context View or edit context. |
|
| 455 | - * @return string |
|
| 456 | - */ |
|
| 457 | - public function get_coupon_code( $context = 'view' ) { |
|
| 458 | - return $this->get_code( $context ); |
|
| 459 | - } |
|
| 450 | + /** |
|
| 451 | + * Alias for self::get_code(). |
|
| 452 | + * |
|
| 453 | + * @since 1.0.19 |
|
| 454 | + * @param string $context View or edit context. |
|
| 455 | + * @return string |
|
| 456 | + */ |
|
| 457 | + public function get_coupon_code( $context = 'view' ) { |
|
| 458 | + return $this->get_code( $context ); |
|
| 459 | + } |
|
| 460 | 460 | |
| 461 | - /** |
|
| 462 | - * Alias for self::get_code(). |
|
| 463 | - * |
|
| 464 | - * @since 1.0.19 |
|
| 465 | - * @param string $context View or edit context. |
|
| 466 | - * @return string |
|
| 467 | - */ |
|
| 468 | - public function get_discount_code( $context = 'view' ) { |
|
| 469 | - return $this->get_code( $context ); |
|
| 470 | - } |
|
| 461 | + /** |
|
| 462 | + * Alias for self::get_code(). |
|
| 463 | + * |
|
| 464 | + * @since 1.0.19 |
|
| 465 | + * @param string $context View or edit context. |
|
| 466 | + * @return string |
|
| 467 | + */ |
|
| 468 | + public function get_discount_code( $context = 'view' ) { |
|
| 469 | + return $this->get_code( $context ); |
|
| 470 | + } |
|
| 471 | 471 | |
| 472 | - /** |
|
| 473 | - * Get the discount's amount. |
|
| 474 | - * |
|
| 475 | - * @since 1.0.19 |
|
| 476 | - * @param string $context View or edit context. |
|
| 477 | - * @return float |
|
| 478 | - */ |
|
| 479 | - public function get_amount( $context = 'view' ) { |
|
| 480 | - return $this->get_prop( 'amount', $context ); |
|
| 481 | - } |
|
| 482 | - |
|
| 483 | - /** |
|
| 484 | - * Get the discount's formated amount/rate. |
|
| 485 | - * |
|
| 486 | - * @since 1.0.19 |
|
| 487 | - * @return string |
|
| 488 | - */ |
|
| 489 | - public function get_formatted_amount() { |
|
| 490 | - |
|
| 491 | - if ( $this->is_type( 'flat' ) ) { |
|
| 492 | - $rate = wpinv_price( wpinv_format_amount( $this->get_amount() ) ); |
|
| 493 | - } else { |
|
| 494 | - $rate = $this->get_amount() . '%'; |
|
| 495 | - } |
|
| 496 | - |
|
| 497 | - return apply_filters( 'wpinv_format_discount_rate', $rate, $this->get_type(), $this->get_amount() ); |
|
| 498 | - } |
|
| 472 | + /** |
|
| 473 | + * Get the discount's amount. |
|
| 474 | + * |
|
| 475 | + * @since 1.0.19 |
|
| 476 | + * @param string $context View or edit context. |
|
| 477 | + * @return float |
|
| 478 | + */ |
|
| 479 | + public function get_amount( $context = 'view' ) { |
|
| 480 | + return $this->get_prop( 'amount', $context ); |
|
| 481 | + } |
|
| 482 | + |
|
| 483 | + /** |
|
| 484 | + * Get the discount's formated amount/rate. |
|
| 485 | + * |
|
| 486 | + * @since 1.0.19 |
|
| 487 | + * @return string |
|
| 488 | + */ |
|
| 489 | + public function get_formatted_amount() { |
|
| 490 | + |
|
| 491 | + if ( $this->is_type( 'flat' ) ) { |
|
| 492 | + $rate = wpinv_price( wpinv_format_amount( $this->get_amount() ) ); |
|
| 493 | + } else { |
|
| 494 | + $rate = $this->get_amount() . '%'; |
|
| 495 | + } |
|
| 496 | + |
|
| 497 | + return apply_filters( 'wpinv_format_discount_rate', $rate, $this->get_type(), $this->get_amount() ); |
|
| 498 | + } |
|
| 499 | 499 | |
| 500 | - /** |
|
| 501 | - * Get the discount's start date. |
|
| 502 | - * |
|
| 503 | - * @since 1.0.19 |
|
| 504 | - * @param string $context View or edit context. |
|
| 505 | - * @return string |
|
| 506 | - */ |
|
| 507 | - public function get_start( $context = 'view' ) { |
|
| 508 | - return $this->get_prop( 'start', $context ); |
|
| 509 | - } |
|
| 500 | + /** |
|
| 501 | + * Get the discount's start date. |
|
| 502 | + * |
|
| 503 | + * @since 1.0.19 |
|
| 504 | + * @param string $context View or edit context. |
|
| 505 | + * @return string |
|
| 506 | + */ |
|
| 507 | + public function get_start( $context = 'view' ) { |
|
| 508 | + return $this->get_prop( 'start', $context ); |
|
| 509 | + } |
|
| 510 | 510 | |
| 511 | - /** |
|
| 512 | - * Alias for self::get_start(). |
|
| 513 | - * |
|
| 514 | - * @since 1.0.19 |
|
| 515 | - * @param string $context View or edit context. |
|
| 516 | - * @return string |
|
| 517 | - */ |
|
| 518 | - public function get_start_date( $context = 'view' ) { |
|
| 519 | - return $this->get_start( $context ); |
|
| 520 | - } |
|
| 511 | + /** |
|
| 512 | + * Alias for self::get_start(). |
|
| 513 | + * |
|
| 514 | + * @since 1.0.19 |
|
| 515 | + * @param string $context View or edit context. |
|
| 516 | + * @return string |
|
| 517 | + */ |
|
| 518 | + public function get_start_date( $context = 'view' ) { |
|
| 519 | + return $this->get_start( $context ); |
|
| 520 | + } |
|
| 521 | 521 | |
| 522 | - /** |
|
| 523 | - * Get the discount's expiration date. |
|
| 524 | - * |
|
| 525 | - * @since 1.0.19 |
|
| 526 | - * @param string $context View or edit context. |
|
| 527 | - * @return string |
|
| 528 | - */ |
|
| 529 | - public function get_expiration( $context = 'view' ) { |
|
| 530 | - return $this->get_prop( 'expiration', $context ); |
|
| 531 | - } |
|
| 522 | + /** |
|
| 523 | + * Get the discount's expiration date. |
|
| 524 | + * |
|
| 525 | + * @since 1.0.19 |
|
| 526 | + * @param string $context View or edit context. |
|
| 527 | + * @return string |
|
| 528 | + */ |
|
| 529 | + public function get_expiration( $context = 'view' ) { |
|
| 530 | + return $this->get_prop( 'expiration', $context ); |
|
| 531 | + } |
|
| 532 | 532 | |
| 533 | - /** |
|
| 534 | - * Alias for self::get_expiration(). |
|
| 535 | - * |
|
| 536 | - * @since 1.0.19 |
|
| 537 | - * @param string $context View or edit context. |
|
| 538 | - * @return string |
|
| 539 | - */ |
|
| 540 | - public function get_expiration_date( $context = 'view' ) { |
|
| 541 | - return $this->get_expiration( $context ); |
|
| 542 | - } |
|
| 543 | - |
|
| 544 | - /** |
|
| 545 | - * Alias for self::get_expiration(). |
|
| 546 | - * |
|
| 547 | - * @since 1.0.19 |
|
| 548 | - * @param string $context View or edit context. |
|
| 549 | - * @return string |
|
| 550 | - */ |
|
| 551 | - public function get_end_date( $context = 'view' ) { |
|
| 552 | - return $this->get_expiration( $context ); |
|
| 553 | - } |
|
| 533 | + /** |
|
| 534 | + * Alias for self::get_expiration(). |
|
| 535 | + * |
|
| 536 | + * @since 1.0.19 |
|
| 537 | + * @param string $context View or edit context. |
|
| 538 | + * @return string |
|
| 539 | + */ |
|
| 540 | + public function get_expiration_date( $context = 'view' ) { |
|
| 541 | + return $this->get_expiration( $context ); |
|
| 542 | + } |
|
| 543 | + |
|
| 544 | + /** |
|
| 545 | + * Alias for self::get_expiration(). |
|
| 546 | + * |
|
| 547 | + * @since 1.0.19 |
|
| 548 | + * @param string $context View or edit context. |
|
| 549 | + * @return string |
|
| 550 | + */ |
|
| 551 | + public function get_end_date( $context = 'view' ) { |
|
| 552 | + return $this->get_expiration( $context ); |
|
| 553 | + } |
|
| 554 | 554 | |
| 555 | - /** |
|
| 556 | - * Get the discount's type. |
|
| 557 | - * |
|
| 558 | - * @since 1.0.19 |
|
| 559 | - * @param string $context View or edit context. |
|
| 560 | - * @return string |
|
| 561 | - */ |
|
| 562 | - public function get_type( $context = 'view' ) { |
|
| 563 | - return $this->get_prop( 'type', $context ); |
|
| 564 | - } |
|
| 565 | - |
|
| 566 | - /** |
|
| 567 | - * Get the number of times a discount has been used. |
|
| 568 | - * |
|
| 569 | - * @since 1.0.19 |
|
| 570 | - * @param string $context View or edit context. |
|
| 571 | - * @return int |
|
| 572 | - */ |
|
| 573 | - public function get_uses( $context = 'view' ) { |
|
| 574 | - return (int) $this->get_prop( 'uses', $context ); |
|
| 575 | - } |
|
| 576 | - |
|
| 577 | - /** |
|
| 578 | - * Get the discount's usage, i.e uses / max uses. |
|
| 579 | - * |
|
| 580 | - * @since 1.0.19 |
|
| 581 | - * @return string |
|
| 582 | - */ |
|
| 583 | - public function get_usage() { |
|
| 584 | - |
|
| 585 | - if ( ! $this->has_limit() ) { |
|
| 586 | - return $this->get_uses() . ' / ' . ' ∞'; |
|
| 587 | - } |
|
| 588 | - |
|
| 589 | - return $this->get_uses() . ' / ' . (int) $this->get_max_uses(); |
|
| 590 | - |
|
| 591 | - } |
|
| 592 | - |
|
| 593 | - /** |
|
| 594 | - * Get the maximum number of time a discount can be used. |
|
| 595 | - * |
|
| 596 | - * @since 1.0.19 |
|
| 597 | - * @param string $context View or edit context. |
|
| 598 | - * @return int |
|
| 599 | - */ |
|
| 600 | - public function get_max_uses( $context = 'view' ) { |
|
| 601 | - $max_uses = $this->get_prop( 'max_uses', $context ); |
|
| 602 | - return empty( $max_uses ) ? null : $max_uses; |
|
| 603 | - } |
|
| 604 | - |
|
| 605 | - /** |
|
| 606 | - * Checks if this is a single use discount or not. |
|
| 607 | - * |
|
| 608 | - * @since 1.0.19 |
|
| 609 | - * @param string $context View or edit context. |
|
| 610 | - * @return bool |
|
| 611 | - */ |
|
| 612 | - public function get_is_single_use( $context = 'view' ) { |
|
| 613 | - return $this->get_prop( 'is_single_use', $context ); |
|
| 614 | - } |
|
| 615 | - |
|
| 616 | - /** |
|
| 617 | - * Get the items that can be used with this discount. |
|
| 618 | - * |
|
| 619 | - * @since 1.0.19 |
|
| 620 | - * @param string $context View or edit context. |
|
| 621 | - * @return array |
|
| 622 | - */ |
|
| 623 | - public function get_items( $context = 'view' ) { |
|
| 624 | - return wpinv_parse_list( $this->get_prop( 'items', $context ) ); |
|
| 625 | - } |
|
| 626 | - |
|
| 627 | - /** |
|
| 628 | - * Alias for self::get_items(). |
|
| 629 | - * |
|
| 630 | - * @since 1.0.19 |
|
| 631 | - * @param string $context View or edit context. |
|
| 632 | - * @return array |
|
| 633 | - */ |
|
| 634 | - public function get_allowed_items( $context = 'view' ) { |
|
| 635 | - return $this->get_items( $context ); |
|
| 636 | - } |
|
| 637 | - |
|
| 638 | - /** |
|
| 639 | - * Get the items that are not allowed to use this discount. |
|
| 640 | - * |
|
| 641 | - * @since 1.0.19 |
|
| 642 | - * @param string $context View or edit context. |
|
| 643 | - * @return array |
|
| 644 | - */ |
|
| 645 | - public function get_excluded_items( $context = 'view' ) { |
|
| 646 | - return wpinv_parse_list( $this->get_prop( 'excluded_items', $context ) ); |
|
| 647 | - } |
|
| 648 | - |
|
| 649 | - /** |
|
| 650 | - * Checks if this is a recurring discount or not. |
|
| 651 | - * |
|
| 652 | - * @since 1.0.19 |
|
| 653 | - * @param string $context View or edit context. |
|
| 654 | - * @return int|string|bool |
|
| 655 | - */ |
|
| 656 | - public function get_is_recurring( $context = 'view' ) { |
|
| 657 | - return $this->get_prop( 'is_recurring', $context ); |
|
| 658 | - } |
|
| 659 | - |
|
| 660 | - /** |
|
| 661 | - * Get's the minimum total amount allowed for this discount. |
|
| 662 | - * |
|
| 663 | - * @since 1.0.19 |
|
| 664 | - * @param string $context View or edit context. |
|
| 665 | - * @return float |
|
| 666 | - */ |
|
| 667 | - public function get_min_total( $context = 'view' ) { |
|
| 668 | - $minimum = $this->get_prop( 'min_total', $context ); |
|
| 669 | - return empty( $minimum ) ? null : $minimum; |
|
| 670 | - } |
|
| 671 | - |
|
| 672 | - /** |
|
| 673 | - * Alias for self::get_min_total(). |
|
| 674 | - * |
|
| 675 | - * @since 1.0.19 |
|
| 676 | - * @param string $context View or edit context. |
|
| 677 | - * @return float |
|
| 678 | - */ |
|
| 679 | - public function get_minimum_total( $context = 'view' ) { |
|
| 680 | - return $this->get_min_total( $context ); |
|
| 681 | - } |
|
| 682 | - |
|
| 683 | - /** |
|
| 684 | - * Get's the maximum total amount allowed for this discount. |
|
| 685 | - * |
|
| 686 | - * @since 1.0.19 |
|
| 687 | - * @param string $context View or edit context. |
|
| 688 | - * @return float |
|
| 689 | - */ |
|
| 690 | - public function get_max_total( $context = 'view' ) { |
|
| 691 | - $maximum = $this->get_prop( 'max_total', $context ); |
|
| 692 | - return empty( $maximum ) ? null : $maximum; |
|
| 693 | - } |
|
| 694 | - |
|
| 695 | - /** |
|
| 696 | - * Alias for self::get_max_total(). |
|
| 697 | - * |
|
| 698 | - * @since 1.0.19 |
|
| 699 | - * @param string $context View or edit context. |
|
| 700 | - * @return float |
|
| 701 | - */ |
|
| 702 | - public function get_maximum_total( $context = 'view' ) { |
|
| 703 | - return $this->get_max_total( $context ); |
|
| 704 | - } |
|
| 705 | - |
|
| 706 | - /** |
|
| 707 | - * Magic method for accessing discount properties. |
|
| 708 | - * |
|
| 709 | - * @since 1.0.15 |
|
| 710 | - * @access public |
|
| 711 | - * |
|
| 712 | - * @param string $key Discount data to retrieve |
|
| 713 | - * @param string $context View or edit context. |
|
| 714 | - * @return mixed Value of the given discount property (if set). |
|
| 715 | - */ |
|
| 716 | - public function get( $key, $context = 'view' ) { |
|
| 555 | + /** |
|
| 556 | + * Get the discount's type. |
|
| 557 | + * |
|
| 558 | + * @since 1.0.19 |
|
| 559 | + * @param string $context View or edit context. |
|
| 560 | + * @return string |
|
| 561 | + */ |
|
| 562 | + public function get_type( $context = 'view' ) { |
|
| 563 | + return $this->get_prop( 'type', $context ); |
|
| 564 | + } |
|
| 565 | + |
|
| 566 | + /** |
|
| 567 | + * Get the number of times a discount has been used. |
|
| 568 | + * |
|
| 569 | + * @since 1.0.19 |
|
| 570 | + * @param string $context View or edit context. |
|
| 571 | + * @return int |
|
| 572 | + */ |
|
| 573 | + public function get_uses( $context = 'view' ) { |
|
| 574 | + return (int) $this->get_prop( 'uses', $context ); |
|
| 575 | + } |
|
| 576 | + |
|
| 577 | + /** |
|
| 578 | + * Get the discount's usage, i.e uses / max uses. |
|
| 579 | + * |
|
| 580 | + * @since 1.0.19 |
|
| 581 | + * @return string |
|
| 582 | + */ |
|
| 583 | + public function get_usage() { |
|
| 584 | + |
|
| 585 | + if ( ! $this->has_limit() ) { |
|
| 586 | + return $this->get_uses() . ' / ' . ' ∞'; |
|
| 587 | + } |
|
| 588 | + |
|
| 589 | + return $this->get_uses() . ' / ' . (int) $this->get_max_uses(); |
|
| 590 | + |
|
| 591 | + } |
|
| 592 | + |
|
| 593 | + /** |
|
| 594 | + * Get the maximum number of time a discount can be used. |
|
| 595 | + * |
|
| 596 | + * @since 1.0.19 |
|
| 597 | + * @param string $context View or edit context. |
|
| 598 | + * @return int |
|
| 599 | + */ |
|
| 600 | + public function get_max_uses( $context = 'view' ) { |
|
| 601 | + $max_uses = $this->get_prop( 'max_uses', $context ); |
|
| 602 | + return empty( $max_uses ) ? null : $max_uses; |
|
| 603 | + } |
|
| 604 | + |
|
| 605 | + /** |
|
| 606 | + * Checks if this is a single use discount or not. |
|
| 607 | + * |
|
| 608 | + * @since 1.0.19 |
|
| 609 | + * @param string $context View or edit context. |
|
| 610 | + * @return bool |
|
| 611 | + */ |
|
| 612 | + public function get_is_single_use( $context = 'view' ) { |
|
| 613 | + return $this->get_prop( 'is_single_use', $context ); |
|
| 614 | + } |
|
| 615 | + |
|
| 616 | + /** |
|
| 617 | + * Get the items that can be used with this discount. |
|
| 618 | + * |
|
| 619 | + * @since 1.0.19 |
|
| 620 | + * @param string $context View or edit context. |
|
| 621 | + * @return array |
|
| 622 | + */ |
|
| 623 | + public function get_items( $context = 'view' ) { |
|
| 624 | + return wpinv_parse_list( $this->get_prop( 'items', $context ) ); |
|
| 625 | + } |
|
| 626 | + |
|
| 627 | + /** |
|
| 628 | + * Alias for self::get_items(). |
|
| 629 | + * |
|
| 630 | + * @since 1.0.19 |
|
| 631 | + * @param string $context View or edit context. |
|
| 632 | + * @return array |
|
| 633 | + */ |
|
| 634 | + public function get_allowed_items( $context = 'view' ) { |
|
| 635 | + return $this->get_items( $context ); |
|
| 636 | + } |
|
| 637 | + |
|
| 638 | + /** |
|
| 639 | + * Get the items that are not allowed to use this discount. |
|
| 640 | + * |
|
| 641 | + * @since 1.0.19 |
|
| 642 | + * @param string $context View or edit context. |
|
| 643 | + * @return array |
|
| 644 | + */ |
|
| 645 | + public function get_excluded_items( $context = 'view' ) { |
|
| 646 | + return wpinv_parse_list( $this->get_prop( 'excluded_items', $context ) ); |
|
| 647 | + } |
|
| 648 | + |
|
| 649 | + /** |
|
| 650 | + * Checks if this is a recurring discount or not. |
|
| 651 | + * |
|
| 652 | + * @since 1.0.19 |
|
| 653 | + * @param string $context View or edit context. |
|
| 654 | + * @return int|string|bool |
|
| 655 | + */ |
|
| 656 | + public function get_is_recurring( $context = 'view' ) { |
|
| 657 | + return $this->get_prop( 'is_recurring', $context ); |
|
| 658 | + } |
|
| 659 | + |
|
| 660 | + /** |
|
| 661 | + * Get's the minimum total amount allowed for this discount. |
|
| 662 | + * |
|
| 663 | + * @since 1.0.19 |
|
| 664 | + * @param string $context View or edit context. |
|
| 665 | + * @return float |
|
| 666 | + */ |
|
| 667 | + public function get_min_total( $context = 'view' ) { |
|
| 668 | + $minimum = $this->get_prop( 'min_total', $context ); |
|
| 669 | + return empty( $minimum ) ? null : $minimum; |
|
| 670 | + } |
|
| 671 | + |
|
| 672 | + /** |
|
| 673 | + * Alias for self::get_min_total(). |
|
| 674 | + * |
|
| 675 | + * @since 1.0.19 |
|
| 676 | + * @param string $context View or edit context. |
|
| 677 | + * @return float |
|
| 678 | + */ |
|
| 679 | + public function get_minimum_total( $context = 'view' ) { |
|
| 680 | + return $this->get_min_total( $context ); |
|
| 681 | + } |
|
| 682 | + |
|
| 683 | + /** |
|
| 684 | + * Get's the maximum total amount allowed for this discount. |
|
| 685 | + * |
|
| 686 | + * @since 1.0.19 |
|
| 687 | + * @param string $context View or edit context. |
|
| 688 | + * @return float |
|
| 689 | + */ |
|
| 690 | + public function get_max_total( $context = 'view' ) { |
|
| 691 | + $maximum = $this->get_prop( 'max_total', $context ); |
|
| 692 | + return empty( $maximum ) ? null : $maximum; |
|
| 693 | + } |
|
| 694 | + |
|
| 695 | + /** |
|
| 696 | + * Alias for self::get_max_total(). |
|
| 697 | + * |
|
| 698 | + * @since 1.0.19 |
|
| 699 | + * @param string $context View or edit context. |
|
| 700 | + * @return float |
|
| 701 | + */ |
|
| 702 | + public function get_maximum_total( $context = 'view' ) { |
|
| 703 | + return $this->get_max_total( $context ); |
|
| 704 | + } |
|
| 705 | + |
|
| 706 | + /** |
|
| 707 | + * Magic method for accessing discount properties. |
|
| 708 | + * |
|
| 709 | + * @since 1.0.15 |
|
| 710 | + * @access public |
|
| 711 | + * |
|
| 712 | + * @param string $key Discount data to retrieve |
|
| 713 | + * @param string $context View or edit context. |
|
| 714 | + * @return mixed Value of the given discount property (if set). |
|
| 715 | + */ |
|
| 716 | + public function get( $key, $context = 'view' ) { |
|
| 717 | 717 | return $this->get_prop( $key, $context ); |
| 718 | - } |
|
| 718 | + } |
|
| 719 | 719 | |
| 720 | - /* |
|
| 720 | + /* |
|
| 721 | 721 | |-------------------------------------------------------------------------- |
| 722 | 722 | | Setters |
| 723 | 723 | |-------------------------------------------------------------------------- |
@@ -727,41 +727,41 @@ discard block |
||
| 727 | 727 | | object. |
| 728 | 728 | */ |
| 729 | 729 | |
| 730 | - /** |
|
| 731 | - * Sets discount status. |
|
| 732 | - * |
|
| 733 | - * @since 1.0.19 |
|
| 734 | - * @param string $status New status. |
|
| 735 | - * @return array details of change. |
|
| 736 | - */ |
|
| 737 | - public function set_status( $status ) { |
|
| 730 | + /** |
|
| 731 | + * Sets discount status. |
|
| 732 | + * |
|
| 733 | + * @since 1.0.19 |
|
| 734 | + * @param string $status New status. |
|
| 735 | + * @return array details of change. |
|
| 736 | + */ |
|
| 737 | + public function set_status( $status ) { |
|
| 738 | 738 | $old_status = $this->get_status(); |
| 739 | 739 | |
| 740 | 740 | $this->set_prop( 'status', $status ); |
| 741 | 741 | |
| 742 | - return array( |
|
| 743 | - 'from' => $old_status, |
|
| 744 | - 'to' => $status, |
|
| 745 | - ); |
|
| 742 | + return array( |
|
| 743 | + 'from' => $old_status, |
|
| 744 | + 'to' => $status, |
|
| 745 | + ); |
|
| 746 | 746 | } |
| 747 | 747 | |
| 748 | 748 | /** |
| 749 | - * Set plugin version when the discount was created. |
|
| 750 | - * |
|
| 751 | - * @since 1.0.19 |
|
| 752 | - */ |
|
| 753 | - public function set_version( $value ) { |
|
| 754 | - $this->set_prop( 'version', $value ); |
|
| 749 | + * Set plugin version when the discount was created. |
|
| 750 | + * |
|
| 751 | + * @since 1.0.19 |
|
| 752 | + */ |
|
| 753 | + public function set_version( $value ) { |
|
| 754 | + $this->set_prop( 'version', $value ); |
|
| 755 | 755 | } |
| 756 | 756 | |
| 757 | 757 | /** |
| 758 | - * Set date when the discount was created. |
|
| 759 | - * |
|
| 760 | - * @since 1.0.19 |
|
| 761 | - * @param string $value Value to set. |
|
| 758 | + * Set date when the discount was created. |
|
| 759 | + * |
|
| 760 | + * @since 1.0.19 |
|
| 761 | + * @param string $value Value to set. |
|
| 762 | 762 | * @return bool Whether or not the date was set. |
| 763 | - */ |
|
| 764 | - public function set_date_created( $value ) { |
|
| 763 | + */ |
|
| 764 | + public function set_date_created( $value ) { |
|
| 765 | 765 | $date = strtotime( $value ); |
| 766 | 766 | |
| 767 | 767 | if ( $date ) { |
@@ -774,13 +774,13 @@ discard block |
||
| 774 | 774 | } |
| 775 | 775 | |
| 776 | 776 | /** |
| 777 | - * Set date when the discount was last modified. |
|
| 778 | - * |
|
| 779 | - * @since 1.0.19 |
|
| 780 | - * @param string $value Value to set. |
|
| 777 | + * Set date when the discount was last modified. |
|
| 778 | + * |
|
| 779 | + * @since 1.0.19 |
|
| 780 | + * @param string $value Value to set. |
|
| 781 | 781 | * @return bool Whether or not the date was set. |
| 782 | - */ |
|
| 783 | - public function set_date_modified( $value ) { |
|
| 782 | + */ |
|
| 783 | + public function set_date_modified( $value ) { |
|
| 784 | 784 | $date = strtotime( $value ); |
| 785 | 785 | |
| 786 | 786 | if ( $date ) { |
@@ -793,324 +793,324 @@ discard block |
||
| 793 | 793 | } |
| 794 | 794 | |
| 795 | 795 | /** |
| 796 | - * Set the discount name. |
|
| 797 | - * |
|
| 798 | - * @since 1.0.19 |
|
| 799 | - * @param string $value New name. |
|
| 800 | - */ |
|
| 801 | - public function set_name( $value ) { |
|
| 796 | + * Set the discount name. |
|
| 797 | + * |
|
| 798 | + * @since 1.0.19 |
|
| 799 | + * @param string $value New name. |
|
| 800 | + */ |
|
| 801 | + public function set_name( $value ) { |
|
| 802 | 802 | $name = sanitize_text_field( $value ); |
| 803 | - $this->set_prop( 'name', $name ); |
|
| 803 | + $this->set_prop( 'name', $name ); |
|
| 804 | 804 | } |
| 805 | 805 | |
| 806 | 806 | /** |
| 807 | - * Alias of self::set_name(). |
|
| 808 | - * |
|
| 809 | - * @since 1.0.19 |
|
| 810 | - * @param string $value New name. |
|
| 811 | - */ |
|
| 812 | - public function set_title( $value ) { |
|
| 813 | - $this->set_name( $value ); |
|
| 807 | + * Alias of self::set_name(). |
|
| 808 | + * |
|
| 809 | + * @since 1.0.19 |
|
| 810 | + * @param string $value New name. |
|
| 811 | + */ |
|
| 812 | + public function set_title( $value ) { |
|
| 813 | + $this->set_name( $value ); |
|
| 814 | 814 | } |
| 815 | 815 | |
| 816 | 816 | /** |
| 817 | - * Set the discount description. |
|
| 818 | - * |
|
| 819 | - * @since 1.0.19 |
|
| 820 | - * @param string $value New description. |
|
| 821 | - */ |
|
| 822 | - public function set_description( $value ) { |
|
| 817 | + * Set the discount description. |
|
| 818 | + * |
|
| 819 | + * @since 1.0.19 |
|
| 820 | + * @param string $value New description. |
|
| 821 | + */ |
|
| 822 | + public function set_description( $value ) { |
|
| 823 | 823 | $description = wp_kses_post( $value ); |
| 824 | - return $this->set_prop( 'description', $description ); |
|
| 824 | + return $this->set_prop( 'description', $description ); |
|
| 825 | 825 | } |
| 826 | 826 | |
| 827 | 827 | /** |
| 828 | - * Alias of self::set_description(). |
|
| 829 | - * |
|
| 830 | - * @since 1.0.19 |
|
| 831 | - * @param string $value New description. |
|
| 832 | - */ |
|
| 833 | - public function set_excerpt( $value ) { |
|
| 834 | - $this->set_description( $value ); |
|
| 828 | + * Alias of self::set_description(). |
|
| 829 | + * |
|
| 830 | + * @since 1.0.19 |
|
| 831 | + * @param string $value New description. |
|
| 832 | + */ |
|
| 833 | + public function set_excerpt( $value ) { |
|
| 834 | + $this->set_description( $value ); |
|
| 835 | 835 | } |
| 836 | 836 | |
| 837 | 837 | /** |
| 838 | - * Alias of self::set_description(). |
|
| 839 | - * |
|
| 840 | - * @since 1.0.19 |
|
| 841 | - * @param string $value New description. |
|
| 842 | - */ |
|
| 843 | - public function set_summary( $value ) { |
|
| 844 | - $this->set_description( $value ); |
|
| 838 | + * Alias of self::set_description(). |
|
| 839 | + * |
|
| 840 | + * @since 1.0.19 |
|
| 841 | + * @param string $value New description. |
|
| 842 | + */ |
|
| 843 | + public function set_summary( $value ) { |
|
| 844 | + $this->set_description( $value ); |
|
| 845 | 845 | } |
| 846 | 846 | |
| 847 | 847 | /** |
| 848 | - * Set the owner of the discount. |
|
| 849 | - * |
|
| 850 | - * @since 1.0.19 |
|
| 851 | - * @param int $value New author. |
|
| 852 | - */ |
|
| 853 | - public function set_author( $value ) { |
|
| 854 | - $this->set_prop( 'author', (int) $value ); |
|
| 855 | - } |
|
| 848 | + * Set the owner of the discount. |
|
| 849 | + * |
|
| 850 | + * @since 1.0.19 |
|
| 851 | + * @param int $value New author. |
|
| 852 | + */ |
|
| 853 | + public function set_author( $value ) { |
|
| 854 | + $this->set_prop( 'author', (int) $value ); |
|
| 855 | + } |
|
| 856 | 856 | |
| 857 | - /** |
|
| 858 | - * Sets the discount code. |
|
| 859 | - * |
|
| 860 | - * @since 1.0.19 |
|
| 861 | - * @param string $value New discount code. |
|
| 862 | - */ |
|
| 863 | - public function set_code( $value ) { |
|
| 864 | - $code = sanitize_text_field( $value ); |
|
| 865 | - $this->set_prop( 'code', $code ); |
|
| 866 | - } |
|
| 857 | + /** |
|
| 858 | + * Sets the discount code. |
|
| 859 | + * |
|
| 860 | + * @since 1.0.19 |
|
| 861 | + * @param string $value New discount code. |
|
| 862 | + */ |
|
| 863 | + public function set_code( $value ) { |
|
| 864 | + $code = sanitize_text_field( $value ); |
|
| 865 | + $this->set_prop( 'code', $code ); |
|
| 866 | + } |
|
| 867 | 867 | |
| 868 | - /** |
|
| 869 | - * Alias of self::set_code(). |
|
| 870 | - * |
|
| 871 | - * @since 1.0.19 |
|
| 872 | - * @param string $value New discount code. |
|
| 873 | - */ |
|
| 874 | - public function set_coupon_code( $value ) { |
|
| 875 | - $this->set_code( $value ); |
|
| 876 | - } |
|
| 868 | + /** |
|
| 869 | + * Alias of self::set_code(). |
|
| 870 | + * |
|
| 871 | + * @since 1.0.19 |
|
| 872 | + * @param string $value New discount code. |
|
| 873 | + */ |
|
| 874 | + public function set_coupon_code( $value ) { |
|
| 875 | + $this->set_code( $value ); |
|
| 876 | + } |
|
| 877 | 877 | |
| 878 | - /** |
|
| 879 | - * Alias of self::set_code(). |
|
| 880 | - * |
|
| 881 | - * @since 1.0.19 |
|
| 882 | - * @param string $value New discount code. |
|
| 883 | - */ |
|
| 884 | - public function set_discount_code( $value ) { |
|
| 885 | - $this->set_code( $value ); |
|
| 886 | - } |
|
| 878 | + /** |
|
| 879 | + * Alias of self::set_code(). |
|
| 880 | + * |
|
| 881 | + * @since 1.0.19 |
|
| 882 | + * @param string $value New discount code. |
|
| 883 | + */ |
|
| 884 | + public function set_discount_code( $value ) { |
|
| 885 | + $this->set_code( $value ); |
|
| 886 | + } |
|
| 887 | 887 | |
| 888 | - /** |
|
| 889 | - * Sets the discount amount. |
|
| 890 | - * |
|
| 891 | - * @since 1.0.19 |
|
| 892 | - * @param float $value New discount code. |
|
| 893 | - */ |
|
| 894 | - public function set_amount( $value ) { |
|
| 895 | - $amount = floatval( wpinv_sanitize_amount( $value ) ); |
|
| 896 | - $this->set_prop( 'amount', $amount ); |
|
| 897 | - } |
|
| 898 | - |
|
| 899 | - /** |
|
| 900 | - * Sets the discount's start date. |
|
| 901 | - * |
|
| 902 | - * @since 1.0.19 |
|
| 903 | - * @param float $value New start date. |
|
| 904 | - */ |
|
| 905 | - public function set_start( $value ) { |
|
| 906 | - $date = strtotime( $value ); |
|
| 888 | + /** |
|
| 889 | + * Sets the discount amount. |
|
| 890 | + * |
|
| 891 | + * @since 1.0.19 |
|
| 892 | + * @param float $value New discount code. |
|
| 893 | + */ |
|
| 894 | + public function set_amount( $value ) { |
|
| 895 | + $amount = floatval( wpinv_sanitize_amount( $value ) ); |
|
| 896 | + $this->set_prop( 'amount', $amount ); |
|
| 897 | + } |
|
| 907 | 898 | |
| 908 | - if ( $date ) { |
|
| 909 | - $this->set_prop( 'start', date( 'Y-m-d H:i', $date ) ); |
|
| 910 | - return true; |
|
| 911 | - } |
|
| 899 | + /** |
|
| 900 | + * Sets the discount's start date. |
|
| 901 | + * |
|
| 902 | + * @since 1.0.19 |
|
| 903 | + * @param float $value New start date. |
|
| 904 | + */ |
|
| 905 | + public function set_start( $value ) { |
|
| 906 | + $date = strtotime( $value ); |
|
| 907 | + |
|
| 908 | + if ( $date ) { |
|
| 909 | + $this->set_prop( 'start', date( 'Y-m-d H:i', $date ) ); |
|
| 910 | + return true; |
|
| 911 | + } |
|
| 912 | 912 | |
| 913 | - $this->set_prop( 'start', '' ); |
|
| 913 | + $this->set_prop( 'start', '' ); |
|
| 914 | 914 | |
| 915 | 915 | return false; |
| 916 | - } |
|
| 917 | - |
|
| 918 | - /** |
|
| 919 | - * Alias of self::set_start(). |
|
| 920 | - * |
|
| 921 | - * @since 1.0.19 |
|
| 922 | - * @param string $value New start date. |
|
| 923 | - */ |
|
| 924 | - public function set_start_date( $value ) { |
|
| 925 | - $this->set_start( $value ); |
|
| 926 | - } |
|
| 927 | - |
|
| 928 | - /** |
|
| 929 | - * Sets the discount's expiration date. |
|
| 930 | - * |
|
| 931 | - * @since 1.0.19 |
|
| 932 | - * @param float $value New expiration date. |
|
| 933 | - */ |
|
| 934 | - public function set_expiration( $value ) { |
|
| 935 | - $date = strtotime( $value ); |
|
| 916 | + } |
|
| 917 | + |
|
| 918 | + /** |
|
| 919 | + * Alias of self::set_start(). |
|
| 920 | + * |
|
| 921 | + * @since 1.0.19 |
|
| 922 | + * @param string $value New start date. |
|
| 923 | + */ |
|
| 924 | + public function set_start_date( $value ) { |
|
| 925 | + $this->set_start( $value ); |
|
| 926 | + } |
|
| 927 | + |
|
| 928 | + /** |
|
| 929 | + * Sets the discount's expiration date. |
|
| 930 | + * |
|
| 931 | + * @since 1.0.19 |
|
| 932 | + * @param float $value New expiration date. |
|
| 933 | + */ |
|
| 934 | + public function set_expiration( $value ) { |
|
| 935 | + $date = strtotime( $value ); |
|
| 936 | 936 | |
| 937 | 937 | if ( $date ) { |
| 938 | 938 | $this->set_prop( 'expiration', date( 'Y-m-d H:i', $date ) ); |
| 939 | 939 | return true; |
| 940 | 940 | } |
| 941 | 941 | |
| 942 | - $this->set_prop( 'expiration', '' ); |
|
| 942 | + $this->set_prop( 'expiration', '' ); |
|
| 943 | 943 | return false; |
| 944 | - } |
|
| 945 | - |
|
| 946 | - /** |
|
| 947 | - * Alias of self::set_expiration(). |
|
| 948 | - * |
|
| 949 | - * @since 1.0.19 |
|
| 950 | - * @param string $value New expiration date. |
|
| 951 | - */ |
|
| 952 | - public function set_expiration_date( $value ) { |
|
| 953 | - $this->set_expiration( $value ); |
|
| 954 | - } |
|
| 955 | - |
|
| 956 | - /** |
|
| 957 | - * Alias of self::set_expiration(). |
|
| 958 | - * |
|
| 959 | - * @since 1.0.19 |
|
| 960 | - * @param string $value New expiration date. |
|
| 961 | - */ |
|
| 962 | - public function set_end_date( $value ) { |
|
| 963 | - $this->set_expiration( $value ); |
|
| 964 | - } |
|
| 965 | - |
|
| 966 | - /** |
|
| 967 | - * Sets the discount type. |
|
| 968 | - * |
|
| 969 | - * @since 1.0.19 |
|
| 970 | - * @param string $value New discount type. |
|
| 971 | - */ |
|
| 972 | - public function set_type( $value ) { |
|
| 973 | - if ( $value && array_key_exists( sanitize_text_field( $value ), wpinv_get_discount_types() ) ) { |
|
| 974 | - $this->set_prop( 'type', sanitize_text_field( $value ) ); |
|
| 975 | - } |
|
| 976 | - } |
|
| 977 | - |
|
| 978 | - /** |
|
| 979 | - * Sets the number of times a discount has been used. |
|
| 980 | - * |
|
| 981 | - * @since 1.0.19 |
|
| 982 | - * @param int $value usage count. |
|
| 983 | - */ |
|
| 984 | - public function set_uses( $value ) { |
|
| 985 | - |
|
| 986 | - $value = (int) $value; |
|
| 987 | - |
|
| 988 | - if ( $value < 0 ) { |
|
| 989 | - $value = 0; |
|
| 990 | - } |
|
| 991 | - |
|
| 992 | - $this->set_prop( 'uses', (int) $value ); |
|
| 993 | - } |
|
| 994 | - |
|
| 995 | - /** |
|
| 996 | - * Sets the maximum number of times a discount can be used. |
|
| 997 | - * |
|
| 998 | - * @since 1.0.19 |
|
| 999 | - * @param int $value maximum usage count. |
|
| 1000 | - */ |
|
| 1001 | - public function set_max_uses( $value ) { |
|
| 1002 | - $this->set_prop( 'max_uses', absint( $value ) ); |
|
| 1003 | - } |
|
| 1004 | - |
|
| 1005 | - /** |
|
| 1006 | - * Sets if this is a single use discount or not. |
|
| 1007 | - * |
|
| 1008 | - * @since 1.0.19 |
|
| 1009 | - * @param int|bool $value is single use. |
|
| 1010 | - */ |
|
| 1011 | - public function set_is_single_use( $value ) { |
|
| 1012 | - $this->set_prop( 'is_single_use', (bool) $value ); |
|
| 1013 | - } |
|
| 1014 | - |
|
| 1015 | - /** |
|
| 1016 | - * Sets the items that can be used with this discount. |
|
| 1017 | - * |
|
| 1018 | - * @since 1.0.19 |
|
| 1019 | - * @param array $value items. |
|
| 1020 | - */ |
|
| 1021 | - public function set_items( $value ) { |
|
| 1022 | - $this->set_prop( 'items', wpinv_parse_list( $value ) ); |
|
| 1023 | - } |
|
| 1024 | - |
|
| 1025 | - /** |
|
| 1026 | - * Alias for self::set_items(). |
|
| 1027 | - * |
|
| 1028 | - * @since 1.0.19 |
|
| 1029 | - * @param array $value items. |
|
| 1030 | - */ |
|
| 1031 | - public function set_allowed_items( $value ) { |
|
| 1032 | - $this->set_items( $value ); |
|
| 1033 | - } |
|
| 1034 | - |
|
| 1035 | - /** |
|
| 1036 | - * Sets the items that can not be used with this discount. |
|
| 1037 | - * |
|
| 1038 | - * @since 1.0.19 |
|
| 1039 | - * @param array $value items. |
|
| 1040 | - */ |
|
| 1041 | - public function set_excluded_items( $value ) { |
|
| 1042 | - $this->set_prop( 'excluded_items', wpinv_parse_list( $value ) ); |
|
| 1043 | - } |
|
| 1044 | - |
|
| 1045 | - /** |
|
| 1046 | - * Sets if this is a recurring discounts or not. |
|
| 1047 | - * |
|
| 1048 | - * @since 1.0.19 |
|
| 1049 | - * @param int|bool $value is recurring. |
|
| 1050 | - */ |
|
| 1051 | - public function set_is_recurring( $value ) { |
|
| 1052 | - $this->set_prop( 'is_recurring', (bool) $value ); |
|
| 1053 | - } |
|
| 1054 | - |
|
| 1055 | - /** |
|
| 1056 | - * Sets the minimum total that can not be used with this discount. |
|
| 1057 | - * |
|
| 1058 | - * @since 1.0.19 |
|
| 1059 | - * @param float $value minimum total. |
|
| 1060 | - */ |
|
| 1061 | - public function set_min_total( $value ) { |
|
| 1062 | - $this->set_prop( 'min_total', (float) wpinv_sanitize_amount( $value ) ); |
|
| 1063 | - } |
|
| 1064 | - |
|
| 1065 | - /** |
|
| 1066 | - * Alias for self::set_min_total(). |
|
| 1067 | - * |
|
| 1068 | - * @since 1.0.19 |
|
| 1069 | - * @param float $value minimum total. |
|
| 1070 | - */ |
|
| 1071 | - public function set_minimum_total( $value ) { |
|
| 1072 | - $this->set_min_total( $value ); |
|
| 1073 | - } |
|
| 1074 | - |
|
| 1075 | - /** |
|
| 1076 | - * Sets the maximum total that can not be used with this discount. |
|
| 1077 | - * |
|
| 1078 | - * @since 1.0.19 |
|
| 1079 | - * @param float $value maximum total. |
|
| 1080 | - */ |
|
| 1081 | - public function set_max_total( $value ) { |
|
| 1082 | - $this->set_prop( 'max_total', (float) wpinv_sanitize_amount( $value ) ); |
|
| 1083 | - } |
|
| 1084 | - |
|
| 1085 | - /** |
|
| 1086 | - * Alias for self::set_max_total(). |
|
| 1087 | - * |
|
| 1088 | - * @since 1.0.19 |
|
| 1089 | - * @param float $value maximum total. |
|
| 1090 | - */ |
|
| 1091 | - public function set_maximum_total( $value ) { |
|
| 1092 | - $this->set_max_total( $value ); |
|
| 1093 | - } |
|
| 1094 | - |
|
| 1095 | - /** |
|
| 1096 | - * @deprecated |
|
| 1097 | - */ |
|
| 1098 | - public function refresh(){} |
|
| 1099 | - |
|
| 1100 | - /** |
|
| 1101 | - * @deprecated |
|
| 1102 | - * |
|
| 1103 | - */ |
|
| 1104 | - public function update_status( $status = 'publish' ){ |
|
| 1105 | - |
|
| 1106 | - if ( $this->exists() && $this->get_status() != $status ) { |
|
| 1107 | - $this->set_status( $status ); |
|
| 1108 | - $this->save(); |
|
| 1109 | - } |
|
| 1110 | - |
|
| 1111 | - } |
|
| 1112 | - |
|
| 1113 | - /* |
|
| 944 | + } |
|
| 945 | + |
|
| 946 | + /** |
|
| 947 | + * Alias of self::set_expiration(). |
|
| 948 | + * |
|
| 949 | + * @since 1.0.19 |
|
| 950 | + * @param string $value New expiration date. |
|
| 951 | + */ |
|
| 952 | + public function set_expiration_date( $value ) { |
|
| 953 | + $this->set_expiration( $value ); |
|
| 954 | + } |
|
| 955 | + |
|
| 956 | + /** |
|
| 957 | + * Alias of self::set_expiration(). |
|
| 958 | + * |
|
| 959 | + * @since 1.0.19 |
|
| 960 | + * @param string $value New expiration date. |
|
| 961 | + */ |
|
| 962 | + public function set_end_date( $value ) { |
|
| 963 | + $this->set_expiration( $value ); |
|
| 964 | + } |
|
| 965 | + |
|
| 966 | + /** |
|
| 967 | + * Sets the discount type. |
|
| 968 | + * |
|
| 969 | + * @since 1.0.19 |
|
| 970 | + * @param string $value New discount type. |
|
| 971 | + */ |
|
| 972 | + public function set_type( $value ) { |
|
| 973 | + if ( $value && array_key_exists( sanitize_text_field( $value ), wpinv_get_discount_types() ) ) { |
|
| 974 | + $this->set_prop( 'type', sanitize_text_field( $value ) ); |
|
| 975 | + } |
|
| 976 | + } |
|
| 977 | + |
|
| 978 | + /** |
|
| 979 | + * Sets the number of times a discount has been used. |
|
| 980 | + * |
|
| 981 | + * @since 1.0.19 |
|
| 982 | + * @param int $value usage count. |
|
| 983 | + */ |
|
| 984 | + public function set_uses( $value ) { |
|
| 985 | + |
|
| 986 | + $value = (int) $value; |
|
| 987 | + |
|
| 988 | + if ( $value < 0 ) { |
|
| 989 | + $value = 0; |
|
| 990 | + } |
|
| 991 | + |
|
| 992 | + $this->set_prop( 'uses', (int) $value ); |
|
| 993 | + } |
|
| 994 | + |
|
| 995 | + /** |
|
| 996 | + * Sets the maximum number of times a discount can be used. |
|
| 997 | + * |
|
| 998 | + * @since 1.0.19 |
|
| 999 | + * @param int $value maximum usage count. |
|
| 1000 | + */ |
|
| 1001 | + public function set_max_uses( $value ) { |
|
| 1002 | + $this->set_prop( 'max_uses', absint( $value ) ); |
|
| 1003 | + } |
|
| 1004 | + |
|
| 1005 | + /** |
|
| 1006 | + * Sets if this is a single use discount or not. |
|
| 1007 | + * |
|
| 1008 | + * @since 1.0.19 |
|
| 1009 | + * @param int|bool $value is single use. |
|
| 1010 | + */ |
|
| 1011 | + public function set_is_single_use( $value ) { |
|
| 1012 | + $this->set_prop( 'is_single_use', (bool) $value ); |
|
| 1013 | + } |
|
| 1014 | + |
|
| 1015 | + /** |
|
| 1016 | + * Sets the items that can be used with this discount. |
|
| 1017 | + * |
|
| 1018 | + * @since 1.0.19 |
|
| 1019 | + * @param array $value items. |
|
| 1020 | + */ |
|
| 1021 | + public function set_items( $value ) { |
|
| 1022 | + $this->set_prop( 'items', wpinv_parse_list( $value ) ); |
|
| 1023 | + } |
|
| 1024 | + |
|
| 1025 | + /** |
|
| 1026 | + * Alias for self::set_items(). |
|
| 1027 | + * |
|
| 1028 | + * @since 1.0.19 |
|
| 1029 | + * @param array $value items. |
|
| 1030 | + */ |
|
| 1031 | + public function set_allowed_items( $value ) { |
|
| 1032 | + $this->set_items( $value ); |
|
| 1033 | + } |
|
| 1034 | + |
|
| 1035 | + /** |
|
| 1036 | + * Sets the items that can not be used with this discount. |
|
| 1037 | + * |
|
| 1038 | + * @since 1.0.19 |
|
| 1039 | + * @param array $value items. |
|
| 1040 | + */ |
|
| 1041 | + public function set_excluded_items( $value ) { |
|
| 1042 | + $this->set_prop( 'excluded_items', wpinv_parse_list( $value ) ); |
|
| 1043 | + } |
|
| 1044 | + |
|
| 1045 | + /** |
|
| 1046 | + * Sets if this is a recurring discounts or not. |
|
| 1047 | + * |
|
| 1048 | + * @since 1.0.19 |
|
| 1049 | + * @param int|bool $value is recurring. |
|
| 1050 | + */ |
|
| 1051 | + public function set_is_recurring( $value ) { |
|
| 1052 | + $this->set_prop( 'is_recurring', (bool) $value ); |
|
| 1053 | + } |
|
| 1054 | + |
|
| 1055 | + /** |
|
| 1056 | + * Sets the minimum total that can not be used with this discount. |
|
| 1057 | + * |
|
| 1058 | + * @since 1.0.19 |
|
| 1059 | + * @param float $value minimum total. |
|
| 1060 | + */ |
|
| 1061 | + public function set_min_total( $value ) { |
|
| 1062 | + $this->set_prop( 'min_total', (float) wpinv_sanitize_amount( $value ) ); |
|
| 1063 | + } |
|
| 1064 | + |
|
| 1065 | + /** |
|
| 1066 | + * Alias for self::set_min_total(). |
|
| 1067 | + * |
|
| 1068 | + * @since 1.0.19 |
|
| 1069 | + * @param float $value minimum total. |
|
| 1070 | + */ |
|
| 1071 | + public function set_minimum_total( $value ) { |
|
| 1072 | + $this->set_min_total( $value ); |
|
| 1073 | + } |
|
| 1074 | + |
|
| 1075 | + /** |
|
| 1076 | + * Sets the maximum total that can not be used with this discount. |
|
| 1077 | + * |
|
| 1078 | + * @since 1.0.19 |
|
| 1079 | + * @param float $value maximum total. |
|
| 1080 | + */ |
|
| 1081 | + public function set_max_total( $value ) { |
|
| 1082 | + $this->set_prop( 'max_total', (float) wpinv_sanitize_amount( $value ) ); |
|
| 1083 | + } |
|
| 1084 | + |
|
| 1085 | + /** |
|
| 1086 | + * Alias for self::set_max_total(). |
|
| 1087 | + * |
|
| 1088 | + * @since 1.0.19 |
|
| 1089 | + * @param float $value maximum total. |
|
| 1090 | + */ |
|
| 1091 | + public function set_maximum_total( $value ) { |
|
| 1092 | + $this->set_max_total( $value ); |
|
| 1093 | + } |
|
| 1094 | + |
|
| 1095 | + /** |
|
| 1096 | + * @deprecated |
|
| 1097 | + */ |
|
| 1098 | + public function refresh(){} |
|
| 1099 | + |
|
| 1100 | + /** |
|
| 1101 | + * @deprecated |
|
| 1102 | + * |
|
| 1103 | + */ |
|
| 1104 | + public function update_status( $status = 'publish' ){ |
|
| 1105 | + |
|
| 1106 | + if ( $this->exists() && $this->get_status() != $status ) { |
|
| 1107 | + $this->set_status( $status ); |
|
| 1108 | + $this->save(); |
|
| 1109 | + } |
|
| 1110 | + |
|
| 1111 | + } |
|
| 1112 | + |
|
| 1113 | + /* |
|
| 1114 | 1114 | |-------------------------------------------------------------------------- |
| 1115 | 1115 | | Conditionals |
| 1116 | 1116 | |-------------------------------------------------------------------------- |
@@ -1119,263 +1119,263 @@ discard block |
||
| 1119 | 1119 | | |
| 1120 | 1120 | */ |
| 1121 | 1121 | |
| 1122 | - /** |
|
| 1123 | - * Checks whether a discount exists in the database or not |
|
| 1124 | - * |
|
| 1125 | - * @since 1.0.15 |
|
| 1126 | - */ |
|
| 1127 | - public function exists(){ |
|
| 1128 | - $id = $this->get_id(); |
|
| 1129 | - return ! empty( $id ); |
|
| 1130 | - } |
|
| 1131 | - |
|
| 1132 | - /** |
|
| 1133 | - * Checks the discount type. |
|
| 1134 | - * |
|
| 1135 | - * |
|
| 1136 | - * @param string $type the discount type to check against |
|
| 1137 | - * @since 1.0.15 |
|
| 1138 | - * @return bool |
|
| 1139 | - */ |
|
| 1140 | - public function is_type( $type ) { |
|
| 1141 | - return $this->get_type() == $type; |
|
| 1142 | - } |
|
| 1143 | - |
|
| 1144 | - /** |
|
| 1145 | - * Checks whether the discount is published or not |
|
| 1146 | - * |
|
| 1147 | - * @since 1.0.15 |
|
| 1148 | - * @return bool |
|
| 1149 | - */ |
|
| 1150 | - public function is_active() { |
|
| 1151 | - return $this->get_status() == 'publish'; |
|
| 1152 | - } |
|
| 1153 | - |
|
| 1154 | - /** |
|
| 1155 | - * Checks whether the discount has max uses |
|
| 1156 | - * |
|
| 1157 | - * @since 1.0.15 |
|
| 1158 | - * @return bool |
|
| 1159 | - */ |
|
| 1160 | - public function has_limit() { |
|
| 1161 | - $limit = $this->get_max_uses(); |
|
| 1162 | - return ! empty( $limit ); |
|
| 1163 | - } |
|
| 1164 | - |
|
| 1165 | - /** |
|
| 1166 | - * Checks whether the discount has ever been used. |
|
| 1167 | - * |
|
| 1168 | - * @since 1.0.15 |
|
| 1169 | - * @return bool |
|
| 1170 | - */ |
|
| 1171 | - public function has_uses() { |
|
| 1172 | - return $this->get_uses() > 0; |
|
| 1173 | - } |
|
| 1174 | - |
|
| 1175 | - /** |
|
| 1176 | - * Checks whether the discount is has exided the usage limit or not |
|
| 1177 | - * |
|
| 1178 | - * @since 1.0.15 |
|
| 1179 | - * @return bool |
|
| 1180 | - */ |
|
| 1181 | - public function has_exceeded_limit() { |
|
| 1182 | - |
|
| 1183 | - if ( ! $this->has_limit() || ! $this->has_uses() ) { |
|
| 1184 | - $exceeded = false ; |
|
| 1185 | - } else { |
|
| 1186 | - $exceeded = ! ( (int) $this->get_max_uses() < $this->get_uses() ); |
|
| 1187 | - } |
|
| 1188 | - |
|
| 1189 | - return apply_filters( 'wpinv_is_discount_maxed_out', $exceeded, $this->get_id(), $this, $this->get_code() ); |
|
| 1190 | - } |
|
| 1191 | - |
|
| 1192 | - /** |
|
| 1193 | - * Checks whether the discount has an expiration date. |
|
| 1194 | - * |
|
| 1195 | - * @since 1.0.15 |
|
| 1196 | - * @return bool |
|
| 1197 | - */ |
|
| 1198 | - public function has_expiration_date() { |
|
| 1199 | - $date = $this->get_expiration_date(); |
|
| 1200 | - return ! empty( $date ); |
|
| 1201 | - } |
|
| 1202 | - |
|
| 1203 | - /** |
|
| 1204 | - * Checks if the discount is expired |
|
| 1205 | - * |
|
| 1206 | - * @since 1.0.15 |
|
| 1207 | - * @return bool |
|
| 1208 | - */ |
|
| 1209 | - public function is_expired() { |
|
| 1210 | - $expired = $this->has_expiration_date() ? current_time( 'timestamp' ) > strtotime( $this->get_expiration_date() ) : false; |
|
| 1211 | - return apply_filters( 'wpinv_is_discount_expired', $expired, $this->get_id(), $this, $this->get_code() ); |
|
| 1212 | - } |
|
| 1213 | - |
|
| 1214 | - /** |
|
| 1215 | - * Checks whether the discount has a start date. |
|
| 1216 | - * |
|
| 1217 | - * @since 1.0.15 |
|
| 1218 | - * @return bool |
|
| 1219 | - */ |
|
| 1220 | - public function has_start_date() { |
|
| 1221 | - $date = $this->get_start_date(); |
|
| 1222 | - return ! empty( $date ); |
|
| 1223 | - } |
|
| 1224 | - |
|
| 1225 | - /** |
|
| 1226 | - * Checks the discount start date. |
|
| 1227 | - * |
|
| 1228 | - * @since 1.0.15 |
|
| 1229 | - * @return bool |
|
| 1230 | - */ |
|
| 1231 | - public function has_started() { |
|
| 1232 | - $started = $this->has_start_date() ? true : current_time( 'timestamp' ) > strtotime( $this->get_start_date() ); |
|
| 1233 | - return apply_filters( 'wpinv_is_discount_started', $started, $this->get_id(), $this, $this->get_code() ); |
|
| 1234 | - } |
|
| 1235 | - |
|
| 1236 | - /** |
|
| 1237 | - * Checks the discount has allowed items or not. |
|
| 1238 | - * |
|
| 1239 | - * @since 1.0.15 |
|
| 1240 | - * @return bool |
|
| 1241 | - */ |
|
| 1242 | - public function has_allowed_items() { |
|
| 1243 | - $allowed_items = $this->get_allowed_items(); |
|
| 1244 | - return ! empty( $allowed_items ); |
|
| 1245 | - } |
|
| 1246 | - |
|
| 1247 | - /** |
|
| 1248 | - * Checks the discount has excluded items or not. |
|
| 1249 | - * |
|
| 1250 | - * @since 1.0.15 |
|
| 1251 | - * @return bool |
|
| 1252 | - */ |
|
| 1253 | - public function has_excluded_items() { |
|
| 1254 | - $excluded_items = $this->get_excluded_items(); |
|
| 1255 | - return ! empty( $excluded_items ); |
|
| 1256 | - } |
|
| 1257 | - |
|
| 1258 | - /** |
|
| 1259 | - * Check if a discount is valid for a given item id. |
|
| 1260 | - * |
|
| 1261 | - * @param int|int[] $item_ids |
|
| 1262 | - * @since 1.0.15 |
|
| 1263 | - * @return boolean |
|
| 1264 | - */ |
|
| 1265 | - public function is_valid_for_items( $item_ids ) { |
|
| 1266 | - |
|
| 1267 | - $item_ids = wp_parse_id_list( $item_ids ); |
|
| 1268 | - $included = array_intersect( $item_ids, $this->get_allowed_items() ); |
|
| 1269 | - $excluded = array_intersect( $item_ids, $this->get_excluded_items() ); |
|
| 1270 | - |
|
| 1271 | - if ( $this->has_excluded_items() && ! empty( $excluded ) ) { |
|
| 1272 | - return false; |
|
| 1273 | - } |
|
| 1274 | - |
|
| 1275 | - if ( $this->has_allowed_items() && empty( $included ) ) { |
|
| 1276 | - return false; |
|
| 1277 | - } |
|
| 1278 | - |
|
| 1279 | - return true; |
|
| 1280 | - } |
|
| 1281 | - |
|
| 1282 | - /** |
|
| 1283 | - * Check if a discount is valid for the given amount |
|
| 1284 | - * |
|
| 1285 | - * @param float $amount The amount to check against |
|
| 1286 | - * @since 1.0.15 |
|
| 1287 | - * @return boolean |
|
| 1288 | - */ |
|
| 1289 | - public function is_valid_for_amount( $amount ) { |
|
| 1290 | - return $this->is_minimum_amount_met( $amount ) && $this->is_maximum_amount_met( $amount ); |
|
| 1291 | - } |
|
| 1292 | - |
|
| 1293 | - /** |
|
| 1294 | - * Checks if the minimum amount is set |
|
| 1295 | - * |
|
| 1296 | - * @since 1.0.15 |
|
| 1297 | - * @return boolean |
|
| 1298 | - */ |
|
| 1299 | - public function has_minimum_amount() { |
|
| 1300 | - $minimum = $this->get_minimum_total(); |
|
| 1301 | - return ! empty( $minimum ); |
|
| 1302 | - } |
|
| 1303 | - |
|
| 1304 | - /** |
|
| 1305 | - * Checks if the minimum amount is met |
|
| 1306 | - * |
|
| 1307 | - * @param float $amount The amount to check against |
|
| 1308 | - * @since 1.0.15 |
|
| 1309 | - * @return boolean |
|
| 1310 | - */ |
|
| 1311 | - public function is_minimum_amount_met( $amount ) { |
|
| 1312 | - $amount = floatval( wpinv_sanitize_amount( $amount ) ); |
|
| 1313 | - $min_met= ! ( $this->has_minimum_amount() && $amount < floatval( wpinv_sanitize_amount( $this->get_minimum_total() ) ) ); |
|
| 1314 | - return apply_filters( 'wpinv_is_discount_min_met', $min_met, $this->get_id(), $this, $this->get_code(), $amount ); |
|
| 1315 | - } |
|
| 1316 | - |
|
| 1317 | - /** |
|
| 1318 | - * Checks if the maximum amount is set |
|
| 1319 | - * |
|
| 1320 | - * @since 1.0.15 |
|
| 1321 | - * @return boolean |
|
| 1322 | - */ |
|
| 1323 | - public function has_maximum_amount() { |
|
| 1324 | - $maximum = $this->get_maximum_total(); |
|
| 1325 | - return ! empty( $maximum ); |
|
| 1326 | - } |
|
| 1327 | - |
|
| 1328 | - /** |
|
| 1329 | - * Checks if the maximum amount is met |
|
| 1330 | - * |
|
| 1331 | - * @param float $amount The amount to check against |
|
| 1332 | - * @since 1.0.15 |
|
| 1333 | - * @return boolean |
|
| 1334 | - */ |
|
| 1335 | - public function is_maximum_amount_met( $amount ) { |
|
| 1336 | - $amount = floatval( wpinv_sanitize_amount( $amount ) ); |
|
| 1337 | - $max_met= ! ( $this->has_maximum_amount() && $amount > floatval( wpinv_sanitize_amount( $this->get_maximum_total() ) ) ); |
|
| 1338 | - return apply_filters( 'wpinv_is_discount_max_met', $max_met, $this->get_id(), $this, $this->get_code(), $amount ); |
|
| 1339 | - } |
|
| 1340 | - |
|
| 1341 | - /** |
|
| 1342 | - * Checks if the discount is recurring. |
|
| 1343 | - * |
|
| 1344 | - * @since 1.0.15 |
|
| 1345 | - * @return boolean |
|
| 1346 | - */ |
|
| 1347 | - public function is_recurring() { |
|
| 1348 | - $recurring = $this->get_is_recurring(); |
|
| 1349 | - return ! empty( $recurring ); |
|
| 1350 | - } |
|
| 1351 | - |
|
| 1352 | - /** |
|
| 1353 | - * Checks if the discount is single use. |
|
| 1354 | - * |
|
| 1355 | - * @since 1.0.15 |
|
| 1356 | - * @return boolean |
|
| 1357 | - */ |
|
| 1358 | - public function is_single_use() { |
|
| 1359 | - $usage = $this->get_is_single_use(); |
|
| 1360 | - return ! empty( $usage ); |
|
| 1361 | - } |
|
| 1362 | - |
|
| 1363 | - /** |
|
| 1364 | - * Check if a discount is valid for the given user |
|
| 1365 | - * |
|
| 1366 | - * @param int|string $user |
|
| 1367 | - * @since 1.0.15 |
|
| 1368 | - * @return boolean |
|
| 1369 | - */ |
|
| 1370 | - public function is_valid_for_user( $user ) { |
|
| 1371 | - |
|
| 1372 | - // Ensure that the discount is single use. |
|
| 1373 | - if ( empty( $user ) || ! $this->is_single_use() ) { |
|
| 1374 | - return true; |
|
| 1375 | - } |
|
| 1376 | - |
|
| 1377 | - // Prepare the user id. |
|
| 1378 | - $user_id = 0; |
|
| 1122 | + /** |
|
| 1123 | + * Checks whether a discount exists in the database or not |
|
| 1124 | + * |
|
| 1125 | + * @since 1.0.15 |
|
| 1126 | + */ |
|
| 1127 | + public function exists(){ |
|
| 1128 | + $id = $this->get_id(); |
|
| 1129 | + return ! empty( $id ); |
|
| 1130 | + } |
|
| 1131 | + |
|
| 1132 | + /** |
|
| 1133 | + * Checks the discount type. |
|
| 1134 | + * |
|
| 1135 | + * |
|
| 1136 | + * @param string $type the discount type to check against |
|
| 1137 | + * @since 1.0.15 |
|
| 1138 | + * @return bool |
|
| 1139 | + */ |
|
| 1140 | + public function is_type( $type ) { |
|
| 1141 | + return $this->get_type() == $type; |
|
| 1142 | + } |
|
| 1143 | + |
|
| 1144 | + /** |
|
| 1145 | + * Checks whether the discount is published or not |
|
| 1146 | + * |
|
| 1147 | + * @since 1.0.15 |
|
| 1148 | + * @return bool |
|
| 1149 | + */ |
|
| 1150 | + public function is_active() { |
|
| 1151 | + return $this->get_status() == 'publish'; |
|
| 1152 | + } |
|
| 1153 | + |
|
| 1154 | + /** |
|
| 1155 | + * Checks whether the discount has max uses |
|
| 1156 | + * |
|
| 1157 | + * @since 1.0.15 |
|
| 1158 | + * @return bool |
|
| 1159 | + */ |
|
| 1160 | + public function has_limit() { |
|
| 1161 | + $limit = $this->get_max_uses(); |
|
| 1162 | + return ! empty( $limit ); |
|
| 1163 | + } |
|
| 1164 | + |
|
| 1165 | + /** |
|
| 1166 | + * Checks whether the discount has ever been used. |
|
| 1167 | + * |
|
| 1168 | + * @since 1.0.15 |
|
| 1169 | + * @return bool |
|
| 1170 | + */ |
|
| 1171 | + public function has_uses() { |
|
| 1172 | + return $this->get_uses() > 0; |
|
| 1173 | + } |
|
| 1174 | + |
|
| 1175 | + /** |
|
| 1176 | + * Checks whether the discount is has exided the usage limit or not |
|
| 1177 | + * |
|
| 1178 | + * @since 1.0.15 |
|
| 1179 | + * @return bool |
|
| 1180 | + */ |
|
| 1181 | + public function has_exceeded_limit() { |
|
| 1182 | + |
|
| 1183 | + if ( ! $this->has_limit() || ! $this->has_uses() ) { |
|
| 1184 | + $exceeded = false ; |
|
| 1185 | + } else { |
|
| 1186 | + $exceeded = ! ( (int) $this->get_max_uses() < $this->get_uses() ); |
|
| 1187 | + } |
|
| 1188 | + |
|
| 1189 | + return apply_filters( 'wpinv_is_discount_maxed_out', $exceeded, $this->get_id(), $this, $this->get_code() ); |
|
| 1190 | + } |
|
| 1191 | + |
|
| 1192 | + /** |
|
| 1193 | + * Checks whether the discount has an expiration date. |
|
| 1194 | + * |
|
| 1195 | + * @since 1.0.15 |
|
| 1196 | + * @return bool |
|
| 1197 | + */ |
|
| 1198 | + public function has_expiration_date() { |
|
| 1199 | + $date = $this->get_expiration_date(); |
|
| 1200 | + return ! empty( $date ); |
|
| 1201 | + } |
|
| 1202 | + |
|
| 1203 | + /** |
|
| 1204 | + * Checks if the discount is expired |
|
| 1205 | + * |
|
| 1206 | + * @since 1.0.15 |
|
| 1207 | + * @return bool |
|
| 1208 | + */ |
|
| 1209 | + public function is_expired() { |
|
| 1210 | + $expired = $this->has_expiration_date() ? current_time( 'timestamp' ) > strtotime( $this->get_expiration_date() ) : false; |
|
| 1211 | + return apply_filters( 'wpinv_is_discount_expired', $expired, $this->get_id(), $this, $this->get_code() ); |
|
| 1212 | + } |
|
| 1213 | + |
|
| 1214 | + /** |
|
| 1215 | + * Checks whether the discount has a start date. |
|
| 1216 | + * |
|
| 1217 | + * @since 1.0.15 |
|
| 1218 | + * @return bool |
|
| 1219 | + */ |
|
| 1220 | + public function has_start_date() { |
|
| 1221 | + $date = $this->get_start_date(); |
|
| 1222 | + return ! empty( $date ); |
|
| 1223 | + } |
|
| 1224 | + |
|
| 1225 | + /** |
|
| 1226 | + * Checks the discount start date. |
|
| 1227 | + * |
|
| 1228 | + * @since 1.0.15 |
|
| 1229 | + * @return bool |
|
| 1230 | + */ |
|
| 1231 | + public function has_started() { |
|
| 1232 | + $started = $this->has_start_date() ? true : current_time( 'timestamp' ) > strtotime( $this->get_start_date() ); |
|
| 1233 | + return apply_filters( 'wpinv_is_discount_started', $started, $this->get_id(), $this, $this->get_code() ); |
|
| 1234 | + } |
|
| 1235 | + |
|
| 1236 | + /** |
|
| 1237 | + * Checks the discount has allowed items or not. |
|
| 1238 | + * |
|
| 1239 | + * @since 1.0.15 |
|
| 1240 | + * @return bool |
|
| 1241 | + */ |
|
| 1242 | + public function has_allowed_items() { |
|
| 1243 | + $allowed_items = $this->get_allowed_items(); |
|
| 1244 | + return ! empty( $allowed_items ); |
|
| 1245 | + } |
|
| 1246 | + |
|
| 1247 | + /** |
|
| 1248 | + * Checks the discount has excluded items or not. |
|
| 1249 | + * |
|
| 1250 | + * @since 1.0.15 |
|
| 1251 | + * @return bool |
|
| 1252 | + */ |
|
| 1253 | + public function has_excluded_items() { |
|
| 1254 | + $excluded_items = $this->get_excluded_items(); |
|
| 1255 | + return ! empty( $excluded_items ); |
|
| 1256 | + } |
|
| 1257 | + |
|
| 1258 | + /** |
|
| 1259 | + * Check if a discount is valid for a given item id. |
|
| 1260 | + * |
|
| 1261 | + * @param int|int[] $item_ids |
|
| 1262 | + * @since 1.0.15 |
|
| 1263 | + * @return boolean |
|
| 1264 | + */ |
|
| 1265 | + public function is_valid_for_items( $item_ids ) { |
|
| 1266 | + |
|
| 1267 | + $item_ids = wp_parse_id_list( $item_ids ); |
|
| 1268 | + $included = array_intersect( $item_ids, $this->get_allowed_items() ); |
|
| 1269 | + $excluded = array_intersect( $item_ids, $this->get_excluded_items() ); |
|
| 1270 | + |
|
| 1271 | + if ( $this->has_excluded_items() && ! empty( $excluded ) ) { |
|
| 1272 | + return false; |
|
| 1273 | + } |
|
| 1274 | + |
|
| 1275 | + if ( $this->has_allowed_items() && empty( $included ) ) { |
|
| 1276 | + return false; |
|
| 1277 | + } |
|
| 1278 | + |
|
| 1279 | + return true; |
|
| 1280 | + } |
|
| 1281 | + |
|
| 1282 | + /** |
|
| 1283 | + * Check if a discount is valid for the given amount |
|
| 1284 | + * |
|
| 1285 | + * @param float $amount The amount to check against |
|
| 1286 | + * @since 1.0.15 |
|
| 1287 | + * @return boolean |
|
| 1288 | + */ |
|
| 1289 | + public function is_valid_for_amount( $amount ) { |
|
| 1290 | + return $this->is_minimum_amount_met( $amount ) && $this->is_maximum_amount_met( $amount ); |
|
| 1291 | + } |
|
| 1292 | + |
|
| 1293 | + /** |
|
| 1294 | + * Checks if the minimum amount is set |
|
| 1295 | + * |
|
| 1296 | + * @since 1.0.15 |
|
| 1297 | + * @return boolean |
|
| 1298 | + */ |
|
| 1299 | + public function has_minimum_amount() { |
|
| 1300 | + $minimum = $this->get_minimum_total(); |
|
| 1301 | + return ! empty( $minimum ); |
|
| 1302 | + } |
|
| 1303 | + |
|
| 1304 | + /** |
|
| 1305 | + * Checks if the minimum amount is met |
|
| 1306 | + * |
|
| 1307 | + * @param float $amount The amount to check against |
|
| 1308 | + * @since 1.0.15 |
|
| 1309 | + * @return boolean |
|
| 1310 | + */ |
|
| 1311 | + public function is_minimum_amount_met( $amount ) { |
|
| 1312 | + $amount = floatval( wpinv_sanitize_amount( $amount ) ); |
|
| 1313 | + $min_met= ! ( $this->has_minimum_amount() && $amount < floatval( wpinv_sanitize_amount( $this->get_minimum_total() ) ) ); |
|
| 1314 | + return apply_filters( 'wpinv_is_discount_min_met', $min_met, $this->get_id(), $this, $this->get_code(), $amount ); |
|
| 1315 | + } |
|
| 1316 | + |
|
| 1317 | + /** |
|
| 1318 | + * Checks if the maximum amount is set |
|
| 1319 | + * |
|
| 1320 | + * @since 1.0.15 |
|
| 1321 | + * @return boolean |
|
| 1322 | + */ |
|
| 1323 | + public function has_maximum_amount() { |
|
| 1324 | + $maximum = $this->get_maximum_total(); |
|
| 1325 | + return ! empty( $maximum ); |
|
| 1326 | + } |
|
| 1327 | + |
|
| 1328 | + /** |
|
| 1329 | + * Checks if the maximum amount is met |
|
| 1330 | + * |
|
| 1331 | + * @param float $amount The amount to check against |
|
| 1332 | + * @since 1.0.15 |
|
| 1333 | + * @return boolean |
|
| 1334 | + */ |
|
| 1335 | + public function is_maximum_amount_met( $amount ) { |
|
| 1336 | + $amount = floatval( wpinv_sanitize_amount( $amount ) ); |
|
| 1337 | + $max_met= ! ( $this->has_maximum_amount() && $amount > floatval( wpinv_sanitize_amount( $this->get_maximum_total() ) ) ); |
|
| 1338 | + return apply_filters( 'wpinv_is_discount_max_met', $max_met, $this->get_id(), $this, $this->get_code(), $amount ); |
|
| 1339 | + } |
|
| 1340 | + |
|
| 1341 | + /** |
|
| 1342 | + * Checks if the discount is recurring. |
|
| 1343 | + * |
|
| 1344 | + * @since 1.0.15 |
|
| 1345 | + * @return boolean |
|
| 1346 | + */ |
|
| 1347 | + public function is_recurring() { |
|
| 1348 | + $recurring = $this->get_is_recurring(); |
|
| 1349 | + return ! empty( $recurring ); |
|
| 1350 | + } |
|
| 1351 | + |
|
| 1352 | + /** |
|
| 1353 | + * Checks if the discount is single use. |
|
| 1354 | + * |
|
| 1355 | + * @since 1.0.15 |
|
| 1356 | + * @return boolean |
|
| 1357 | + */ |
|
| 1358 | + public function is_single_use() { |
|
| 1359 | + $usage = $this->get_is_single_use(); |
|
| 1360 | + return ! empty( $usage ); |
|
| 1361 | + } |
|
| 1362 | + |
|
| 1363 | + /** |
|
| 1364 | + * Check if a discount is valid for the given user |
|
| 1365 | + * |
|
| 1366 | + * @param int|string $user |
|
| 1367 | + * @since 1.0.15 |
|
| 1368 | + * @return boolean |
|
| 1369 | + */ |
|
| 1370 | + public function is_valid_for_user( $user ) { |
|
| 1371 | + |
|
| 1372 | + // Ensure that the discount is single use. |
|
| 1373 | + if ( empty( $user ) || ! $this->is_single_use() ) { |
|
| 1374 | + return true; |
|
| 1375 | + } |
|
| 1376 | + |
|
| 1377 | + // Prepare the user id. |
|
| 1378 | + $user_id = 0; |
|
| 1379 | 1379 | if ( is_numeric( $user ) ) { |
| 1380 | 1380 | $user_id = absint( $user ); |
| 1381 | 1381 | } else if ( is_email( $user ) && $user_data = get_user_by( 'email', $user ) ) { |
@@ -1384,117 +1384,117 @@ discard block |
||
| 1384 | 1384 | $user_id = $user_data->ID; |
| 1385 | 1385 | } |
| 1386 | 1386 | |
| 1387 | - // Ensure that we have a user. |
|
| 1388 | - if ( empty( $user_id ) ) { |
|
| 1389 | - return true; |
|
| 1390 | - } |
|
| 1387 | + // Ensure that we have a user. |
|
| 1388 | + if ( empty( $user_id ) ) { |
|
| 1389 | + return true; |
|
| 1390 | + } |
|
| 1391 | 1391 | |
| 1392 | - // Get all payments with matching user id. |
|
| 1392 | + // Get all payments with matching user id. |
|
| 1393 | 1393 | $payments = wpinv_get_invoices( array( 'user' => $user_id, 'limit' => false, 'paginate' => false ) ); |
| 1394 | - $code = strtolower( $this->get_code() ); |
|
| 1395 | - |
|
| 1396 | - // For each payment... |
|
| 1397 | - foreach ( $payments as $payment ) { |
|
| 1398 | - |
|
| 1399 | - // Only check for paid invoices. |
|
| 1400 | - if ( $payment->is_paid() && strtolower( $payment->get_discount_code() ) == $code ) { |
|
| 1401 | - return false; |
|
| 1402 | - } |
|
| 1403 | - |
|
| 1404 | - } |
|
| 1405 | - |
|
| 1406 | - return true; |
|
| 1407 | - } |
|
| 1408 | - |
|
| 1409 | - /** |
|
| 1410 | - * Deletes the discount from the database |
|
| 1411 | - * |
|
| 1412 | - * @since 1.0.15 |
|
| 1413 | - * @return boolean |
|
| 1414 | - */ |
|
| 1415 | - public function remove() { |
|
| 1416 | - return $this->delete(); |
|
| 1417 | - } |
|
| 1418 | - |
|
| 1419 | - /** |
|
| 1420 | - * Increases a discount's usage. |
|
| 1421 | - * |
|
| 1422 | - * @since 1.0.15 |
|
| 1423 | - * @param int $by The number of usages to increas by. |
|
| 1424 | - * @return int |
|
| 1425 | - */ |
|
| 1426 | - public function increase_usage( $by = 1 ) { |
|
| 1427 | - |
|
| 1428 | - // Abort if zero. |
|
| 1429 | - if ( empty( $by ) ) { |
|
| 1430 | - return; |
|
| 1431 | - } |
|
| 1432 | - |
|
| 1433 | - // Increase the usage. |
|
| 1434 | - $this->set_uses( $this->get_uses() + (int) $by ); |
|
| 1435 | - |
|
| 1436 | - // Save the discount. |
|
| 1437 | - $this->save(); |
|
| 1438 | - |
|
| 1439 | - // Fire relevant hooks. |
|
| 1440 | - if( (int) $by > 0 ) { |
|
| 1441 | - do_action( 'wpinv_discount_increase_use_count', $this->get_uses(), $this->get_id(), $this->get_code(), absint( $by ) ); |
|
| 1442 | - } else { |
|
| 1443 | - do_action( 'wpinv_discount_decrease_use_count', $this->get_uses(), $this->get_id(), $this->get_code(), absint( $by ) ); |
|
| 1444 | - } |
|
| 1445 | - |
|
| 1446 | - // Return the number of times the discount has been used. |
|
| 1447 | - return $this->get_uses(); |
|
| 1448 | - } |
|
| 1449 | - |
|
| 1450 | - /** |
|
| 1451 | - * Alias of self::__toString() |
|
| 1452 | - * |
|
| 1453 | - * @since 1.0.15 |
|
| 1454 | - * @return string|false |
|
| 1455 | - */ |
|
| 1456 | - public function get_data_as_json() { |
|
| 1457 | - return $this->__toString(); |
|
| 1458 | - } |
|
| 1459 | - |
|
| 1460 | - /** |
|
| 1461 | - * Returns a discount's discounted amount. |
|
| 1462 | - * |
|
| 1463 | - * @since 1.0.15 |
|
| 1464 | - * @param float $amount |
|
| 1465 | - * @return float |
|
| 1466 | - */ |
|
| 1467 | - public function get_discounted_amount( $amount ) { |
|
| 1468 | - |
|
| 1469 | - // Convert amount to float. |
|
| 1470 | - $amount = (float) $amount; |
|
| 1471 | - |
|
| 1472 | - // Get discount amount. |
|
| 1473 | - $discount_amount = $this->get_amount(); |
|
| 1474 | - |
|
| 1475 | - if ( empty( $discount_amount ) ) { |
|
| 1476 | - return 0; |
|
| 1477 | - } |
|
| 1478 | - |
|
| 1479 | - // Format the amount. |
|
| 1480 | - $discount_amount = floatval( wpinv_sanitize_amount( $discount_amount ) ); |
|
| 1394 | + $code = strtolower( $this->get_code() ); |
|
| 1395 | + |
|
| 1396 | + // For each payment... |
|
| 1397 | + foreach ( $payments as $payment ) { |
|
| 1398 | + |
|
| 1399 | + // Only check for paid invoices. |
|
| 1400 | + if ( $payment->is_paid() && strtolower( $payment->get_discount_code() ) == $code ) { |
|
| 1401 | + return false; |
|
| 1402 | + } |
|
| 1403 | + |
|
| 1404 | + } |
|
| 1405 | + |
|
| 1406 | + return true; |
|
| 1407 | + } |
|
| 1408 | + |
|
| 1409 | + /** |
|
| 1410 | + * Deletes the discount from the database |
|
| 1411 | + * |
|
| 1412 | + * @since 1.0.15 |
|
| 1413 | + * @return boolean |
|
| 1414 | + */ |
|
| 1415 | + public function remove() { |
|
| 1416 | + return $this->delete(); |
|
| 1417 | + } |
|
| 1418 | + |
|
| 1419 | + /** |
|
| 1420 | + * Increases a discount's usage. |
|
| 1421 | + * |
|
| 1422 | + * @since 1.0.15 |
|
| 1423 | + * @param int $by The number of usages to increas by. |
|
| 1424 | + * @return int |
|
| 1425 | + */ |
|
| 1426 | + public function increase_usage( $by = 1 ) { |
|
| 1427 | + |
|
| 1428 | + // Abort if zero. |
|
| 1429 | + if ( empty( $by ) ) { |
|
| 1430 | + return; |
|
| 1431 | + } |
|
| 1432 | + |
|
| 1433 | + // Increase the usage. |
|
| 1434 | + $this->set_uses( $this->get_uses() + (int) $by ); |
|
| 1435 | + |
|
| 1436 | + // Save the discount. |
|
| 1437 | + $this->save(); |
|
| 1438 | + |
|
| 1439 | + // Fire relevant hooks. |
|
| 1440 | + if( (int) $by > 0 ) { |
|
| 1441 | + do_action( 'wpinv_discount_increase_use_count', $this->get_uses(), $this->get_id(), $this->get_code(), absint( $by ) ); |
|
| 1442 | + } else { |
|
| 1443 | + do_action( 'wpinv_discount_decrease_use_count', $this->get_uses(), $this->get_id(), $this->get_code(), absint( $by ) ); |
|
| 1444 | + } |
|
| 1445 | + |
|
| 1446 | + // Return the number of times the discount has been used. |
|
| 1447 | + return $this->get_uses(); |
|
| 1448 | + } |
|
| 1449 | + |
|
| 1450 | + /** |
|
| 1451 | + * Alias of self::__toString() |
|
| 1452 | + * |
|
| 1453 | + * @since 1.0.15 |
|
| 1454 | + * @return string|false |
|
| 1455 | + */ |
|
| 1456 | + public function get_data_as_json() { |
|
| 1457 | + return $this->__toString(); |
|
| 1458 | + } |
|
| 1459 | + |
|
| 1460 | + /** |
|
| 1461 | + * Returns a discount's discounted amount. |
|
| 1462 | + * |
|
| 1463 | + * @since 1.0.15 |
|
| 1464 | + * @param float $amount |
|
| 1465 | + * @return float |
|
| 1466 | + */ |
|
| 1467 | + public function get_discounted_amount( $amount ) { |
|
| 1468 | + |
|
| 1469 | + // Convert amount to float. |
|
| 1470 | + $amount = (float) $amount; |
|
| 1471 | + |
|
| 1472 | + // Get discount amount. |
|
| 1473 | + $discount_amount = $this->get_amount(); |
|
| 1474 | + |
|
| 1475 | + if ( empty( $discount_amount ) ) { |
|
| 1476 | + return 0; |
|
| 1477 | + } |
|
| 1478 | + |
|
| 1479 | + // Format the amount. |
|
| 1480 | + $discount_amount = floatval( wpinv_sanitize_amount( $discount_amount ) ); |
|
| 1481 | 1481 | |
| 1482 | - // If this is a percentage discount. |
|
| 1483 | - if ( $this->is_type( 'percent' ) ) { |
|
| 1482 | + // If this is a percentage discount. |
|
| 1483 | + if ( $this->is_type( 'percent' ) ) { |
|
| 1484 | 1484 | $discount_amount = $amount * ( $discount_amount / 100 ); |
| 1485 | - } |
|
| 1485 | + } |
|
| 1486 | 1486 | |
| 1487 | - // Discount can not be less than zero... |
|
| 1488 | - if ( $discount_amount < 0 ) { |
|
| 1489 | - $discount_amount = 0; |
|
| 1490 | - } |
|
| 1487 | + // Discount can not be less than zero... |
|
| 1488 | + if ( $discount_amount < 0 ) { |
|
| 1489 | + $discount_amount = 0; |
|
| 1490 | + } |
|
| 1491 | 1491 | |
| 1492 | - // ... or more than the amount. |
|
| 1493 | - if ( $discount_amount > $amount ) { |
|
| 1494 | - $discount_amount = $amount; |
|
| 1495 | - } |
|
| 1492 | + // ... or more than the amount. |
|
| 1493 | + if ( $discount_amount > $amount ) { |
|
| 1494 | + $discount_amount = $amount; |
|
| 1495 | + } |
|
| 1496 | 1496 | |
| 1497 | - return apply_filters( 'wpinv_discount_total_discount_amount', $discount_amount, $amount, $this ); |
|
| 1498 | - } |
|
| 1497 | + return apply_filters( 'wpinv_discount_total_discount_amount', $discount_amount, $amount, $this ); |
|
| 1498 | + } |
|
| 1499 | 1499 | |
| 1500 | 1500 | } |
@@ -56,7 +56,7 @@ |
||
| 56 | 56 | } |
| 57 | 57 | |
| 58 | 58 | function wpinv_admin_messages() { |
| 59 | - settings_errors( 'wpinv-notices' ); |
|
| 59 | + settings_errors( 'wpinv-notices' ); |
|
| 60 | 60 | } |
| 61 | 61 | add_action( 'admin_notices', 'wpinv_admin_messages' ); |
| 62 | 62 | |