suneltr
Forum Replies Created
Viewing 2 replies - 1 through 2 (of 2 total)
-
Ok
if ( $product->is_type( 'variable' ) ) { // find out if attributes have been set in the URL // if not, continue // if yes get the variation id and variation SKU if ( $this->query_string_contains_all_variation_attributes( $product ) ) { // get variation product $product_id = $this->get_variation_from_query_string( $product_id, $product ); // In case a variable product is misconfigured, wc_get_product($product_id) will not // get a product but a bool. So we need to test it and only run it if // we actually get a product. Basically we fall back to the parent product. if ( !is_bool( wc_get_product( $product_id ) ) ) { $product = wc_get_product( $product_id ); } } } // if (is_bool($product)) { //// error_log( 'WooCommerce detects the page ID ' . $product_id . ' as product, but when invoked by wc_get_product( ' . $product_id . ' ) it returns no product object' ); // return; // } $product_id_compiled = $this->get_compiled_product_id( $product_id, $product->get_sku() );The product_id will be the variable product is misconfigured
what about this code
$parent_id = $product_id = get_the_ID(); $parent_product = $product = wc_get_product( $product_id ); // $product = wc_get_product(645645645); if ( is_bool( $product ) ) { // error_log( 'WooCommerce detects the page ID ' . $product_id . ' as product, but when invoked by wc_get_product( ' . $product_id . ' ) it returns no product object' ); return; } $product_attributes = [ 'brand' => $this->get_brand_name( $product_id ), ]; if ( $product->is_type( 'variable' ) ) { // find out if attributes have been set in the URL // if not, continue // if yes get the variation id and variation SKU if ( $this->query_string_contains_all_variation_attributes( $product ) ) { // get variation product $product_id = $this->get_variation_from_query_string( $product_id, $product ); $product = wc_get_product( $product_id ); } } if(is_bool($product)) { $product_id = $parent_id; $product = $parent_product; }- This reply was modified 5 years, 2 months ago by suneltr.
Viewing 2 replies - 1 through 2 (of 2 total)