Code Duplication    Length = 46-60 lines in 2 locations

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

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

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

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