Fatal error: Uncaught Error: Call to a member function get_id() on string
-
ChatGPT says:
This is a plugin bug (in WooCommerce Call for Price Pro) where it’s calling $product->get_id() but sometimes receives a string instead of a WC_Product object. It surfaces while WooCommerce builds variable product data and Stripe Express checks whether to show its button.Fatal error: Uncaught Error: Call to a member function get_id() on string in /home/tashimannox/webapps/tashimannox/wp-content/plugins/woocommerce-call-for-price-pro/includes/class-alg-wc-call-for-price.php:774 Stack trace: #0 /home/tashimannox/webapps/tashimannox/wp-includes/class-wp-hook.php(324): Alg_WC_Call_For_Price->alg_cfp_empty_price_products_stock_management() #1 /home/tashimannox/webapps/tashimannox/wp-includes/plugin.php(205): WP_Hook->apply_filters() #2 /home/tashimannox/webapps/tashimannox/wp-content/plugins/woocommerce/includes/wc-formatting-functions.php(1157): apply_filters() #3 /home/tashimannox/webapps/tashimannox/wp-content/plugins/woocommerce/includes/class-wc-product-variable.php(422): wc_format_content() #4 /home/tashimannox/webapps/tashimannox/wp-content/plugins/woocommerce/includes/class-wc-product-variable.php(340): WC_Product_Variable->get_available_variation() #5 /home/tashimannox/webapps/tashimannox/wp-content/plugins/woocommerce-gateway-stripe/includes/payment-methods/class-wc-stripe-express-checkout-helper.php(695): WC_Product_Variable->get_available_variations() #6 /home/tashimannox/webapps/tashimannox/wp-content/plugins/woocommerce-gateway-stripe/includes/payment-methods/class-wc-stripe-express-checkout-element.php(145): WC_Stripe_Express_Checkout_Helper->should_show_express_checkout_button() #7 /home/tashimannox/webapps/tashimannox/wp-includes/class-wp-hook.php(324): WC_Stripe_Express_Checkout_Element->set_session() #8 /home/tashimannox/webapps/tashimannox/wp-includes/class-wp-hook.php(348): WP_Hook->apply_filters() #9 /home/tashimannox/webapps/tashimannox/wp-includes/plugin.php(517): WP_Hook->do_action() #10 /home/tashimannox/webapps/tashimannox/wp-includes/template-loader.php(13): do_action() #11 /home/tashimannox/webapps/tashimannox/wp-blog-header.php(19): require_once('...') #12 /home/tashimannox/webapps/tashimannox/index.php(17): require('...') #13 {main} thrown in /home/tashimannox/webapps/tashimannox/wp-content/plugins/woocommerce-call-for-price-pro/includes/class-alg-wc-call-for-price.php on line 774I edited the main code in class-alg-wc-call-for-price.php to fix it as follows, so please can you put your own fix in before the next update:
public function alg_cfp_empty_price_products_stock_management( $short_desc ) {
// early in alg_cfp_empty_price_products_stock_management(...)
if ( is_string($product) )
{
// It’s actually the content string from wc_format_content — bail safely.
return $content ?? '';
}
if ( is_numeric($product) )
{
$product = wc_get_product($product);
}
if ( ! $product instanceof WC_Product )
{
return $content ?? '';
}
if ( is_product() ) {
global $product;
$product_id = $product->get_id();
$product_price = $product->get_price();
$product_type = $product->get_type();
switch ( $product->get_type() ) {
case 'simple':
if ( ( ( '' === $product_price || ( ( '0' === $product_price ) && ( 'yes' === get_option( 'alg_call_for_price_enable_cfp_for_zero_price', 'no' ) ) ) ) && ( 'yes' === $this->alg_wc_cfp_stock_setting_for_empty_price_product() ) ) ) {
$short_desc .= wc_get_stock_html( $product );
}
break;
}
}
return $short_desc;
}
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
The topic ‘Fatal error: Uncaught Error: Call to a member function get_id() on string’ is closed to new replies.