Check if $product exists before using

And removed some PHP variables.
This commit is contained in:
Claudio Sanches 2020-11-11 19:55:59 -03:00
parent cb727736c0
commit 6e2086e3eb
1 changed files with 2 additions and 5 deletions

View File

@ -906,12 +906,9 @@ class WC_Form_Handler {
}
// Prevent parent variable product from being added to cart.
if ( empty( $variation_id ) && $product->is_type( 'variable' ) ) {
$url = get_permalink( $product_id );
$product_name = $product->get_name();
if ( empty( $variation_id ) && $product && $product->is_type( 'variable' ) ) {
/* translators: 1: product link, 2: product name */
wc_add_notice( sprintf( __( 'Please choose product options by visiting <a href="%1$s" title="%2$s">%2$s</a>.', 'woocommerce' ), esc_url( $url ), esc_html( $product_name ) ), 'error' );
wc_add_notice( sprintf( __( 'Please choose product options by visiting <a href="%1$s" title="%2$s">%2$s</a>.', 'woocommerce' ), esc_url( get_permalink( $product_id ) ), esc_html( $product->get_name() ) ), 'error' );
return false;
}