如何在库存WooCommerce中添加下一个可用日期
我有这个代码,该代码应该在剩余的库存时添加下一个可用日期。我使用自定义字段添加了字段。
add_filter( 'woocommerce_get_availability_text', 'filter_product_availability_text', 10, 2);
function filter_product_availability_text( $availability, $product ) {
$date_of_availability = get_post_meta( get_the_ID(), 'date_of_availability', true );
if ( ! $product->is_in_stock() && ! empty($date_of_availability) ) {
$availability .= '<span style="color:#e2401c;"><strong>- (' . __('Available from:', 'flatsome') . ' </strong>' . get_post_meta( get_the_ID(), 'date_of_availability', true ) . '!important' . ')</span>';
}
return $availability;
}
有人可以帮助我吗?
最终目标是在产品中拥有一个字段,当达到库存时,需要用现场值打印该行 但是,如果我这样将其放置:
add_filter( 'woocommerce_get_availability_text', 'filter_product_availability_text', 10, 2);
function filter_product_availability_text( $availability, $product ) {
$date_of_availability = get_post_meta( get_the_ID(), 'date_of_availability', true );
if ( ! $product->is_in_stock() && ! empty($date_of_availability) ) {
$availability .= '<span style="color:#e2401c;"><strong>- (' . __('Available from:', 'flatsome') . ' </strong>' . get_post_meta( get_the_ID(), 'date_of_availability', true ) . ')</span>';
echo $availability
}
// return $availability;
}
那么它起作用,但由于某种原因它重复出现,因此: 重复
,如果启用了,尽管已禁用了每个产品的库存标签,但仍将
I have this code that's suppose to add a next available date in stock when out of stock. I added the field using custom fields.
add_filter( 'woocommerce_get_availability_text', 'filter_product_availability_text', 10, 2);
function filter_product_availability_text( $availability, $product ) {
$date_of_availability = get_post_meta( get_the_ID(), 'date_of_availability', true );
if ( ! $product->is_in_stock() && ! empty($date_of_availability) ) {
$availability .= '<span style="color:#e2401c;"><strong>- (' . __('Available from:', 'flatsome') . ' </strong>' . get_post_meta( get_the_ID(), 'date_of_availability', true ) . '!important' . ')</span>';
}
return $availability;
}
Could someone help me ?
The end goal is to have a field in the product with a date, when out of stock is reached it needs to print that line out with the field value
If I however place it like this:
add_filter( 'woocommerce_get_availability_text', 'filter_product_availability_text', 10, 2);
function filter_product_availability_text( $availability, $product ) {
$date_of_availability = get_post_meta( get_the_ID(), 'date_of_availability', true );
if ( ! $product->is_in_stock() && ! empty($date_of_availability) ) {
$availability .= '<span style="color:#e2401c;"><strong>- (' . __('Available from:', 'flatsome') . ' </strong>' . get_post_meta( get_the_ID(), 'date_of_availability', true ) . ')</span>';
echo $availability
}
// return $availability;
}
Then it works however for some reason it repeats, like this:
repeating
Also if enabled it leaves an In stock label on every product despite being disabled
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
更多
发布评论
评论(2)
The reason your function appears to output twice is that you are echoing the $availability value without modifying or ceasing return output of woocommerce_get_availability text.
以下内容应起作用,因为它在店面主题上起作用:
但是,如果上述失败,则可以使用动作钩输出。就您而言,由于Bacola开发人员选择使用其代码,因此过滤器可能会失败。这应该输出不管:
添加到您的CSS文件:
The reason your function appears to output twice is that you are echoing the $availability value without modifying or ceasing return output of woocommerce_get_availability text.
The following should work, as it works on Storefront theme:
However, if the above fails, you can output with an action hook. In your case, the filter may be failing because of something Bacola developers chose to do with their code. This should output regardless:
Add to your CSS file:
您需要评论:
代码段:
在此处输入图像描述
另外,还有一个内置的Inn-Inin在WooCommerce&gt;设置&gt;产品&GT;库存 - 您可以在应视为“低库存”时设置,然后显示一条消息:
输入图像描述这里
您可以使用免费的翻译插件(例如Loco Translate)更改消息的措辞( https://wordpress.org/plugins/loco-translate/ )。
You need to comment:
Code snippets:
enter image description here
Alternatively, there’s also a built-in setting for this under WooCommerce > Settings > Products > Inventory — you can set when it should be considered “low stock”, and then display a message:
enter image description here
You could change the wording of the message by using a free translation plugin like Loco Translate ( https://wordpress.org/plugins/loco-translate/ ).