| Server IP : 69.72.244.102 / Your IP : 216.73.216.164 Web Server : LiteSpeed System : Linux s3434.fra1.stableserver.net 4.18.0-513.24.1.lve.2.el8.x86_64 #1 SMP Fri May 24 12:42:50 UTC 2024 x86_64 User : konzalta ( 1271) PHP Version : 7.4.33 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : OFF | Pkexec : OFF Directory : /home/konzalta/www/wp-content/plugins/dynamic-pricing/ |
Upload File : |
<?php
/**
* Plugin Name: Dynamic Pricing for Services
* Description: Adjusts the price based on the number of people.
* Version: 1.0
* Author: Your Name
*/
// Hook into WooCommerce to adjust the price
add_action('woocommerce_before_calculate_totals', 'dynamic_pricing_adjust_price');
function dynamic_pricing_adjust_price($cart) {
// Check if cart is empty
if (is_admin() && !defined('DOING_AJAX')) return;
// Loop through cart items
foreach ($cart->get_cart() as $cart_item_key => $cart_item) {
$product_id = $cart_item['product_id'];
// Check if the product is the one with dynamic pricing
if ($product_id == 1620) {
$quantity = $cart_item['quantity'];
// Calculate the new price
$base_price = 150;
$additional_price_per_person = 50;
$total_price = $base_price + ($quantity - 2) * $additional_price_per_person;
// Set the new price
//$cart_item['data']->set_price($total_price / $quantity);
// Adjust subtotal to match the total price
$cart_item['line_subtotal'] = $total_price;
$cart_item['line_subtotal_tax'] = 0; // Reset taxes if needed
}
}
}