Skip Navigation

[Resolved] Use of _stock – manage format

This thread is resolved. Here is a description of the problem and solution.

Problem:
Use of _stock - manage format

Solution:
To format that _stock field you as per your requirement you need to create custom shortcode.

You can find the proposed solution in this case with the following reply:
https://toolset.com/forums/topic/use-of-_stock-manage-format/#post-1339603

Relevant Documentation:
=> https://toolset.com/documentation/adding-custom-code/using-toolset-to-add-custom-code/

This support ticket is created 5 years, 1 month ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Kolkata (GMT+05:30)

Tagged: 

This topic contains 2 replies, has 2 voices.

Last updated by Pat 5 years, 1 month ago.

Assisted by: Minesh.

Author
Posts
#1339577

Pat

Hello,

I'm using Toolset and WC and have declared _stock as a field to be used with Views. The issue is that the format of this field is like 15.0000000 and I want only 15
Is there a way to manage the format of this field?

Regards
Pat

#1339603

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Can you please try to add the following code to your current theme's functions.php file:
Or
Add it to "Custom Code" section offered by Toolset:
=> https://toolset.com/documentation/adding-custom-code/using-toolset-to-add-custom-code/

function func_format_stock($atts, $content = "") {
 
$x = number_format(wpv_do_shortcode($content),2, '.', ',');
if($atts['type']=='stock') {
     $val = explode(".",$x);
     return  $val[0];
} 
}
add_shortcode('format_num', 'func_format_stock');

To display quantity:

[format_num type='stock'] [wpv-post-field name="_stock"] [/format_num]
#1339609

Pat

Super Minesh !
Thanks you
Pat