WC_Product_External

External Product Class.

Defined (1)

The class is defined in the following location(s).

/includes/class-wc-product-external.php  
  1. class WC_Product_External extends WC_Product { 
  2.  
  3. /** 
  4. * Stores product data. 
  5. * @var array 
  6. */ 
  7. protected $extra_data = array( 
  8. 'product_url' => '',  
  9. 'button_text' => '',  
  10. ); 
  11.  
  12. /** 
  13. * Get internal type. 
  14. * @return string 
  15. */ 
  16. public function get_type() { 
  17. return 'external'; 
  18.  
  19. /** 
  20. |-------------------------------------------------------------------------- 
  21. | Getters 
  22. |-------------------------------------------------------------------------- 
  23. | Methods for getting data from the product object. 
  24. */ 
  25.  
  26. /** 
  27. * Get product url. 
  28. * @param string $context 
  29. * @return string 
  30. */ 
  31. public function get_product_url( $context = 'view' ) { 
  32. return esc_url( $this->get_prop( 'product_url', $context ) ); 
  33.  
  34. /** 
  35. * Get button text. 
  36. * @param string $context 
  37. * @return string 
  38. */ 
  39. public function get_button_text( $context = 'view' ) { 
  40. return $this->get_prop( 'button_text', $context ); 
  41.  
  42. /** 
  43. |-------------------------------------------------------------------------- 
  44. | Setters 
  45. |-------------------------------------------------------------------------- 
  46. | Functions for setting product data. These should not update anything in the 
  47. | database itself and should only change what is stored in the class 
  48. | object. 
  49. */ 
  50.  
  51. /** 
  52. * Set product URL. 
  53. * @since 3.0.0 
  54. * @param string $product_url Product URL. 
  55. */ 
  56. public function set_product_url( $product_url ) { 
  57. $this->set_prop( 'product_url', $product_url ); 
  58.  
  59. /** 
  60. * Set button text. 
  61. * @since 3.0.0 
  62. * @param string $button_text Button text. 
  63. */ 
  64. public function set_button_text( $button_text ) { 
  65. $this->set_prop( 'button_text', $button_text ); 
  66.  
  67. /** 
  68. * External products cannot be stock managed. 
  69. * @since 3.0.0 
  70. * @param bool 
  71. */ 
  72. public function set_manage_stock( $manage_stock ) { 
  73. $this->set_prop( 'manage_stock', false ); 
  74.  
  75. if ( true === $manage_stock ) { 
  76. $this->error( 'product_external_invalid_manage_stock', __( 'External products cannot be stock managed.', 'woocommerce' ) ); 
  77.  
  78. /** 
  79. * External products cannot be stock managed. 
  80. * @since 3.0.0 
  81. * @param bool 
  82. */ 
  83. public function set_stock_status( $stock_status = '' ) { 
  84. $this->set_prop( 'stock_status', 'instock' ); 
  85.  
  86. if ( 'instock' !== $stock_status ) { 
  87. $this->error( 'product_external_invalid_stock_status', __( 'External products cannot be stock managed.', 'woocommerce' ) ); 
  88.  
  89. /** 
  90. * xternal products cannot be backordered. 
  91. * @since 3.0.0 
  92. * @param string $backorders Options: 'yes', 'no' or 'notify'. 
  93. */ 
  94. public function set_backorders( $backorders ) { 
  95. $this->set_prop( 'backorders', 'no' ); 
  96.  
  97. if ( 'no' !== $backorders ) { 
  98. $this->error( 'product_external_invalid_backorders', __( 'External products cannot be backordered.', 'woocommerce' ) ); 
  99.  
  100. /** 
  101. |-------------------------------------------------------------------------- 
  102. | Other Actions 
  103. |-------------------------------------------------------------------------- 
  104. */ 
  105.  
  106. /** 
  107. * Returns false if the product cannot be bought. 
  108. * @access public 
  109. * @return bool 
  110. */ 
  111. public function is_purchasable() { 
  112. return apply_filters( 'woocommerce_is_purchasable', false, $this ); 
  113.  
  114. /** 
  115. * Get the add to url used mainly in loops. 
  116. * @access public 
  117. * @return string 
  118. */ 
  119. public function add_to_cart_url() { 
  120. return apply_filters( 'woocommerce_product_add_to_cart_url', $this->get_product_url(), $this ); 
  121.  
  122. /** 
  123. * Get the add to cart button text for the single page. 
  124. * @access public 
  125. * @return string 
  126. */ 
  127. public function single_add_to_cart_text() { 
  128. return apply_filters( 'woocommerce_product_single_add_to_cart_text', $this->get_button_text() ? $this->get_button_text() : _x( 'Buy product', 'placeholder', 'woocommerce' ), $this ); 
  129.  
  130. /** 
  131. * Get the add to cart button text. 
  132. * @access public 
  133. * @return string 
  134. */ 
  135. public function add_to_cart_text() { 
  136. return apply_filters( 'woocommerce_product_add_to_cart_text', $this->get_button_text() ? $this->get_button_text() : _x( 'Buy product', 'placeholder', 'woocommerce' ), $this );