Code Duplication    Length = 46-60 lines in 2 locations

includes/abstracts/abstract-wc-product.php 1 location

@@ 676-735 (lines=60) @@
673
	 *
674
	 * @return string
675
	 */
676
	public function get_availability() {
677
		$availability = $class = '';
678
679
		if ( $this->managing_stock() ) {
680
681
			if ( $this->is_in_stock() && $this->get_total_stock() > get_option( 'woocommerce_notify_no_stock_amount' ) ) {
682
683
				switch ( get_option( 'woocommerce_stock_format' ) ) {
684
685
					case 'no_amount' :
686
						$availability = __( 'In stock', 'woocommerce' );
687
					break;
688
689
					case 'low_amount' :
690
						if ( $this->get_total_stock() <= get_option( 'woocommerce_notify_low_stock_amount' ) ) {
691
							$availability = sprintf( __( 'Only %s left in stock', 'woocommerce' ), $this->get_total_stock() );
692
693
							if ( $this->backorders_allowed() && $this->backorders_require_notification() ) {
694
								$availability .= ' ' . __( '(can be backordered)', 'woocommerce' );
695
							}
696
						} else {
697
							$availability = __( 'In stock', 'woocommerce' );
698
						}
699
					break;
700
701
					default :
702
						$availability = sprintf( __( '%s in stock', 'woocommerce' ), $this->get_total_stock() );
703
704
						if ( $this->backorders_allowed() && $this->backorders_require_notification() ) {
705
							$availability .= ' ' . __( '(can be backordered)', 'woocommerce' );
706
						}
707
					break;
708
				}
709
710
				$class        = 'in-stock';
711
712
			} elseif ( $this->backorders_allowed() && $this->backorders_require_notification() ) {
713
714
				$availability = __( 'Available on backorder', 'woocommerce' );
715
				$class        = 'available-on-backorder';
716
717
			} elseif ( $this->backorders_allowed() ) {
718
719
				$availability = __( 'In stock', 'woocommerce' );
720
				$class        = 'in-stock';
721
722
			} else {
723
724
				$availability = __( 'Out of stock', 'woocommerce' );
725
				$class        = 'out-of-stock';
726
			}
727
728
		} elseif ( ! $this->is_in_stock() ) {
729
730
			$availability = __( 'Out of stock', 'woocommerce' );
731
			$class        = 'out-of-stock';
732
		}
733
734
		return apply_filters( 'woocommerce_get_availability', array( 'availability' => $availability, 'class' => $class ), $this );
735
	}
736
737
	/**
738
	 * Returns whether or not the product is featured.

includes/class-wc-product-variation.php 1 location

@@ 540-585 (lines=46) @@
537
	 *
538
	 * @return string
539
	 */
540
	public function get_availability() {
541
		$availability = $class = '';
542
543
		if ( $this->managing_stock() ) {
544
			if ( $this->is_in_stock() && $this->get_stock_quantity() > get_option( 'woocommerce_notify_no_stock_amount' ) ) {
545
				switch ( get_option( 'woocommerce_stock_format' ) ) {
546
					case 'no_amount' :
547
						$availability = __( 'In stock', 'woocommerce' );
548
					break;
549
					case 'low_amount' :
550
						if ( $this->get_stock_quantity() <= get_option( 'woocommerce_notify_low_stock_amount' ) ) {
551
							$availability = sprintf( __( 'Only %s left in stock', 'woocommerce' ), $this->get_stock_quantity() );
552
553
							if ( $this->backorders_allowed() && $this->backorders_require_notification() ) {
554
								$availability .= ' ' . __( '(can be backordered)', 'woocommerce' );
555
							}
556
						} else {
557
							$availability = __( 'In stock', 'woocommerce' );
558
						}
559
					break;
560
					default :
561
						$availability = sprintf( __( '%s in stock', 'woocommerce' ), $this->get_stock_quantity() );
562
563
						if ( $this->backorders_allowed() && $this->backorders_require_notification() ) {
564
							$availability .= ' ' . __( '(can be backordered)', 'woocommerce' );
565
						}
566
					break;
567
				}
568
				$class        = 'in-stock';
569
			} elseif ( $this->backorders_allowed() && $this->backorders_require_notification() ) {
570
				$availability = __( 'Available on backorder', 'woocommerce' );
571
				$class        = 'available-on-backorder';
572
			} elseif ( $this->backorders_allowed() ) {
573
				$availability = __( 'In stock', 'woocommerce' );
574
				$class        = 'in-stock';
575
			} else {
576
				$availability = __( 'Out of stock', 'woocommerce' );
577
				$class        = 'out-of-stock';
578
			}
579
		} elseif ( ! $this->is_in_stock() ) {
580
			$availability = __( 'Out of stock', 'woocommerce' );
581
			$class        = 'out-of-stock';
582
		}
583
584
		return apply_filters( 'woocommerce_get_availability', array( 'availability' => $availability, 'class' => $class ), $this );
585
	}
586
587
	/**
588
	 * Returns whether or not the product needs to notify the customer on backorder.