class-wc-product-simple.php 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. <?php
  2. /**
  3. * Simple Product Class.
  4. *
  5. * The default product type kinda product.
  6. *
  7. * @package WooCommerce/Classes/Products
  8. */
  9. defined( 'ABSPATH' ) || exit;
  10. /**
  11. * Simple product class.
  12. */
  13. class WC_Product_Simple extends WC_Product {
  14. /**
  15. * Initialize simple product.
  16. *
  17. * @param WC_Product|int $product Product instance or ID.
  18. */
  19. public function __construct( $product = 0 ) {
  20. $this->supports[] = 'ajax_add_to_cart';
  21. parent::__construct( $product );
  22. }
  23. /**
  24. * Get internal type.
  25. *
  26. * @return string
  27. */
  28. public function get_type() {
  29. return 'simple';
  30. }
  31. /**
  32. * Get the add to url used mainly in loops.
  33. *
  34. * @return string
  35. */
  36. public function add_to_cart_url() {
  37. $url = $this->is_purchasable() && $this->is_in_stock() ? remove_query_arg( 'added-to-cart', add_query_arg( 'add-to-cart', $this->id ) ) : get_permalink( $this->id );
  38. return apply_filters( 'woocommerce_product_add_to_cart_url', $url, $this );
  39. }
  40. /**
  41. * Get the add to cart button text.
  42. *
  43. * @return string
  44. */
  45. public function add_to_cart_text() {
  46. $text = $this->is_purchasable() && $this->is_in_stock() ? __( 'Add to cart', 'woocommerce' ) : __( 'Read more', 'woocommerce' );
  47. return apply_filters( 'woocommerce_product_add_to_cart_text', $text, $this );
  48. }
  49. /**
  50. * Get the add to cart button text description - used in aria tags.
  51. *
  52. * @since 3.3.0
  53. * @return string
  54. */
  55. public function add_to_cart_description() {
  56. /* translators: %s: Product title */
  57. $text = $this->is_purchasable() && $this->is_in_stock() ? __( 'Add &ldquo;%s&rdquo; to your cart', 'woocommerce' ) : __( 'Read more about &ldquo;%s&rdquo;', 'woocommerce' );
  58. return apply_filters( 'woocommerce_product_add_to_cart_description', sprintf( $text, $this->get_name() ), $this );
  59. }
  60. }