簡體   English   中英

更改WooCommerce缺貨徽章文字

[英]Changing WooCommerce out of stock badge text

我們在Wordpress和Woo Commerce上使用鄰居主題,以便出售一次性的獨特商品。 庫存管理在確保銷售的產品無法再次購買方面表現良好,而不是將商品顯示為缺貨。 這在原則上是好的,事實上,“庫存”的項目說明價格下轉向“缺貨”的顯示器的工作原理沒有問題,我們甚至發現代碼,如果有必要改變這種狀況顯示在這里 這很好 - 將以下代碼添加到主題中的functions.php:

add_filter('woocommerce_stock_html', 'change_stock_message', 10, 2);
function change_stock_message($message, $stock_status) {
    if ($stock_status == "Out of stock") {
        $message = '<p class="stock out-of-stock">Sold</p>';    
    } else {
        $message = '<p class="stock in-stock">Available</p>';           
    }
    return $message;
}

但是,我們真正想要做的是更改圖像中出現的缺貨徽章中的文本,例如http://neighborhood.swiftideas.net/product/common-projects-achilles/

在此輸入圖像描述

更改CSS是沒有問題的,因此文本字體,背景,大小等很容易被更改添加到custom-css:

.out-of-stock-badge {
    background: red;
    font-size: 12px;
}

如何將缺貨徽章文本從“缺貨”更改為“已售出”?

2019年3月你需要的代碼片段在一個名為wc-product-loop-outofstock-flash.php的文件中(在我看來是w​​p-content / Themes / Avada / woocommerce)

<?php if ( ! $product->is_in_stock() ) : ?>
    <div class="fusion-out-of-stock">
        <div class="fusion-position-text">
        <?php esc_attr_e( 'Fully Booked', 'Avada' ); ?>
        </div>
     </div>
<?php
endif;

這里查看結果但我不能保證它們將在2019年5月之后出現。完全預訂的項目位於頁面底部

我不知道你正在使用的主題。 但我認為以下代碼可能會解決您的問題 -

add_filter('woocommerce_sale_flash', 'woocommerce_sale_flashmessage', 10, 2);
function woocommerce_sale_flashmessage($flash){
    global $product;
    $availability = $product->get_availability();

    if ($availability['availability'] == 'Out of stock') :
        $flash = '<span class="out-of-stock-badge">'.__( 'SOLD', 'woocommerce' ).'</span>';

    endif;
    return $flash;
}

在主題的functions.php文件中添加它。

按照@ maksbd19的建議,我發現需要在themes文件夾內的woocommerce文件夾中進行編輯的twofiles(在本例中為鄰居)。 這些是content-product.php和single-product \\ product-image.php。 在這兩種情況下,我將以下行從“Out of Stock”更改為“Sold”,如下所示:

...} else if (is_out_of_stock()) {
    echo '<span class="out-of-stock-badge">' . __( 'Sold', 'swiftframework' ) . '</span>';
} else if (!$product->get_price()) {...

希望能幫助別人。

您可以使用子主題header.php文件中的代碼

創建子主題 - https://codex.wordpress.org/Child_Themes

jQuery( document ).ready(function() {
    jQuery(".onsale.oos").text(function () {
        return jQuery(this).text().replace("Out of stock", "SOLD"); 
    });
});

暫無
暫無

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

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