1 <?php
2
3 if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
4
5 /**
6 * External Product Class
7 *
8 * External products cannot be bought; they link offsite. Extends simple products.
9 *
10 * @class WC_Product_External
11 * @version 2.0.0
12 * @package WooCommerce/Classes/Products
13 * @category Class
14 * @author WooThemes
15 */
16 class WC_Product_External extends WC_Product {
17
18 /**
19 * __construct function.
20 *
21 * @access public
22 * @param mixed $product
23 */
24 public function __construct( $product ) {
25 $this->product_type = 'external';
26 parent::__construct( $product );
27 }
28
29 /**
30 * Returns false if the product cannot be bought.
31 *
32 * @access public
33 * @return bool
34 */
35 public function is_purchasable() {
36 return apply_filters( 'woocommerce_is_purchasable', false, $this );
37 }
38
39 /**
40 * Get the add to url used mainly in loops.
41 *
42 * @access public
43 * @return string
44 */
45 public function add_to_cart_url() {
46 return apply_filters( 'woocommerce_product_add_to_cart_url', $this->get_product_url(), $this );
47 }
48
49 /**
50 * Get the add to cart button text for the single page
51 *
52 * @access public
53 * @return string
54 */
55 public function single_add_to_cart_text() {
56 return apply_filters( 'woocommerce_product_single_add_to_cart_text', $this->get_button_text(), $this );
57 }
58
59 /**
60 * Get the add to cart button text
61 *
62 * @access public
63 * @return string
64 */
65 public function add_to_cart_text() {
66 return apply_filters( 'woocommerce_product_single_add_to_cart_text', $this->get_button_text(), $this );
67 }
68
69 /**
70 * get_product_url function.
71 *
72 * @access public
73 * @return string
74 */
75 public function get_product_url() {
76 return esc_url( $this->product_url );
77 }
78
79 /**
80 * get_button_text function.
81 *
82 * @access public
83 * @return string
84 */
85 public function get_button_text() {
86 return $this->button_text ? $this->button_text : __( 'Buy product', 'woocommerce' );
87 }
88 }
89