亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

去除產品元數據中的 HTML

去除產品元數據中的 HTML

PHP
慕俠2389804 2022-12-03 11:06:34
我為 Woo store 創建了一個功能來顯示自定義分類法。不知何故,我的每一個 span 容器都被破壞了。這是代碼:add_action( 'woocommerce_product_meta_start', 'add_my_meta', 1 );function add_my_meta() {    $series = the_terms($post->ID, 'series');    if ($series) {        $meta_output = '<span style="display:block;">Series: ';        $meta_array = array();        foreach ($series as $serie) {            $meta_array[] = '<a href="' . get_term_link( $serie->slug, 'series') .'">' . $serie->name . '</a>';        }        $meta_output .= join( ', ', $meta_array ) . '</span>';    }    return $meta_output;}所以預期的輸出是<span style="display:block;">Series: <a href="https://example.com/series/myseries/" rel="tag">My Series</a></span>當前輸出是<a href="https://example.com/series/myseries/" rel="tag">My Series</a>跨度和文本已刪除。以前從未遇到過這個問題,問題是什么以及如何解決?
查看完整描述

1 回答

?
翻過高山走不出你

TA貢獻1875條經驗 獲得超3個贊

發現了一些錯誤——需要使用 get_the_terms(是 the_terms)和 $serie->term_id(是 $serie->slug)


add_action( 'woocommerce_product_meta_start', 'add_my_meta', 1 );

function add_my_meta() {

    $series = get_the_terms($post->ID, 'series');

    if ( is_array($series) ) {

        $meta_array = array();

        foreach ($series as $serie) {

            $meta_array[] = '<a href="' . get_term_link( $serie->term_id, 'series') .'">' . $serie->name . '</a>';

        }

        echo '<span class="tagged_as">Series: ' . implode( ', ', $meta_array ) . '</span>';

    }

}


查看完整回答
反對 回復 2022-12-03
  • 1 回答
  • 0 關注
  • 87 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號