Code Duplication    Length = 42-42 lines in 2 locations

includes/class-wcs-shortcodes.php 2 locations

@@ 482-523 (lines=42) @@
479
	 * @param  array $atts
480
	 * @return string
481
	 */
482
	public static function get_subscription_period_interval( $atts ) {
483
		global $wpdb, $post;
484
485
		$defaults = shortcode_atts( array(
486
			'id'  => '',
487
			'sku' => '',
488
		), $atts );
489
490
		$atts = wp_parse_args( $atts, $defaults );
491
492
		if ( ! empty( $atts['id'] ) && $atts['id'] > 0 ) {
493
			$product_data = wc_get_product( $atts['id'] );
494
		} elseif ( ! empty( $atts['sku'] ) ) {
495
			$product_id   = wc_get_product_id_by_sku( $atts['sku'] );
496
			$product_data = get_post( $product_id );
497
		} else {
498
			$product_data = wc_get_product( $post->ID );
499
		}
500
501
		// Check that the product type is supported. Return blank if not supported.
502
		if ( ! is_object( $product_data ) || ! in_array( $product_data->product_type, self::get_supported_product_types() ) ) {
503
			return '';
504
		}
505
506
		ob_start();
507
508
		// Get Subscription Period Interval
509
		$period_interval = WC_Subscriptions_Product::get_interval( $product_data );
510
511
		// If the period is empty, look for alternative.
512
		if ( empty( $period_interval ) ) {
513
			$scheme = self::get_satt_lowest_scheme_data( $product_data );
514
515
			if ( !empty( $scheme ) && is_array( $scheme ) ) {
516
				$period_interval = $scheme['scheme']['subscription_period_interval'];
517
			}
518
		}
519
520
		echo $period_interval;
521
522
		return ob_get_clean();
523
	} // END get_subscription_period_interval()
524
525
	/**
526
	 * Displays the subscription length of the subscription product.
@@ 727-768 (lines=42) @@
724
	 * @param  array $atts
725
	 * @return string
726
	 */
727
	public static function get_subscription_trial_length( $atts ) {
728
		global $wpdb, $post;
729
730
		$defaults = shortcode_atts( array(
731
			'id'  => '',
732
			'sku' => '',
733
		), $atts );
734
735
		$atts = wp_parse_args( $atts, $defaults );
736
737
		if ( ! empty( $atts['id'] ) && $atts['id'] > 0 ) {
738
			$product_data = wc_get_product( $atts['id'] );
739
		} elseif ( ! empty( $atts['sku'] ) ) {
740
			$product_id   = wc_get_product_id_by_sku( $atts['sku'] );
741
			$product_data = get_post( $product_id );
742
		} else {
743
			$product_data = wc_get_product( $post->ID );
744
		}
745
746
		// Check that the product type is supported. Return blank if not supported.
747
		if ( ! is_object( $product_data ) || ! in_array( $product_data->product_type, self::get_supported_product_types() ) ) {
748
			return '';
749
		}
750
751
		ob_start();
752
753
		// Get Subscription Trial Length
754
		$trial_length = WC_Subscriptions_Product::get_trial_length( $product_data );
755
756
		// If the trial length is empty, look for alternative.
757
		if ( empty( $trial_length ) ) {
758
			$scheme = self::get_satt_lowest_scheme_data( $product_data );
759
760
			if ( !empty( $scheme ) && is_array( $scheme ) ) {
761
				$trial_length = $scheme['scheme']['subscription_trial_length'];
762
			}
763
		}
764
765
		echo $trial_length;
766
767
		return ob_get_clean();
768
	} // END get_subscription_trial_length()
769
770
	/**
771
	 * Displays the subscription trial period of the subscription product.