Code Duplication    Length = 42-42 lines in 2 locations

includes/class-wcs-shortcodes.php 2 locations

@@ 475-516 (lines=42) @@
472
	 * @param  array $atts
473
	 * @return string
474
	 */
475
	public static function get_subscription_period_interval( $atts ) {
476
		global $wpdb, $post;
477
478
		$defaults = shortcode_atts( array(
479
			'id'  => '',
480
			'sku' => '',
481
		), $atts );
482
483
		$atts = wp_parse_args( $atts, $defaults );
484
485
		if ( ! empty( $atts['id'] ) && $atts['id'] > 0 ) {
486
			$product_data = wc_get_product( $atts['id'] );
487
		} elseif ( ! empty( $atts['sku'] ) ) {
488
			$product_id   = wc_get_product_id_by_sku( $atts['sku'] );
489
			$product_data = get_post( $product_id );
490
		} else {
491
			$product_data = wc_get_product( $post->ID );
492
		}
493
494
		// Check that the product type is supported. Return blank if not supported.
495
		if ( ! is_object( $product_data ) || ! in_array( $product_data->product_type, self::get_supported_product_types() ) ) {
496
			return '';
497
		}
498
499
		ob_start();
500
501
		// Get Subscription Period Interval
502
		$period_interval = WC_Subscriptions_Product::get_interval( $product_data );
503
504
		// If the period is empty, look for alternative.
505
		if ( empty( $period_interval ) ) {
506
			$scheme = self::get_satt_lowest_scheme_data( $product_data );
507
508
			if ( !empty( $scheme ) && is_array( $scheme ) ) {
509
				$period_interval = $scheme['scheme']['subscription_period_interval'];
510
			}
511
		}
512
513
		echo $period_interval;
514
515
		return ob_get_clean();
516
	} // END get_subscription_period_interval()
517
518
	/**
519
	 * Displays the subscription length of the subscription product.
@@ 712-753 (lines=42) @@
709
	 * @param  array $atts
710
	 * @return string
711
	 */
712
	public static function get_subscription_trial_length( $atts ) {
713
		global $wpdb, $post;
714
715
		$defaults = shortcode_atts( array(
716
			'id'  => '',
717
			'sku' => '',
718
		), $atts );
719
720
		$atts = wp_parse_args( $atts, $defaults );
721
722
		if ( ! empty( $atts['id'] ) && $atts['id'] > 0 ) {
723
			$product_data = wc_get_product( $atts['id'] );
724
		} elseif ( ! empty( $atts['sku'] ) ) {
725
			$product_id   = wc_get_product_id_by_sku( $atts['sku'] );
726
			$product_data = get_post( $product_id );
727
		} else {
728
			$product_data = wc_get_product( $post->ID );
729
		}
730
731
		// Check that the product type is supported. Return blank if not supported.
732
		if ( ! is_object( $product_data ) || ! in_array( $product_data->product_type, self::get_supported_product_types() ) ) {
733
			return '';
734
		}
735
736
		ob_start();
737
738
		// Get Subscription Trial Length
739
		$trial_length = WC_Subscriptions_Product::get_trial_length( $product_data );
740
741
		// If the trial length is empty, look for alternative.
742
		if ( empty( $trial_length ) ) {
743
			$scheme = self::get_satt_lowest_scheme_data( $product_data );
744
745
			if ( !empty( $scheme ) && is_array( $scheme ) ) {
746
				$trial_length = $scheme['scheme']['subscription_trial_length'];
747
			}
748
		}
749
750
		echo $trial_length;
751
752
		return ob_get_clean();
753
	} // END get_subscription_trial_length()
754
755
	/**
756
	 * Displays the subscription trial period of the subscription product.