在WooCommerce变量产品选择器中更改库存状态名称? [英] Change stock status names in WooCommerce variable products selector?

查看:136
本文介绍了在WooCommerce变量产品选择器中更改库存状态名称?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有此代码:

$stock_status = $variation_obj->get_stock_status();
$stock_qty = $variation_obj->get_stock_quantity();
if( $stock_qty>0 )
    return $term_name .= ' - ' . $stock_status . ' ('.$stock_qty.')';
else
    return $term_name .= ' - ' . $stock_status;

}

我用它来显示变化库存状态,例如有库存"或无库存".目前,我的功能的这一部分有效,但是以这种方式显示库存状态:

I use it to show the variation stock status like "In Stock" or "Out of Stock". Currently this part of my function works, but show the stock status is this way:

因此,我想问一个人如何显示库存"而不是下图所示的库存".
我尝试使用一些功能来自定义库存状态,但看起来没有任何作用.

So I want to ask someone how to show "In Stock" instead of "instock" as is shown in image under.
I tryed to use some functions for custom stock status, but looks like dont have any effect.

请帮忙吗?

谢谢.

推荐答案

您可以简单地使用 str_replace()这样的PHP函数:

You can do it simply using str_replace() PHP function this way:

$stock_status = $variation_obj->get_stock_status();

// Here we change both $stock_status names to human readable strings:
$stock_status = str_replace( array('instock','outofstock'), array('In Stock','Out of Stock'), $stock_status );

$stock_qty = $variation_obj->get_stock_quantity();

if( $stock_qty>0 )
    return $term_name .= ' - ' . $stock_status . ' ('.$stock_qty.')';
else
    return $term_name .= ' - ' . $stock_status;

}

这篇关于在WooCommerce变量产品选择器中更改库存状态名称?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆