gpt4 book ai didi

wordpress - Woocommerce:更改 "# in stock"文本

转载 作者:行者123 更新时间:2023-12-04 18:22:42 25 4
gpt4 key购买 nike

我需要将“ # in stock ”文本更改为“ # Deals left ”。

我将以下代码添加到 function.php 文件中,但这会删除实际数字。

add_filter( 'woocommerce_get_availability', 'custom_get_availability', 1, 2);

function custom_get_availability( $availability, $_product ) {
//change text "In Stock' to 'SPECIAL ORDER'
if ( $_product->is_in_stock() ) $availability['availability'] = __('SPOTS LEFT', 'woocommerce');

//change text "Out of Stock' to 'SOLD OUT'
if ( !$_product->is_in_stock() ) $availability['availability'] = __('SOLD OUT', 'woocommerce');
return $availability;
}

有人可以帮忙吗?

最佳答案

你可以试试下面的代码:

add_filter( 'woocommerce_get_availability', 'custom_get_availability', 1, 2);

function custom_get_availability( $availability, $_product ) {
global $product;
$stock = $product->get_total_stock();

if ( $_product->is_in_stock() ) $availability['availability'] = __($stock . ' SPOTS LEFT', 'woocommerce');
if ( !$_product->is_in_stock() ) $availability['availability'] = __('SOLD OUT', 'woocommerce');

return $availability;
}

关于wordpress - Woocommerce:更改 "# in stock"文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23064185/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com