【问题标题】:Why WooCommerce product get_description does not get content generated by shortcode为什么 WooCommerce 产品 get_description 无法获取短代码生成的内容
【发布时间】:2020-01-31 08:34:02
【问题描述】:

我正在阅读 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 生成的架构中显示为“描述”?

【问题讨论】:

    标签: php wordpress woocommerce schema product


    【解决方案1】:

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

    我在 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;
        }
    }
    

    【讨论】:

      猜你喜欢
      • 2021-10-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-10-21
      • 2018-08-14
      • 1970-01-01
      • 2016-09-05
      • 1970-01-01
      相关资源
      最近更新 更多