In my wordpress website I getting below error
Fatal error: Call to a member function get_id() on boolean in /home/customer/www/ae.testing.com/public_html/wp-content/themes/movedo-child/functions.php on line 33
Previously working fine . but now what exact issue i am not getting. if any one have idea then let me know
function.php as follows:
<?php
function movedo_child_theme_setup() {
}
add_action( 'after_setup_theme', 'movedo_child_theme_setup' );
function display_price_in_variation_option_name( $term ) {
echo $product = wc_get_product();
$id = $product->get_id();
if ( empty( $term ) || empty( $id ) ) {
return $term;
}
if ( $product->is_type( 'variable' ) ) {
$product_variations = $product->get_available_variations();
} else {
return $term;
}
foreach($product_variations as $variation){
if(count($variation['attributes']) > 1){
return $term;
}
foreach($variation['attributes'] as $key => $slug){
if("attribute_" == mb_substr( $key, 0, 10 )){
$taxonomy = mb_substr( $key, 10 ) ;
$attribute = get_term_by('slug', $slug, $taxonomy);
if($attribute->name == $term){
$term .= " (" . wp_kses( wc_price($variation['display_price']), array()) . ")";
}
}
}
}
return $term;
}
add_filter( 'woocommerce_variation_option_name', 'display_price_in_variation_option_name' );
On line "$id = $product->get_id();" I m getting this error.