Skip to content

Instantly share code, notes, and snippets.

View ludekcerny's full-sized avatar

Ludek Cerny ludekcerny

View GitHub Profile
@Lonsdale201
Lonsdale201 / code
Last active November 4, 2024 15:18
JetFromBuilder - Call hook - Woo product Stock modification (like preorder)
// place the code in the child theme functions.php or a custom code snippets plugin, like FluentSnippets
// What do this code
// What this Call hook does is to extract the product identifier from the field that is filled,
// and the order quantity from the quantity field. It checks when the form is submitted
// if there is enough of the product in stock, if so, it subtracts the quantity when the form is submitted.
// If there is not enough, an error is generated and the stock of the product is not changed.
// This code does not require the JFB Add to cart add-on. The hook does not go through the checkout process,
// it only adjusts the stock of the product based on the quantity of the order the user has submitted.