| @@ -113,10 +113,34 @@ | ||
| 113 | 113 | public function get_limit() { |
| 114 | 114 | return $this->product->get_meta( '_subscrpt_limit' ); |
| 115 | 115 | } |
| 116 | 116 | |
| 117 | + public function get_renewal_limit() { | |
| 118 | + return $this->product->get_meta( '_subscrpt_max_no_payment' ); | |
| 119 | + } | |
| 120 | + | |
| 121 | + public function get_max_no_payment() { | |
| 122 | + return $this->product->get_meta( '_subscrpt_max_no_payment' ); | |
| 123 | + } | |
| 124 | + | |
| 117 | 125 | public function is_enabled(): bool { |
| 118 | - return $this->product->get_meta( '_subscrpt_enabled' ); | |
| 126 | + if ( empty( $this->product->get_meta( '_subscrpt_enabled' ) ) ) { | |
| 127 | + return false; | |
| 128 | + } | |
| 129 | + | |
| 130 | + // Once plan-connected, a product is a subscription only while it still has | |
| 131 | + // a plan — it never falls back to the legacy terms after a detach. | |
| 132 | + if ( 'yes' === $this->product->get_meta( '_subscrpt_plan_connected_before' ) && function_exists( 'subscrpt_product_has_plan' ) ) { | |
| 133 | + $parent = $this->product->get_parent_id(); | |
| 134 | + $has_plan = $parent | |
| 135 | + ? subscrpt_product_has_plan( $parent, $this->product->get_id() ) | |
| 136 | + : subscrpt_product_has_plan( $this->product->get_id() ); | |
| 137 | + if ( ! $has_plan ) { | |
| 138 | + return false; | |
| 139 | + } | |
| 140 | + } | |
| 141 | + | |
| 142 | + return true; | |
| 119 | 143 | } |
| 120 | 144 | |
| 121 | 145 | public function get_trial_timing_per(): int { |
| 122 | 146 | return (int) ( $this->product->get_meta( '_subscrpt_trial_timing_per' ) ?? 1 ); |
| @@ -125,8 +149,62 @@ | ||
| 125 | 149 | public function get_trial_timing_option() { |
| 126 | 150 | return $this->product->get_meta( '_subscrpt_trial_timing_option' ); |
| 127 | 151 | } |
| 128 | 152 | |
| 129 | - public function get_signup_fee(): int { | |
| 153 | + public function get_signup_fee(): float { | |
| 130 | 154 | return 0; |
| 155 | + } | |
| 156 | + | |
| 157 | + /** | |
| 158 | + * Get the payment type (recurring or split_payment). | |
| 159 | + * | |
| 160 | + * @return string Payment type. | |
| 161 | + */ | |
| 162 | + public function get_payment_type(): string { | |
| 163 | + return $this->product->get_meta( '_subscrpt_payment_type' ) ?: 'recurring'; | |
| 164 | + } | |
| 165 | + | |
| 166 | + /** | |
| 167 | + * Check if product uses split payment type. | |
| 168 | + * | |
| 169 | + * @return bool True if split payment, false otherwise. | |
| 170 | + */ | |
| 171 | + public function is_split_payment(): bool { | |
| 172 | + return 'split_payment' === $this->get_payment_type(); | |
| 173 | + } | |
| 174 | + | |
| 175 | + /** | |
| 176 | + * Get access ends timing for split payments. | |
| 177 | + * | |
| 178 | + * @return string Access ends timing option. | |
| 179 | + */ | |
| 180 | + public function get_access_ends_timing(): string { | |
| 181 | + return $this->product->get_meta( '_subscrpt_access_ends_timing' ) ?: 'after_full_duration'; | |
| 182 | + } | |
| 183 | + | |
| 184 | + /** | |
| 185 | + * Get custom access duration time. | |
| 186 | + * | |
| 187 | + * @return int Custom access duration time. | |
| 188 | + */ | |
| 189 | + public function get_custom_access_duration_time(): int { | |
| 190 | + return (int) ( $this->product->get_meta( '_subscrpt_custom_access_duration_time' ) ?: 1 ); | |
| 191 | + } | |
| 192 | + | |
| 193 | + /** | |
| 194 | + * Get custom access duration type. | |
| 195 | + * | |
| 196 | + * @return string Custom access duration type (days, weeks, months, years). | |
| 197 | + */ | |
| 198 | + public function get_custom_access_duration_type(): string { | |
| 199 | + return $this->product->get_meta( '_subscrpt_custom_access_duration_type' ) ?: 'months'; | |
| 200 | + } | |
| 201 | + | |
| 202 | + /** | |
| 203 | + * Check if product has custom access duration. | |
| 204 | + * | |
| 205 | + * @return bool True if custom duration, false otherwise. | |
| 206 | + */ | |
| 207 | + public function has_custom_access_duration(): bool { | |
| 208 | + return 'custom_duration' === $this->get_access_ends_timing(); | |
| 131 | 209 | } |
| 132 | 210 | } |