首页 > 解决方案 > 在 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
}

感谢我能得到的所有帮助。

标签: woocommerce

解决方案


您可以使用此功能来显示您的自定义选项内容:

add_action( 'woocommerce_single_product_summary', 'display_psm_meta', 5 );
function display_psm_meta() {
    echo get_option( 'psm_content' );
}

推荐阅读