第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

在 WooCommerce 產(chǎn)品上顯示自定義前綴以及每米價(jià)格

在 WooCommerce 產(chǎn)品上顯示自定義前綴以及每米價(jià)格

PHP
慕森王 2023-08-26 17:51:05
我使用此代碼在我的產(chǎn)品價(jià)格下方添加文本function cw_change_product_price_display( $price ) {    $price .= ' <span class="unidad">por unidad</span>';    return $price;}add_filter( 'woocommerce_get_price_html', 'cw_change_product_price_display' );add_filter( 'woocommerce_cart_item_price', 'cw_change_product_price_display' );但我需要顯示以下文本: 每米價(jià)格為: 以及此公式:$product->get_price()/$product->get_length() . get_woocommerce_currency_symbol();產(chǎn)品價(jià)格除以產(chǎn)品長(zhǎng)度,無(wú)法在不導(dǎo)致網(wǎng)站錯(cuò)誤的情況下使其正常工作。另外,有什么方法可以使此代碼僅適用于某些產(chǎn)品嗎?因?yàn)橛泻芏鄦挝怀鍪?
查看完整描述

1 回答

?
倚天杖

TA貢獻(xiàn)1828條經(jīng)驗(yàn) 獲得超3個(gè)贊

您可以將其用于簡(jiǎn)單的產(chǎn)品:


add_filter( 'woocommerce_get_price_html', 'custom_product_price_display', 10, 2 );

add_filter( 'woocommerce_cart_item_price', 'custom_product_price_display', 10, 2 );

function custom_product_price_display( $price, $product ) {

    if( ! is_a( $product, 'WC_Product' ) ) {

        $product = $product['data'];

    }

    

    // Price per meter prefixed

    if( $product->is_type('simple') && $product->get_length() ) {

        $unit_price_html = wc_price( $product->get_price() / $product->get_length() );

        $price .= ' <span class="per-meter">' . __("Price per meter is: ") . $unit_price_html . '</span>';

    } 

    return $price;

}

代碼位于活動(dòng)子主題(或活動(dòng)主題)的functions.php 文件中。經(jīng)過(guò)測(cè)試并有效。


要處理“每米顯示的價(jià)格”和“每單位”前綴,請(qǐng)改用以下內(nèi)容:


add_filter( 'woocommerce_get_price_html', 'custom_product_price_display', 10, 2 );

add_filter( 'woocommerce_cart_item_price', 'custom_product_price_display', 10, 2 );

function custom_product_price_display( $price, $product ) {

    if( ! is_a( $product, 'WC_Product' ) ) {

        $product = $product['data'];

    }

    

    // Price per meter prefixed

    if( $product->is_type('simple') && $product->get_length() ) {

        $unit_price_html = wc_price( $product->get_price() / $product->get_length() );

        $price .= ' <span class="per-meter">' . __("Price per meter is: ") . $unit_price_html . '</span>';

    } 

    // Prefix" per unit"

    else {

        $price .= ' <span class="per-unit">' . __("per unit") . $unit_price_html . '</span>';

    }

    return $price;

}


查看完整回答
反對(duì) 回復(fù) 2023-08-26
  • 1 回答
  • 0 關(guān)注
  • 134 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)