簡體   English   中英

Woocommerce 店鋪頁面價格后加“庫存”

[英]Woocommerce adding "stock" after price in shop page

嘿,我需要在我的商店頁面上的價格后添加“有貨”文本。 屏幕

我找到了這段代碼

add_filter( 'woocommerce_get_price_html', 'prepend_append_icon_to_price', 10, 2 );
function prepend_append_icon_to_price( $price, $product ) {

    if( has_term( 'fast-shipping', 'product_cat', $product->get_id() ) && ! is_product() ){
        $price .= '<span style="float:right"><i class="fas fa-shipping-fast"></i></span> ';
    }
    return $price;
}

我有這段代碼

function envy_stock_catalog() {
    global $product;
    if ( $product->is_in_stock() ) {
        echo '<div class="stock" >' . $product->get_stock_quantity() . __( ' in stock', 'envy' ) . '</div>';
    } else {
        echo '<div class="out-of-stock" >' . __( 'out of stock', 'envy' ) . '</div>';
    }
}
add_action( 'woocommerce_after_shop_loop_item_title', 'envy_stock_catalog' );

現在我需要結合這些代碼,你能幫我嗎? 請:)

你可以做這樣的事情來滿足你的要求。 您可以將此代碼放在您的函數中。php。

if(is_shop){
remove_action( 'woocommerce_after_shop_loop_item_title', 'woocommerce_template_loop_price', 10 ); // remove previous price from shop
}
add_action('woocommerce_after_shop_loop_item_title','faastechies_solution');
function faastechies_solution(){
if(is_shop){    
global $product;
// Add your template here according to your further requirement. Just add classes and ids and use this css in your custom css or custom css file. 
 ?>
<span style="color:black; font-size: 16px font-weight: bold"> Price: <p 
style="display: inline; font-size: 16px; color: red; font-weight: 600"> 
    <? echo $product->get_regular_price();?>
    </p> Status: <p style="display: inline; font-size: 16px; color: red; font-weight: 
    600">
     <? echo $product->get_stock_status();;?>
     </p></span>
     <? 
     }}

好的,謝謝@fasstechies 我編輯了代碼,現在它可以工作了:)謝謝。

remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_price', 10 );
remove_action( 'woocommerce_after_shop_loop_item_title', 'woocommerce_template_loop_price', 10 );
add_action('woocommerce_after_shop_loop_item_title','faastechies_solution');
function faastechies_solution(){
if (is_shop()){
global $product;
// Add your template here according to your further requirement. Just add classes and ids and use this css in your custom css or custom css file. 
 ?>
<span style="color:black; font-size: 16px font-weight: bold"> Price: <p 
style="display: inline; font-size: 16px; color: red; font-weight: 600"> 
    <? echo $product->get_regular_price();?>
    </p> Status: <p style="display: inline; font-size: 16px; color: red; font-weight: 
    600">
     <? echo $product->get_stock_status();;?>
     </p></span>
     <? 
     }}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM