【问题标题】:Add short description under the product title in WooCommerce archive pages在 WooCommerce 存档页面的产品标题下添加简短描述
【发布时间】:2021-07-12 13:03:18
【问题描述】:

我的网站是https://outlet.ltd/deals。我尝试通过以下链接将 WooCommerce 产品的简短描述添加到实现页面网格(在产品标题下),但没有成功。什么都没有显示。

我正在使用REHub theme。有人可以帮忙吗?

【问题讨论】:

    标签: wordpress woocommerce wordpress-theming


    【解决方案1】:

    你可以用 woocommerce_after_shop_loop_item_title 钩子来实现

    add_action('woocommerce_after_shop_loop_item_title','my_product_description');
    
    function my_product_description() {
    
    // get the global product obj
    
        global $product;
    
    // get the global product obj
    
     $description = $product->get_short_description();
    
    echo $description;
    
    }
    

    【讨论】:

    • 谢谢。我应该将它添加到 funtions.php 中,对吧?
    【解决方案2】:

    将此代码添加到您的主题functions.php 文件中。

    // define the woocommerce_after_shop_loop_item_title callback 
    function action_woocommerce_after_shop_loop_item_title(  ) { 
        global $product;
        if( is_shop() ):
            echo $product->get_short_description();
        endif;
    }; 
             
    // add the action 
    add_action( 'woocommerce_after_shop_loop_item_title', 'action_woocommerce_after_shop_loop_item_title', 5 );
    

    它对我有用。

    【讨论】:

    • 致命错误:无法重新声明 action_woocommerce_after_shop_loop_item_title()(之前在 /home/outlet.ltd/public_html/wp-content/plugins/code-sn-ps/php/sn-p-ops.php 中声明(469) : eval()'d code:3) in /home/outlet.ltd/public_html/wp-content/themes/rehub-theme/functions.php 1797 行
    • 您需要将动作函数名称action_woocommerce_after_shop_loop_item_title更改为my_action_woocommerce_after_shop_loop_item_title。所以代码将是这样的: function my_action_woocommerce_after_shop_loop_item_title( ) { global $product; if( is_shop() ): echo $product->get_short_description();万一; }; add_action('woocommerce_after_shop_loop_item_title', 'my_action_woocommerce_after_shop_loop_item_title', 5);
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-08-11
    • 2018-08-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-06-08
    相关资源
    最近更新 更多