php - 在 function.php 文件中获取产品标题
问题描述
我正在尝试在 functions.php 页面上获取当前的 woocommerce 产品标题。我尝试使用 $product->ID、get_the_title 等所有功能,但没有人在工作。
function custom_title() {
global $new_myKey, $post, $product;
$cache_key = 'myKey';
$myKey = wp_cache_get( $cache_key );
if( false === $myKey ){
$new_myKey = get_the_title();
wp_cache_set( $myKey, $new_myKey );
}
}
add_action( 'after_setup_theme', 'custom_title' );
此时 $new_myKey = get_the_title(); 我想获得动态产品标题。有什么办法吗?
解决方案
推荐阅读
- unity3d - Google play 在我的 Unity 游戏中检测到 android 广告 ID。在哪里?
- c - Printf 不打印 - 返回 NULL
- kobo - 如何使用 Kobo API 将数据发布到 kobotoolbox 表单?
- security - 从独立脚本手动运行函数
- apache-kafka-streams - Kafka Streaming 作为 ETL 替代品的最佳实践是什么?
- azure-devops - 如何在 AzureDevOps 中使用旧名称重新创建代理池?
- coinbase-api - 如何在 coinbase api 中导入转换?
- html - 在 CSS 中,如何重置按钮的默认浏览器给定样式?
- python - Python中列表中的最短路径
- javascript - 使用 jQuery 内联附加图像