Add more specific errors for all product type which are unpurchasable
This commit is contained in:
parent
50d9c73809
commit
b2e262f6cc
|
@ -151,6 +151,15 @@ class WC_Product_External extends WC_Product {
|
|||
return apply_filters( 'woocommerce_is_purchasable', false, $this );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a user friendly message about why an item is not purchasable.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_unable_to_purchase_message() {
|
||||
return __( 'Sorry, this external product cannot be purchased here.', 'woocommerce' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the add to url used mainly in loops.
|
||||
*
|
||||
|
|
|
@ -82,6 +82,16 @@ class WC_Product_Grouped extends WC_Product {
|
|||
return apply_filters( 'woocommerce_is_purchasable', false, $this );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a user friendly message about why an item is not purchasable.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_unable_to_purchase_message() {
|
||||
|
||||
return __( 'Sorry, this grouped product cannot be purchased individually.');
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the price in html format.
|
||||
*
|
||||
|
|
|
@ -547,6 +547,23 @@ class WC_Product_Variation extends WC_Product_Simple {
|
|||
return apply_filters( 'woocommerce_variation_is_purchasable', $this->variation_is_visible() && parent::is_purchasable() && ( 'publish' === $this->parent_data['status'] || current_user_can( 'edit_post', $this->get_parent_id() ) ), $this );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a user friendly message about why an item is not purchasable.
|
||||
* Override abstract so the error can be more precise.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_unable_to_purchase_message() {
|
||||
if ( ! $this->variation_is_visible() ) {
|
||||
$message = __( 'Sorry, this product variation cannot be purchased because it is disabled.', 'woocommerce' );
|
||||
} elseif( 'publish' === $this->parent_data['status'] || current_user_can( 'edit_post', $this->get_parent_id() ) ) {
|
||||
$message = __( 'Sorry, this product variation cannot be purchased because its parent has been removed.', 'woocommerce');
|
||||
} else {
|
||||
$message = parent::get_unable_to_purchase_message();
|
||||
}
|
||||
return $message;
|
||||
}
|
||||
|
||||
/**
|
||||
* Controls whether this particular variation will appear greyed-out (inactive) or not (active).
|
||||
* Used by extensions to make incompatible variations appear greyed-out, etc.
|
||||
|
|
Loading…
Reference in New Issue