Title: Plugin customization
Last modified: July 27, 2024

---

# Plugin customization

 *  Resolved [lanrantor](https://wordpress.org/support/users/lanrantor/)
 * (@lanrantor)
 * [1 year, 10 months ago](https://wordpress.org/support/topic/plugin-customization-34/)
 * Hi, Andrew,
 * I tested the Stock Level Pricing plugin today, just want to know if you could
   be able to customize it as per the following rule?
    1. When the product stock quantity is greater than “0,” the price will be the standard
       regular price as set by WooCommerce.
    2. When the product stock quantity equals “0,” the price will be adjusted according
       to the following formula: price = [regular price + 50 (input)] + [regular price*
       35% (input)] + 20 (input). For example, if the regular price is USD 100, the
       new price will be USD 205 (USD 205 = USD 100 + USD 35 + USD 20) when the stock
       quantity reaches “0.” Once the stock quantity is greater than “0,” the price
       will revert to the regular price.
    3. Please do not display these pricing rules on the product page.
 * Regards
 * Gerry

Viewing 2 replies - 1 through 2 (of 2 total)

 *  Plugin Author [Andrew](https://wordpress.org/support/users/krandrew/)
 * (@krandrew)
 * [1 year, 10 months ago](https://wordpress.org/support/topic/plugin-customization-34/#post-17924119)
 * Hi Gerry,
 * I don’t think that any plugin is capable of handling your specific case, including
   Stock Level Pricing. It would be much easier to simply write a function that 
   will change the price for all products with a stock level of 0, rather than trying
   to adjust the Stock Level Pricing plugin, as this goes against the core logic
   of the plugin.
 * Here is a simple function that you can put inside your functions.php file to 
   recalculate the price of all products with a stock level of 0:
 *     ```wp-block-code
       // Add the function to adjust product price based on 0 stock levelfunction custom_adjust_price_based_on_stock($price, $product) {    // Get the regular price of the product    $regular_price = $product->get_regular_price();    // Get the stock quantity of the product    $stock_quantity = $product->get_stock_quantity();    // Check if the stock quantity is 0    if ($stock_quantity === 0) {        // Calculate the new price based on the given formula        $adjusted_price = $regular_price + 50 + ($regular_price * 0.35) + 20;        return $adjusted_price;    }    // If stock quantity is greater than 0, return the regular price    return $regular_price;}// Hook into WooCommerce to apply the custom price adjustmentadd_filter('woocommerce_product_get_price', 'custom_adjust_price_based_on_stock', 10, 2);add_filter('woocommerce_product_variation_get_price', 'custom_adjust_price_based_on_stock', 10, 2);// Ensure the custom price adjustment is applied to product variations as welladd_filter('woocommerce_variation_prices_price', 'custom_adjust_price_based_on_stock', 10, 2);add_filter('woocommerce_variation_prices_regular_price', 'custom_adjust_price_based_on_stock', 10, 2);
       ```
   
 * Of course, it’s pretty basic, but it does the job. It would get a bit more complicated
   if you want to consider the sale price as well, or make it compatible with other
   plugins that may adjust the price (other than simply retrieving the regular price
   and making calculations).
 *  Thread Starter [lanrantor](https://wordpress.org/support/users/lanrantor/)
 * (@lanrantor)
 * [1 year, 10 months ago](https://wordpress.org/support/topic/plugin-customization-34/#post-17925625)
 * Hi, Andrew,
 * Much appreciated your reply.
 * The function you suggested greatly helped to solve my problem, (FYI. I added (“
   $stock_quantity === null”) after($stock_quantity === 0).
 * Regards
 * Gerry

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘Plugin customization’ is closed to new replies.

 * ![](https://ps.w.org/stock-level-pricing/assets/icon-256x256.png?rev=3038435)
 * [Stock Level Pricing](https://wordpress.org/plugins/stock-level-pricing/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/stock-level-pricing/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/stock-level-pricing/)
 * [Active Topics](https://wordpress.org/support/plugin/stock-level-pricing/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/stock-level-pricing/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/stock-level-pricing/reviews/)

 * 2 replies
 * 2 participants
 * Last reply from: [lanrantor](https://wordpress.org/support/users/lanrantor/)
 * Last activity: [1 year, 10 months ago](https://wordpress.org/support/topic/plugin-customization-34/#post-17925625)
 * Status: resolved