|
@@ 457-498 (lines=42) @@
|
| 454 |
|
* @param array $atts |
| 455 |
|
* @return string |
| 456 |
|
*/ |
| 457 |
|
public static function get_subscription_period_interval( $atts ) { |
| 458 |
|
global $wpdb, $post; |
| 459 |
|
|
| 460 |
|
$defaults = shortcode_atts( array( |
| 461 |
|
'id' => '', |
| 462 |
|
'sku' => '', |
| 463 |
|
), $atts ); |
| 464 |
|
|
| 465 |
|
$atts = wp_parse_args( $atts, $defaults ); |
| 466 |
|
|
| 467 |
|
if ( ! empty( $atts['id'] ) && $atts['id'] > 0 ) { |
| 468 |
|
$product_data = wc_get_product( $atts['id'] ); |
| 469 |
|
} elseif ( ! empty( $atts['sku'] ) ) { |
| 470 |
|
$product_id = wc_get_product_id_by_sku( $atts['sku'] ); |
| 471 |
|
$product_data = get_post( $product_id ); |
| 472 |
|
} else { |
| 473 |
|
$product_data = wc_get_product( $post->ID ); |
| 474 |
|
} |
| 475 |
|
|
| 476 |
|
// Check that the product type is supported. Return blank if not supported. |
| 477 |
|
if ( ! is_object( $product_data ) || ! in_array( $product_data->product_type, self::get_supported_product_types() ) ) { |
| 478 |
|
return ''; |
| 479 |
|
} |
| 480 |
|
|
| 481 |
|
ob_start(); |
| 482 |
|
|
| 483 |
|
// Get Subscription Period Interval |
| 484 |
|
$period_interval = WC_Subscriptions_Product::get_interval( $product_data ); |
| 485 |
|
|
| 486 |
|
// If the period is empty, look for alternative. |
| 487 |
|
if ( empty( $period_interval ) ) { |
| 488 |
|
$scheme = self::get_satt_lowest_scheme_data( $product_data ); |
| 489 |
|
|
| 490 |
|
if ( !empty( $scheme ) && is_array( $scheme ) ) { |
| 491 |
|
$period_interval = $scheme['scheme']['subscription_period_interval']; |
| 492 |
|
} |
| 493 |
|
} |
| 494 |
|
|
| 495 |
|
echo $period_interval; |
| 496 |
|
|
| 497 |
|
return ob_get_clean(); |
| 498 |
|
} // END get_subscription_period_interval() |
| 499 |
|
|
| 500 |
|
/** |
| 501 |
|
* Displays the subscription length of the subscription product. |
|
@@ 702-743 (lines=42) @@
|
| 699 |
|
* @param array $atts |
| 700 |
|
* @return string |
| 701 |
|
*/ |
| 702 |
|
public static function get_subscription_trial_length( $atts ) { |
| 703 |
|
global $wpdb, $post; |
| 704 |
|
|
| 705 |
|
$defaults = shortcode_atts( array( |
| 706 |
|
'id' => '', |
| 707 |
|
'sku' => '', |
| 708 |
|
), $atts ); |
| 709 |
|
|
| 710 |
|
$atts = wp_parse_args( $atts, $defaults ); |
| 711 |
|
|
| 712 |
|
if ( ! empty( $atts['id'] ) && $atts['id'] > 0 ) { |
| 713 |
|
$product_data = wc_get_product( $atts['id'] ); |
| 714 |
|
} elseif ( ! empty( $atts['sku'] ) ) { |
| 715 |
|
$product_id = wc_get_product_id_by_sku( $atts['sku'] ); |
| 716 |
|
$product_data = get_post( $product_id ); |
| 717 |
|
} else { |
| 718 |
|
$product_data = wc_get_product( $post->ID ); |
| 719 |
|
} |
| 720 |
|
|
| 721 |
|
// Check that the product type is supported. Return blank if not supported. |
| 722 |
|
if ( ! is_object( $product_data ) || ! in_array( $product_data->product_type, self::get_supported_product_types() ) ) { |
| 723 |
|
return ''; |
| 724 |
|
} |
| 725 |
|
|
| 726 |
|
ob_start(); |
| 727 |
|
|
| 728 |
|
// Get Subscription Trial Length |
| 729 |
|
$trial_length = WC_Subscriptions_Product::get_trial_length( $product_data ); |
| 730 |
|
|
| 731 |
|
// If the trial length is empty, look for alternative. |
| 732 |
|
if ( empty( $trial_length ) ) { |
| 733 |
|
$scheme = self::get_satt_lowest_scheme_data( $product_data ); |
| 734 |
|
|
| 735 |
|
if ( !empty( $scheme ) && is_array( $scheme ) ) { |
| 736 |
|
$trial_length = $scheme['scheme']['subscription_trial_length']; |
| 737 |
|
} |
| 738 |
|
} |
| 739 |
|
|
| 740 |
|
echo $trial_length; |
| 741 |
|
|
| 742 |
|
return ob_get_clean(); |
| 743 |
|
} // END get_subscription_trial_length() |
| 744 |
|
|
| 745 |
|
/** |
| 746 |
|
* Displays the subscription trial period of the subscription product. |