Show variations in upsells when parent is not published (#30042)

* Show variations in upsells when parent is not published

I was struggling to get the upsell section to show for our eCommerce site. After some digging I found that line 1525 stopped variations from showing in the upsell section if the parent product was set to privately published. This makes testing products and upsells hard, and it's inconsistent behaviour when simple products that are privately published do show up. The proposed change will make variations show up as long as the current user can edit the parent product. This is consistent with the behaviour for simple products.

* Add changelog

---------

Co-authored-by: Jorge Torres <jorge.torres@automattic.com>
This commit is contained in:
Dekadinious 2023-12-01 18:08:11 +01:00 committed by GitHub
parent 94e4ffd611
commit acdb2df13a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 5 additions and 1 deletions

View File

@ -0,0 +1,4 @@
Significance: minor
Type: add
Display variation upsells from private variable products to users with required permissions.

View File

@ -1603,7 +1603,7 @@ class WC_Product extends WC_Abstract_Legacy_Product {
if ( $this->get_parent_id() ) {
$parent_product = wc_get_product( $this->get_parent_id() );
if ( $parent_product && 'publish' !== $parent_product->get_status() ) {
if ( $parent_product && 'publish' !== $parent_product->get_status() && ! current_user_can( 'edit_post', $parent_product->get_id() ) ) {
$visible = false;
}
}