admin管理员组文章数量:1122846
i am finding how to change the value from _stock_status on single product. I have display the product stock status by that code:
<?php echo get_post_meta( get_the_ID(), '_stock_status', true ); ?>
but '_stock_status' return the value: "outofstock". I want to change this value to other name
Please help me to solve this. Thank you in advance
i am finding how to change the value from _stock_status on single product. I have display the product stock status by that code:
<?php echo get_post_meta( get_the_ID(), '_stock_status', true ); ?>
but '_stock_status' return the value: "outofstock". I want to change this value to other name
Please help me to solve this. Thank you in advance
Share Improve this question asked Jan 19, 2019 at 8:01 mrleezoomrleezoo 111 silver badge2 bronze badges2 Answers
Reset to default 0You can use the code update_post_meta( get_the_ID(), '_stock_status',$value)
to change the value of the meta. Please place the above line in the code where you want to change the status value and remember $value is the variable/array/object you can place any string/array/object in it.
IMO, It'd be best to create a helper function which returns your changed/translated text.
function wpse326063_stock_texts( $product_id ) {
$status = get_post_meta( $product_id, '_stock_status', true );
//Out of Stock Message
if ( $status == 'outofstock' ) {
$status = 'This Product is Out of Stock';
}
//You can add your conditionals to change other texts.
return $status;
}
Now you can use it like this..
<?php echo wpse326063_stock_texts( get_the_ID() );?>
本文标签: woocommerce offtopichow to change value return by stockstatus
版权声明:本文标题:woocommerce offtopic - how to change value return by _stock_status 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736291058a1928643.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论