Aucune description

class-wc-product-simple.php 1.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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(
  38. 'added-to-cart',
  39. add_query_arg(
  40. array(
  41. 'add-to-cart' => $this->get_id(),
  42. ),
  43. ( function_exists( 'is_feed' ) && is_feed() ) || ( function_exists( 'is_404' ) && is_404() ) ? $this->get_permalink() : ''
  44. )
  45. ) : $this->get_permalink();
  46. return apply_filters( 'woocommerce_product_add_to_cart_url', $url, $this );
  47. }
  48. /**
  49. * Get the add to cart button text.
  50. *
  51. * @return string
  52. */
  53. public function add_to_cart_text() {
  54. $text = $this->is_purchasable() && $this->is_in_stock() ? __( 'Add to cart', 'woocommerce' ) : __( 'Read more', 'woocommerce' );
  55. return apply_filters( 'woocommerce_product_add_to_cart_text', $text, $this );
  56. }
  57. /**
  58. * Get the add to cart button text description - used in aria tags.
  59. *
  60. * @since 3.3.0
  61. * @return string
  62. */
  63. public function add_to_cart_description() {
  64. /* translators: %s: Product title */
  65. $text = $this->is_purchasable() && $this->is_in_stock() ? __( 'Add &ldquo;%s&rdquo; to your cart', 'woocommerce' ) : __( 'Read more about &ldquo;%s&rdquo;', 'woocommerce' );
  66. return apply_filters( 'woocommerce_product_add_to_cart_description', sprintf( $text, $this->get_name() ), $this );
  67. }
  68. }