Completed
Push — master ( e007b2...badb13 )
by Gerhard
08:45
created

WC_Product_Simple::add_to_cart_url()   B

Complexity

Conditions 7
Paths 4

Size

Total Lines 12

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 56

Importance

Changes 0
Metric Value
cc 7
nc 4
nop 0
dl 0
loc 12
ccs 0
cts 8
cp 0
crap 56
rs 8.8333
c 0
b 0
f 0
1
<?php
2
/**
3
 * Simple Product Class.
4
 *
5
 * The default product type kinda product.
6
 *
7
 * @package WooCommerce/Classes/Products
8
 */
9
10
defined( 'ABSPATH' ) || exit;
11
12
/**
13
 * Simple product class.
14
 */
15
class WC_Product_Simple extends WC_Product {
16
17
	/**
18
	 * Initialize simple product.
19
	 *
20
	 * @param WC_Product|int $product Product instance or ID.
21
	 */
22 251
	public function __construct( $product = 0 ) {
23 251
		$this->supports[] = 'ajax_add_to_cart';
24 251
		parent::__construct( $product );
25
	}
26
27
	/**
28
	 * Get internal type.
29
	 *
30
	 * @return string
31
	 */
32 233
	public function get_type() {
33 233
		return 'simple';
34
	}
35
36
	/**
37
	 * Get the add to url used mainly in loops.
38
	 *
39
	 * @return string
40
	 */
41
	public function add_to_cart_url() {
42
		$url = $this->is_purchasable() && $this->is_in_stock() ? remove_query_arg(
43
			'added-to-cart',
44
			add_query_arg(
45
				array(
46
					'add-to-cart' => $this->get_id(),
47
				),
48
				( function_exists( 'is_feed' ) && is_feed() ) || ( function_exists( 'is_404' ) && is_404() ) ? $this->get_permalink() : ''
49
			)
50
		) : $this->get_permalink();
51
		return apply_filters( 'woocommerce_product_add_to_cart_url', $url, $this );
52
	}
53
54
	/**
55
	 * Get the add to cart button text.
56
	 *
57
	 * @return string
58
	 */
59 1
	public function add_to_cart_text() {
60 1
		$text = $this->is_purchasable() && $this->is_in_stock() ? __( 'Add to cart', 'woocommerce' ) : __( 'Read more', 'woocommerce' );
61
62 1
		return apply_filters( 'woocommerce_product_add_to_cart_text', $text, $this );
63
	}
64
65
	/**
66
	 * Get the add to cart button text description - used in aria tags.
67
	 *
68
	 * @since 3.3.0
69
	 * @return string
70
	 */
71
	public function add_to_cart_description() {
72
		/* translators: %s: Product title */
73
		$text = $this->is_purchasable() && $this->is_in_stock() ? __( 'Add &ldquo;%s&rdquo; to your cart', 'woocommerce' ) : __( 'Read more about &ldquo;%s&rdquo;', 'woocommerce' );
74
75
		return apply_filters( 'woocommerce_product_add_to_cart_description', sprintf( $text, $this->get_name() ), $this );
76
	}
77
}
78