WC_Product_Simple{}
Simple product class.
Hooks from the class
Usage
$WC_Product_Simple = new WC_Product_Simple(); // use class methods
Methods
- public __construct( $product = 0 )
- public add_to_cart_description()
- public add_to_cart_success_message()
- public add_to_cart_text()
- public add_to_cart_url()
- public get_type()
WC_Product_Simple{} WC Product Simple{} code WC 9.4.2
class WC_Product_Simple extends WC_Product { /** * Initialize simple product. * * @param WC_Product|int $product Product instance or ID. */ public function __construct( $product = 0 ) { $this->supports[] = 'ajax_add_to_cart'; parent::__construct( $product ); } /** * Get internal type. * * @return string */ public function get_type() { return 'simple'; } /** * Get the add to url used mainly in loops. * * @return string */ public function add_to_cart_url() { $url = $this->is_purchasable() && $this->is_in_stock() ? remove_query_arg( 'added-to-cart', add_query_arg( array( 'add-to-cart' => $this->get_id(), ), ( function_exists( 'is_feed' ) && is_feed() ) || ( function_exists( 'is_404' ) && is_404() ) ? $this->get_permalink() : '' ) ) : $this->get_permalink(); return apply_filters( 'woocommerce_product_add_to_cart_url', $url, $this ); } /** * Get the add to cart button text. * * @return string */ public function add_to_cart_text() { $text = $this->is_purchasable() && $this->is_in_stock() ? __( 'Add to cart', 'woocommerce' ) : __( 'Read more', 'woocommerce' ); return apply_filters( 'woocommerce_product_add_to_cart_text', $text, $this ); } /** * Get the add to cart button text description - used in aria tags. * * @since 3.3.0 * @return string */ public function add_to_cart_description() { /* translators: %s: Product title */ $text = $this->is_purchasable() && $this->is_in_stock() ? __( 'Add to cart: “%s”', 'woocommerce' ) : __( 'Read more about “%s”', 'woocommerce' ); return apply_filters( 'woocommerce_product_add_to_cart_description', sprintf( $text, $this->get_name() ), $this ); } /** * Get the add to cart button success message - used to update the mini cart live region. * * @return string */ public function add_to_cart_success_message() { $text = ''; if ( $this->is_purchasable() && $this->is_in_stock() ) { /* translators: %s: Product title */ $text = __( '“%s” has been added to your cart', 'woocommerce' ); $text = sprintf( $text, $this->get_name() ); } /** * Filter product add to cart success message. * * @since 9.2.0 * @param string $text The success message when a product is added to the cart. * @param WC_Product_Simple $this Reference to the current WC_Product_Simple instance. */ return apply_filters( 'woocommerce_product_add_to_cart_success_message', $text, $this ); } }