简体   繁体   English

更改WooCommerce缺货徽章文字

[英]Changing WooCommerce out of stock badge text

We are using the Neighborhood theme on Wordpress and Woo Commerce in order to sell one-off, unique items. 我们在Wordpress和Woo Commerce上使用邻居主题,以便出售一次性的独特商品。 Stock management works well in terms of ensuring that products sold cannot be purchased again displaying the item as out of stock instead. 库存管理在确保销售的产品无法再次购买方面表现良好,而不是将商品显示为缺货。 This in principle is fine and indeed, the display of "In stock" turning to "Out of stock" under the price on the item description works no problem and we have even found code to change that display if necessary here . 这在原则上是好的,事实上,“库存”的项目说明价格下转向“缺货”的显示器的工作原理没有问题,我们甚至发现代码,如果有必要改变这种状况显示在这里 This works fine - adding the following code to the functions.php in the theme: 这很好 - 将以下代码添加到主题中的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;
}

However, what we really want to do is change the text in the out of stock badge that appears across the image eg http://neighborhood.swiftideas.net/product/common-projects-achilles/ . 但是,我们真正想要做的是更改图像中出现的缺货徽章中的文本,例如http://neighborhood.swiftideas.net/product/common-projects-achilles/

在此输入图像描述

Changing the CSS is no problem so the text font, background, size etc. is easily altered adding something like this to the custom-css: 更改CSS是没有问题的,因此文本字体,背景,大小等很容易被更改添加到custom-css:

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

How to change the out-of-stock-badge text from "Out of stock" to "SOLD"? 如何将缺货徽章文本从“缺货”更改为“已售出”?

March 2019 The snippet you need is in a file called wc-product-loop-outofstock-flash.php in (in my case wp-content/Themes/Avada/woocommerce ) 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;

Check out the results here but I cannot guarantee they will be around after May 2019 Fully booked items are at the bottom of the page 这里查看结果但我不能保证它们将在2019年5月之后出现。完全预订的项目位于页面底部

I don't know about the theme your are using. 我不知道你正在使用的主题。 But I think that the following code might solve your problem- 但我认为以下代码可能会解决您的问题 -

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;
}

Add this in your theme's functions.php file. 在主题的functions.php文件中添加它。

Following @maksbd19 suggestion I found twofiles that required editing within the woocommerce folder inside the themes folder (in this case neighborhood). 按照@ maksbd19的建议,我发现需要在themes文件夹内的woocommerce文件夹中进行编辑的twofiles(在本例中为邻居)。 These are content-product.php and single-product\\product-image.php. 这些是content-product.php和single-product \\ product-image.php。 In both cases, I change the following line from 'Out of Stock' to 'Sold' as follows: 在这两种情况下,我将以下行从“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()) {...

Hope that helps someone. 希望能帮助别人。

You can use the code in your child themes header.php file 您可以使用子主题header.php文件中的代码

To create child theme - https://codex.wordpress.org/Child_Themes 创建子主题 - 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.

相关问题 在Woocommerce存档页面中将“销售”徽章替换为“缺货” - Replace “Sale” badge by “Out of Stock” in Woocommerce archive pages 用 WooCommerce 中的按钮替换缺货文本 - Replace Out of stock text with a button in WooCommerce 在 WooCommerce 中产品缺货时更改单个添加到购物车文本 - Change single add to cart text when product is out of stock in WooCommerce 将显示的价格替换为缺货 WooCommerce 产品的文本 - Replace displayed price by a text for out of stock WooCommerce products WooCommerce 自定义缺货文本 + 特定产品 ID - WooCommerce custom out of stock text + specific product id 根据 WooCommerce 中的产品类别自定义“缺货”文本 - Custom “Out of stock” text based on product category in WooCommerce 更改WooCommerce上的“有货”文本 - Change “in stock” text on WooCommerce 如何在 Woocommerce 缺货产品文本下方添加单个产品的 Woocommerce 产品价格 - How can I add below of Woocommerce out of stock product text the Woocommerce product price on a single product WooCommerce 产品在实际没有缺货时显示“缺货”消息 - WooCommerce products showing “Out of stock” message when not actually out of stock 如果 WooCommerce 中的一个变体缺货,则将所有变体设置为缺货 - Set all variations out of stock if one variation is out of stock in WooCommerce
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM