Check a valid product object was obtained before calling its methods.

This commit is contained in:
barryhughes 2023-01-13 14:38:56 -08:00
parent ebae81ccaf
commit c41eccc58e
2 changed files with 19 additions and 1 deletions

View File

@ -0,0 +1,4 @@
Significance: patch
Type: fix
When adjusting download permissions, confirm the child products have not been removed.

View File

@ -99,7 +99,21 @@ class DownloadPermissionsAdjuster {
$children_with_downloads = array();
foreach ( $children_ids as $child_id ) {
$child = wc_get_product( $child_id );
$child = wc_get_product( $child_id );
// Ensure we have a valid child product.
if ( ! $child ) {
wc_get_logger()->warning(
sprintf(
/* translators: 1: child product ID 2: parent product ID. */
__( 'Unable to load child product %1$d while adjusting download permissions for product %2$d.', 'woocommerce' ),
$child_id,
$product_id
)
);
continue;
}
$children_with_downloads[ $child_id ] = $this->get_download_files_and_permissions( $child );
}