1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452
<?php
defined( 'ABSPATH' ) || exit();
function bwcs_subscriptions_active() {
wc_deprecated_function( __FUNCTION__, '3.0.0', 'wcs_braintree_active' );
return wcs_braintree_active();
}
function bwcs_braintree_subscriptions_active() {
wc_deprecated_function( __FUNCTION__, '3.0.0', 'wc_braintree_subscriptions_active' );
return wc_braintree_subscriptions_active();
}
function bwcs_order_is_subscription( $order ) {
wc_deprecated_function( __FUNCTION__, '3.0.0', '$order->get_meta ( \'subscription_type\', true ) === \'braintree\'' );
return $order->get_meta( 'subscription_type', true ) === 'braintree';
}
function bwcs_can_delete_payment_method( $error, $token ) {
wc_deprecated_function( __FUNCTION__, '3.0.0', 'Warning is no longer issued.' );
global $wpdb;
$statuses = wcs_get_subscription_statuses();
unset( $statuses['wc-cancelled'] );
unset( $statuses['wc-pending-cancel'] );
$in_statuses = implode( "','", array_fill( 0, count( $statuses ), '%s' ) );
$in_statuses = vsprintf( $in_statuses, array_keys( $statuses ) );
$query = $wpdb->prepare(
"SELECT id FROM $wpdb->posts AS posts INNER JOIN $wpdb->postmeta AS postmeta
ON posts.ID = postmeta.post_id WHERE posts.post_type = 'shop_subscription'
AND posts.post_status IN ('{$in_statuses}') AND postmeta.meta_key = '_payment_method_token' AND postmeta.meta_value = %s",
$token
);
$results = $wpdb->get_results( $query );
if ( $results ) {
$message = sprintf( _n( 'There is %s subscription associated with this payment method.', 'There are %s subscriptions associated with this payment method.', count( $results ), 'woo-payment-gateway' ), count( $results ) );
$error->add( 'method-delete-error', $message );
}
return $error;
}
function bwcs_is_change_payment_method() {
wc_deprecated_function( __FUNCTION__, '3.0.0', 'WC_Subscriptions_Change_Payment_Gateway::$is_request_to_change_payment' );
return wcs_braintree_active() && WC_Subscriptions_Change_Payment_Gateway::$is_request_to_change_payment;
}
function bwcs_is_woocommerce_change_payment() {
wc_deprecated_function( __FUNCTION__, '3.0.0', 'did_action(\'woocommerce_subscriptions_pre_update_payment_method\')' );
return did_action( 'woocommerce_subscriptions_pre_update_payment_method' );
}
function bwcs_cart_item_contains_subscription( $cart_item ) {
$product = $cart_item['data'];
return bwcs_product_is_subscription( $product );
}
function bwcs_product_is_subscription( $product ) {
if ( ! is_object( $product ) ) {
$product = wc_get_product( $product );
}
if ( bwcs_subscriptions_active() ) {
return WC_Subscriptions_Product::is_subscription( $product ) && bwc_get_product_property( 'braintree_subscription', $product ) === 'yes';
}
return $product->get_meta( 'braintree_subscription', true ) === 'yes';
}
function bwcs_order_contains_subscription( $order ) {
if ( ! is_object( $order ) ) {
$order = wc_get_order( $order );
}
foreach ( $order->get_items() as $k => $item ) {
$product = $order->get_product_from_item( $item );
if ( $product ) {
if ( bwcs_product_is_subscription( $product ) ) {
return true;
}
}
}
return false;
}
function bwcs_get_plan_from_product( $product ) {
wc_deprecated_function( __FUNCTION__, '3.0.0', 'wcs_braintree_get_plan_from_product' );
return wcs_braintree_get_plan_from_product( $product );
}
function bwcs_calculate_order_total( $order, $subscription ) {
wc_deprecated_function( __FUNCTION__, '3.0.0', 'Do not use this function' );
}
function bwcs_order_has_coupon( $order ) {
wc_deprecated_function( __FUNCTION__, '3.0.0', 'no longer supported' );
return $order->get_item_count( 'coupon' ) > 0;
}
function bwcs_get_cart_item_key( $subscription ) {
wc_deprecated_function( __FUNCTION__, '3.0.0', 'no longer supported' );
foreach ( WC()->cart->cart_contents as $cart_item_key->$cart_contents ) {
if ( $subscription->has_product( $cart_contents['product_id'] ) ) {
return $cart_item_key;
}
}
return '';
}
function bwcs_get_product_from_subscription( $subscription ) {
wc_deprecated_function( __FUNCTION__, '3.0.0', 'no longer supported' );
foreach ( $subscription->get_items() as $k => $item ) {
if ( $product = $subscription->get_product_from_item( $item ) ) {
return $product;
}
}
return false;
}
function bwcs_is_braintree_subscription( $subscription ) {
wc_deprecated_function( __FUNCTION__, '3.0.0', 'no longer supported' );
if ( is_object( $subscription ) ) {
$id = $subscription->get_id();
} else {
$id = $subscription;
}
return get_post_meta( $id, '_subscription_type', true ) === 'braintree';
}
function bwcs_can_combine_subscriptions() {
wc_deprecated_function( __FUNCTION__, '3.0.0', 'no longer supported' );
return false;
}
function bwcs_start_date_in_site_timezone( $subscription, $format = 'Y-m-d H:i:s' ) {
wc_deprecated_function( __FUNCTION__, '3.0.0', 'no longer supported' );
$synchronized = get_post_meta( $subscription->get_id(), '_contains_synced_subscription', true ) === 'true';
$trial_date = bwcs_get_subscription_date( 'trial_end', $subscription );
if ( $synchronized || $trial_date ) {
$date_type = 'next_payment';
} else {
$date_type = 'start';
}
$tz = wc_timezone_string();
if ( $tz ) {
$date = new DateTime( bwcs_get_subscription_date( $date_type, $subscription ), new DateTimeZone( 'UTC' ) );
$date->setTimezone( new DateTimeZone( $tz ) );
$date = new DateTimeZone( $date->format( $format ), new DateTimeZone( 'UTC' ) );
} else {
$offset = get_option( 'gmt_offset' );
$timestamp = $subscription->get_time( $date_type );
$date_string = gmdate( $format, $timestamp + $offset * HOUR_IN_SECONDS );
$date = DateTime::createFromFormat( $format, $date_string, new DateTimeZone( 'UTC' ) );
}
return $date;
}
function bwcs_get_start_date_in_utc( $subscription ) {
wc_deprecated_function( __FUNCTION__, '3.0.0', 'no longer supported' );
$synchronized = get_post_meta( $subscription->get_id(), '_contains_synced_subscription', true ) === 'true';
$trial_date = bwcs_get_subscription_date( 'trial_end', $subscription );
if ( $synchronized || $trial_date ) {
$date_type = 'next_payment';
} else {
$date_type = 'start';
}
$start_date = bwcs_get_subscription_date( $date_type, $subscription );
return DateTime::createFromFormat( 'Y-m-d H:i:s', $start_date, new DateTimeZone( 'UTC' ) );
}
function bwcs_get_current_date_time() {
wc_deprecated_function( __FUNCTION__, '3.0.0', 'no longer supported' );
$tz = wc_timezone_string();
if ( $tz ) {
$date = new DateTime( 'now', new DateTimeZone( $tz ) );
} else {
$offset = get_option( 'gmt_offset' );
$date_string = gmdate( 'Y-m-d H:i:s', time() + $offset * HOUR_IN_SECONDS );
$date = DateTime::createFromFormat( $format, $date_string, new DateTimeZone( 'UTC' ) );
}
return $date;
}
function bwcs_subscription_has_trial( $subscription ) {
wc_deprecated_function( __FUNCTION__, '3.0.0', 'no longer supported' );
return (bool) $subscription->get_time( 'trial_end' );
}
function bwcs_subscription_is_synched( $subscription ) {
wc_deprecated_function( __FUNCTION__, '3.0.0', 'no longer supported' );
return $subscription->get_meta( 'contains_synced_subscription' ) === 'true';
}
function bwcs_is_paid_for_failed_renewal_request() {
wc_deprecated_function( __FUNCTION__, '3.0.0', 'no longer supported' );
return (bool) did_action( 'woocommerce_subscriptions_paid_for_failed_renewal_order' );
}
function bwcs_get_num_of_billing_cycles( $product ) {
wc_deprecated_function( __FUNCTION__, '3.0.0', 'no longer supported' );
return floor( WC_Subscriptions_Product::get_length( $product ) / WC_Subscriptions_Product::get_interval( $product ) );
}
function bwcs_retry_after_exception() {
wc_deprecated_function( __FUNCTION__, '3.0.0', 'no longer supported' );
return false;
}
function bwcs_get_subscription_date( $type, $subscription ) {
wc_deprecated_function( __FUNCTION__, '3.0.0', 'no longer supported' );
$type = wcs_normalise_date_type_key( $type, false );
return $subscription->get_date( $type );
}