parent
856d192bff
commit
aec0e0e327
|
@ -57,7 +57,7 @@ class WC_Product {
|
||||||
public $product_type = null;
|
public $product_type = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Prouduct shipping class
|
* Product shipping class
|
||||||
*
|
*
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
|
@ -70,6 +70,12 @@ class WC_Product {
|
||||||
*/
|
*/
|
||||||
protected $shipping_class_id = 0;
|
protected $shipping_class_id = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Supported features such as 'ajax_add_to_cart'
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
|
protected $supports = array();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor gets the post object and sets the ID for the loaded product.
|
* Constructor gets the post object and sets the ID for the loaded product.
|
||||||
*
|
*
|
||||||
|
@ -144,6 +150,19 @@ class WC_Product {
|
||||||
return $this->post;
|
return $this->post;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if a product supports a given feature.
|
||||||
|
*
|
||||||
|
* Product classes should override this to declare support (or lack of support) for a feature.
|
||||||
|
*
|
||||||
|
* @param string $feature string The name of a feature to test support for.
|
||||||
|
* @return bool True if the product supports the feature, false otherwise.
|
||||||
|
* @since 2.5.0
|
||||||
|
*/
|
||||||
|
public function supports( $feature ) {
|
||||||
|
return apply_filters( 'woocommerce_product_supports', in_array( $feature, $this->supports ) ? true : false, $feature, $this );
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* get_gallery_attachment_ids function.
|
* get_gallery_attachment_ids function.
|
||||||
*
|
*
|
||||||
|
@ -750,17 +769,6 @@ class WC_Product {
|
||||||
return apply_filters( 'woocommerce_is_purchasable', $purchasable, $this );
|
return apply_filters( 'woocommerce_is_purchasable', $purchasable, $this );
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns whether or not the product can be added to the cart via ajax
|
|
||||||
*
|
|
||||||
* @since 2.4.9
|
|
||||||
* @return bool
|
|
||||||
*/
|
|
||||||
public function supports_ajax_add_to_cart() {
|
|
||||||
return apply_filters( 'woocommerce_product_supports_ajax_add_to_cart', $this->is_type( 'simple' ), $this );
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set a products price dynamically.
|
* Set a products price dynamically.
|
||||||
*
|
*
|
||||||
|
|
|
@ -24,6 +24,7 @@ class WC_Product_Simple extends WC_Product {
|
||||||
*/
|
*/
|
||||||
public function __construct( $product ) {
|
public function __construct( $product ) {
|
||||||
$this->product_type = 'simple';
|
$this->product_type = 'simple';
|
||||||
|
$this->supports[] = 'ajax_add_to_cart';
|
||||||
parent::__construct( $product );
|
parent::__construct( $product );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -12,11 +12,11 @@
|
||||||
* @see http://docs.woothemes.com/document/template-structure/
|
* @see http://docs.woothemes.com/document/template-structure/
|
||||||
* @author WooThemes
|
* @author WooThemes
|
||||||
* @package WooCommerce/Templates
|
* @package WooCommerce/Templates
|
||||||
* @version 2.4.9
|
* @version 2.5.0
|
||||||
*/
|
*/
|
||||||
|
|
||||||
if ( ! defined( 'ABSPATH' ) ) {
|
if ( ! defined( 'ABSPATH' ) ) {
|
||||||
exit; // Exit if accessed directly
|
exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
global $product;
|
global $product;
|
||||||
|
@ -28,7 +28,7 @@ echo apply_filters( 'woocommerce_loop_add_to_cart_link',
|
||||||
esc_attr( $product->get_sku() ),
|
esc_attr( $product->get_sku() ),
|
||||||
esc_attr( isset( $quantity ) ? $quantity : 1 ),
|
esc_attr( isset( $quantity ) ? $quantity : 1 ),
|
||||||
$product->is_purchasable() && $product->is_in_stock() ? 'add_to_cart_button' : '',
|
$product->is_purchasable() && $product->is_in_stock() ? 'add_to_cart_button' : '',
|
||||||
$product->supports_ajax_add_to_cart() ? 'ajax_add_to_cart' : '',
|
$product->supports( 'ajax_add_to_cart' ) ? 'ajax_add_to_cart' : '',
|
||||||
esc_attr( $product->product_type ),
|
esc_attr( $product->product_type ),
|
||||||
esc_html( $product->add_to_cart_text() )
|
esc_html( $product->add_to_cart_text() )
|
||||||
),
|
),
|
||||||
|
|
Loading…
Reference in New Issue