繁体   English   中英

为什么WooCommerce产品get_description没有得到简码生成的内容

[英]Why WooCommerce product get_description does not get content generated by shortcode

我正在阅读class-wc-structured-data,它是WooCommerce插件中生成产品模式的关键文件。 我想知道为什么通过将简码(标签内容)插入 WooCommerce 文本编辑器(产品的完整描述)生成的内容无法通过此代码进行重新定义:

'description' => wp_strip_all_tags( do_shortcode( $product->get_short_description() ? $product->get_short_description() : $product->get_description() ) )

从文件中提取的完整内容是:

$markup = array(
            '@type'       => 'Product',
            '@id'         => $permalink . '#product', // Append '#product' to differentiate between this @id and the @id generated for the Breadcrumblist.
            'name'        => $product->get_name(),
            'url'         => $permalink,
            'image'       => wp_get_attachment_url( $product->get_image_id() ),
            'description' => wp_strip_all_tags( do_shortcode( $product->get_short_description() ? $product->get_short_description() : $product->get_description() ) ),
        );

是否有任何解决方案可以使插入 WooCommerce 文本编辑器中的短代码内容在 WooCommerce 生成的架构中显示为“描述”?

我有一个类似的问题,我的目标是将描述从“选项卡”部分移动到不同的钩子。 所以,我禁用了“选项卡”部分,然后我添加了一个自定义操作来仅显示描述。 可悲的是,短代码没有呈现。

我在 Woocommerce 文档中找到了这个提示: https://docs.woocommerce.com/document/allow-shortcodes-in-product-excerpts/

这同样适用于描述,所以我修改了我的代码,添加了他们描述的函数:do_shortcode(wpautop(wptexturize($product->get_description())))。

我的最终代码如下,希望对您有所帮助。

// Remove all tabs
add_filter( 'woocommerce_product_tabs', 'zod_remove_product_tabs', 98 );
function zod_remove_product_tabs( $tabs ) {
    unset( $tabs['description'] );          // Remove the description tab
    unset( $tabs['reviews'] );          // Remove the reviews tab
    unset( $tabs['additional_information'] );   // Remove the additional information tab
    return $tabs;
}
// Add description in the hook after summary 
add_action( 'woocommerce_after_single_product_summary', 'zod_product_full_description' );
function zod_product_full_description () {
    if(is_product()) {
    $product = wc_get_product( get_the_ID() );
    $description = do_shortcode(wpautop(wptexturize($product->get_description())));
    echo $description;
    }
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM