You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

求助:如何修复get_product已弃用报错?自定义主题更新问题

Fixing the "get_product is deprecated since version 3.0! Use wc_get_product instead" Warning

Hey there, let's work through this WooCommerce deprecation warning step by step. The issue is straightforward: WooCommerce 3.0+ phased out the old get_product() function in favor of wc_get_product(), and your custom theme still has lingering references to the outdated method. Here's how to track down and fix every instance:

Step 1: Locate all uses of get_product in your theme

You mentioned modifying price.php and abstract-wc-product.php, but there are almost certainly other files in your theme calling the deprecated function. Here's how to find them all:

  • Open your theme's directory in a code editor (like VS Code, Sublime Text, or PhpStorm)
  • Use the global search tool (Ctrl+Shift+F in VS Code) to search for get_product( across every file in your theme folder
  • Pay extra attention to these common locations:
    • The theme's root functions.php file
    • WooCommerce template overrides (usually stored in a woocommerce subfolder of your theme)
    • Custom product templates (like single-product.php, archive-product.php, or theme-specific product blocks)
    • Include/module folders (often named inc or modules)

Step 2: Replace get_product with wc_get_product everywhere

For every match you find, swap the old function call with the new one. Examples of the replacement:

  • Before: $product = get_product( $product_id );
  • After: $product = wc_get_product( $product_id );

Don't miss subtle variations either, like:

  • get_product( get_the_ID() ) → wc_get_product( get_the_ID() )
  • get_product( $post->ID ) → wc_get_product( $post->ID )

Step 3: Pinpoint remaining warnings with debug mode

If the warning still pops up after your first pass, enable WordPress debug mode to get the exact file and line number triggering the issue:

  1. Open your site's wp-config.php file (in the root WordPress directory)
  2. Find the line define('WP_DEBUG', false); and replace it with:
    define('WP_DEBUG', true);
    define('WP_DEBUG_LOG', true);
    define('WP_DEBUG_DISPLAY', true);
    
  3. Refresh the page with the warning. You'll now see the full path to the file and line where get_product is still being used—this will help you track down any missed instances.

Step 4: Clear all caches

After making your changes, clear every layer of cache to ensure the updates take effect:

  • Your WordPress caching plugin's cache (if you use tools like WP Rocket, W3 Total Cache, or LiteSpeed Cache)
  • Your browser's cache (use Ctrl+Shift+R for a hard refresh)
  • Any server-level cache (check your hosting control panel if you're unsure)

Bonus Tips

  • Backup first: Always make a copy of your theme files before modifying them, so you can revert quickly if something breaks.
  • Loop in your theme developer: Since this is a custom theme built by your boss, let them know about the deprecated function. Updating the theme's core code will prevent this issue from coming back if the theme gets updated later.

内容的提问来源于stack exchange,提问作者Kristoffer Bålerud Helgesen

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.22 08:00:50