AI Verified

Name

WooCommerce Stock Status Progress Bar for Variations

About

An expanded on version of ecommercehints.com's WooCommerce Stock Status Progress Bar This snippet inserts a progress bar on both single products and variable products' pages, allowing customers to track the availability of units in stock. By visually representing the remaining stock and the number of units already sold, it effectively conveys scarcity. This implementation of the Fear Of Missing Out (FOMO) tactic instills a sense of urgency, motivating potential buyers to make a purchase.

Language

PHP

Rating

Voted: 0 by 0 user(s)

How to Setup Snippet

To integrate the pre-coded solution, you can easily add it to your active child theme's functions.php file. Alternatively, it is recommended to utilize the Code Snippets Plugin for a more convenient implementation.

Codevault

Wyohost-

Scroll down to see more snippets from this codevault.

Wordpress Compatability

The author has indicated that this snippet is compatable up to wordpress version: 6.1

Our AI bot has checked this snippet is compatable up to wordpress version: 6.1

Code Snippet Plugin Sync

Free & Pro

Download this snippet by clicking the download button, then head over to the Code Snippet Plugin settings in your wordpress admin dashboard, select the import menu then upload this file to import into your wordpress site.

Pro Only (Coming Soon)

You will be able to click a button and sync this snippet to your wordpress site automatically and from your dashboard manage all code snippets across all your wordpress sites that have the Code Snippets Pro plugin installed.

Snippet Source:

https://ecommercehints.com/woocommerce-stock-status-progress-bar

History

Last modified:

26/05/2023

Important Note

This snippet has the following status:

AI Verified

This snippet has been tested by our AI bot, see any comments below.

AI Bot Comments:

Found 0 vulnerabilities

WooCommerce Stock Status Progress Bar for Variations

 
                    
1/**
2 * Snippet Name: WooCommerce Stock Status Progress Bar for Varianble Products
3 * Snippet Author: wyohost.com and ChatGPT
4 * Based on snippet by: https://ecommercehints.com's original snippet.
5 *
6 */
7 
8add_action( 'woocommerce_before_add_to_cart_form', 'ecommercehints_stock_status_progress_bar', 10, 0 );
9function ecommercehints_stock_status_progress_bar() {
10 global $product;
11 if (!$product->managing_stock()) return; // Don't show the progress bar if stock isn't being managed
12 
13 echo '<div id="stock_status_progress_bar"></div>'; // Placeholder for the progress bar
14 
15 ?>
16 <script type="text/javascript">
17 jQuery(document).ready(function($) {
18 // When a variation is selected
19 $('.variations_form').on('found_variation', function(event, variation) {
20 // Update the progress bar with the stock quantity of the selected variation
21 $('#stock_status_progress_bar').html('Only ' + variation.max_qty + ' Items remaining!<br><progress max="100" value="' + variation.max_qty + '"></progress>');
22 });
23 
24 // When resetting the variations
25 $('.variations_form').on('reset_data', function() {
26 $('#stock_status_progress_bar').html('');
27 });
28 });
29 </script>
30 <?php
31}

0

Related Snippets

Please see some snippets below related to this snippet..

WooCommerce

Unverified

0

CLOUD Meister: Checkout shipping inline

Added: 1 year ago

Last Updated: 1 year ago

WooCommerce

AI Verified

0

WooCommerce Remove Total Column In My Account Orders Table

Added: 1 year ago

Last Updated: 1 year ago

This snippet allows you to remove the ‘Total’ column from the table of orders shown in the users’ my account dashboard.

WooCommerce

AI Verified

0

Remove WooCommerce Checkout Fields

Added: 1 year ago

Last Updated: 1 year ago

This code removes certain checkout fields from a WooCommerce checkout page, including billing company, billing address, billing city, billing postcode, billing country, billing state, billing phone, a...

Other Snippets in this Codevault

These are some popular snippets from this users codevault..

WooCommerce

AI Verified

0

WooCommerce Stock Status Progress Bar for Variations

Added: 1 year ago

Last Updated: 1 year ago

An expanded on version of ecommercehints.com's WooCommerce Stock Status Progress Bar This snippet inserts a progress bar on both single products and variable products' pages, allowing customers t...