Adding custom attribute to WooCommerce shop loop product title

…衆ロ難τιáo~ 提交于 2019-12-02 09:14:26

Calling get_attribute() directly will throw an error like

Call to undefined function get_attribute()

So use it in this way

add_action('woocommerce_shop_loop_item_title', 'wh_insertAfterShopProductTitle', 15);

function wh_insertAfterShopProductTitle()
{
    global $product;

    $abv = $product->get_attribute('pa_alcohol-by-volume');
    if (empty($abv))
        return;
    echo __($abv, 'woocommerce');
}

Code goes in functions.php file of your active child theme (or theme). Or also in any plugin php files.
Code is tested and works.

Hope this helps!

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!