Uncaught Error: Call to a member function get_type() on bool in /functions.php
-
Hi, I’ve been trying to call a single product’s attributes via shortcode and use in my page builder. The code is below;
add_shortcode("variation_table", "custom_available_variations_table"); function custom_available_variations_table( $atts ) { global $post; // Attributes $atts = shortcode_atts( array( 'id' => $post->ID ), $atts, 'variation_table' ); if( is_admin() ) return; // Only on front end $product = wc_get_product($atts['id']); // Get the WC_Product Object $output = '<div class="fs-product-data-wrapper">'; // Variable products if( $product->is_type('variable')) { // Get available variations in the variable product $available_variations = $product->get_available_variations(); if( count($available_variations) > 0 ){ foreach( $available_variations as $variation ) $output .= format_product_data_output( $variation['variation_id'] ); } } // Simple products elseif( $product->is_type('simple')) { $output .= format_product_data_output( $product->get_id() ); } else return; // Exit return $output .= '</div>'; // return always for a shortcode } // Utility funtion: getting and formtting product data function format_product_data_output( $the_id ){ $empty = __( '<em>(empty)</em>', 'woocommerce' ); // Get an instance of the WC_Product_Variation object $product = wc_get_product( $the_id ); $durability = $product->get_attribute( 'pa_durability' ); $durability = ! empty( $durability ) ? get_term_by( 'slug', $durability, 'pa_durability' )->name : $empty; $output = ' <ul> <li class="fs-data-size">Durability: '.$durability.'</li> </ul>'; return $output; }
And below is the error I keep getting
Uncaught Error: Call to a member function get_type() on bool in wp-content/themes/childtheme/functions.php:139 Stack trace: #0 wp-includes/shortcodes.php(356): custom_available_variations_table(Array, '', 'variation_table') #1 [internal function]: do_shortcode_tag(Array) #2 wp-includes/shortcodes.php(228): preg_replace_callback('/\\[(\\[?)(variat...', 'do_shortcode_ta...', '[variation_tabl...') #3 wp-content/plugins/js_composer/include/helpers/helpers.php(240): do_shortcode('[variation_tabl...') #4 wp-content/plugins/js_composer/include/templates/shortcodes/vc_column_text.php(31): wpb_js_remove_wpautop('<p>[variation_t...', true) #5 wp-content/plugins/js_composer/include/classes/shortcodes/core/class-wpbakeryshortcode.php(271): require('/home/hypacart/...') #6 wp-content/plugins/js_composer/include/classes/shortcodes/co
Viewing 3 replies - 1 through 3 (of 3 total)
Viewing 3 replies - 1 through 3 (of 3 total)
- The topic ‘Uncaught Error: Call to a member function get_type() on bool in /functions.php’ is closed to new replies.