Skip Navigation

[Resolved] Change stock level formatting

This support ticket is created 5 years, 3 months 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
- 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 -
- 13:00 – 18:00 13:00 – 18:00 13:00 – 18:00 14:00 – 18:00 13:00 – 18:00 -

Supporter timezone: America/Jamaica (GMT-05:00)

Tagged: 

This topic contains 3 replies, has 3 voices.

Last updated by Shane 5 years, 3 months ago.

Assisted by: Shane.

Author
Posts
#1354791

I have the stock level displayed on my site as per this support ticket: https://toolset.com/forums/topic/unable-to-display-stock-quantity/

However, the stock level is showing up as 13.000000 - how can I amend the shortcode to only show 13. (Shortcode: [wpv-post-field name='_stock'] )

Kind Regards,
Orla

#1354847

_stock will return you the stock you have of the product as saved by WooCommerce.
Do you have 13k of the product in stock?

If so the display is correct. You cannot alter that - but you could write a custom ShortCode that somehow alters the value of stock to a less long cypher.
But Toolset cannot help with this, it requires custom coding.

#1354981

No there were 13 in stock. The formatting was showing 13.00000

Now I am having a bigger issue but I will post in a separate support request as it is complicated.

#1355091

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Orla,

Perhaps you can try this below.

// Add Shortcode
function wp_cust_round( $atts ) {

	// Attributes
	$atts = shortcode_atts(
		array(
			'num' => '',
		),
		$atts
	);

	return round($atts['num']);

}
add_shortcode( 'wp_cust_round', 'wp_cust_round' );

I wrote this custom code to round your number to the nearest whole number.
Usage is [wp_cust_round num="[wpv-post-field name='_stock']"]

Add the custom shortcode to your toolset custom code settings in Toolset -> Settings -> Custom Coding and activate it.

Please let me know if this helps.

Thanks,
Shane