woocommerce - 在 WooCommerce 产品页面中显示来自自定义 wp_editor 页面的内容
问题描述
我正在尝试echo
在 WooCommerce 产品页面上完成一个,但我不知道如何。我创建了自定义子菜单选项(产品 -> 挂钩内容),并wp_editor
在该页面上插入了该选项并为其提供了一个Save
按钮。内容已保存,但我不知道如何在产品页面上显示该内容。
任何帮助表示赞赏。这是代码。
add_action( 'woocommerce_single_product_summary', 'display_psm_meta', 5 );
function display_psm_meta() {
// echo the content from the wp_editor here
}
add_action( 'admin_menu', 'hooked_content_page', 9999 );
function hooked_content_page() {
add_submenu_page( 'edit.php?post_type=product', 'Hooked Content', 'Hooked Content', 'edit_products', 'hooked_content', 'hooked_content_page_callback', 9999 );
}
function hooked_content_page_callback() {
if ( isset( $_POST['psm_content'] ) ) {
update_option( 'psm_content', $_POST['psm_content'] );
} ?>
<div class='wrap'>
<h2>Hooked Content</h2>
<form method='post'> <?php
$content = get_option( 'psm_content' );
wp_editor( $content, 'psm_content', $settings = array( 'textarea_rows' => '10' ) );
submit_button( 'Save', 'primary' ); ?>
</form>
</div>
<?php
}
感谢我能得到的所有帮助。
解决方案
您可以使用此功能来显示您的自定义选项内容:
add_action( 'woocommerce_single_product_summary', 'display_psm_meta', 5 );
function display_psm_meta() {
echo get_option( 'psm_content' );
}
推荐阅读
- reactjs - 如何解决 Firebase:没有创建 Firebase App '[DEFAULT]' - 调用 Firebase App.initializeApp() (app/no-app)
- python - BeautifulSoup 和 MechanicalSoup 不会读取网站
- salesforce - 如何部署(启动)SFDX 项目
- python - 与此 Python 函数等效的 JaxNumpy 兼容是什么?
- node.js - Netlify 函数中奇怪的 cookie 行为
- apache-kafka - 选择正确的 KafkaUser 身份验证类型?
- c# - 使用 Powershell Core 进行多线程在线交换 - C#
- java - 我的反转方法没有反转任何东西?
- ruby-on-rails - 使用acts_as_list 扩展ActiveStorage::Attachment 时遇到问题
- python - 将电话号码添加到用户资料注册的 DJANGO 表单