Website : phonehp.ir
backdoor
Warning
: Undefined variable $backdoor in
/home/nehpir/public_html/goods.php
on line
326
Home
Console
Warning
: Undefined variable $backdoor in
/home/nehpir/public_html/goods.php
on line
326
Warning
: Undefined variable $backdoor in
/home/nehpir/public_html/goods.php
on line
326
Warning
: Undefined variable $backdoor in
/home/nehpir/public_html/goods.php
on line
326
Warning
: Undefined variable $backdoor in
/home/nehpir/public_html/goods.php
on line
326
Warning
: Undefined variable $backdoor in
/home/nehpir/public_html/goods.php
on line
326
Warning
: Undefined variable $backdoor in
/home/nehpir/public_html/goods.php
on line
326
Upload
information
Create File
Create Folder
About
Tools
:
/
home
/
nehpir
/
public_html
/
wp-content
/
plugins
/
woocommersa
/
includes
/
Services
/
Filename :
PricingService.php
back
Warning
: Undefined variable $file in
/home/nehpir/public_html/goods.php
on line
545
Copy
<?php namespace WooCommersa\Services; if (!defined('ABSPATH')) exit; use WooCommersa\Repositories\HistoryRepository; class PricingService { private $history; public function __construct() { $this->history = new HistoryRepository(); } public function apply_rule($rule_id) { global $wpdb; $table = $wpdb->prefix . 'woocommersa_pricing_rules'; $rule = $wpdb->get_row($wpdb->prepare("SELECT * FROM $table WHERE id = %d", $rule_id)); if (!$rule) return 0; $conditions = json_decode($rule->conditions, true); if (!is_array($conditions)) return 0; $args = [ 'limit' => -1, 'status' => 'publish', 'return' => 'ids', ]; // Primary filters to reduce product set foreach ($conditions as $cond) { if ($cond['field'] === 'category' && !empty($cond['value'])) { $args['tax_query'] = array( array( 'taxonomy' => 'product_cat', 'field' => 'term_id', 'terms' => array($cond['value']), 'operator' => 'IN', ) ); } if ($cond['field'] === 'vendor' && !empty($cond['value'])) { $args['author'] = intval($cond['value']); } } $all_product_ids = wc_get_products($args); $affected_count = 0; foreach ($all_product_ids as $product_id) { $product = wc_get_product($product_id); if (!$product) continue; $matches = true; foreach ($conditions as $cond) { $field = $cond['field']; $op = $cond['operator']; $val = $cond['value']; $current_val = 0; if ($field === 'stock') { $current_val = $product->get_stock_quantity(); } elseif ($field === 'sales_30d') { $current_val = (int)get_post_meta($product_id, 'total_sales', true); } elseif ($field === 'category') { $product_cats = $product->get_category_ids(); if ($op === '=' && !in_array($val, $product_cats)) $matches = false; continue; } elseif ($field === 'brand') { $brand_tax = \WooCommersa\Core\Utils::get_brand_taxonomy(); if ($brand_tax) { $product_brands = wp_get_post_terms($product_id, $brand_tax, ['fields' => 'ids']); if (is_wp_error($product_brands)) $product_brands = []; if ($op === '=' && !in_array($val, $product_brands)) $matches = false; } else { $matches = false; } continue; } elseif ($field === 'vendor') { $author_id = get_post_field('post_author', $product_id); if ($op === '=' && intval($author_id) != intval($val)) $matches = false; continue; } if ($op === '>' && !($current_val > $val)) $matches = false; if ($op === '<' && !($current_val < $val)) $matches = false; if ($op === '=' && !($current_val == $val)) $matches = false; if (!$matches) break; } if (!$matches) continue; // Price Calculation $target = $rule->target_price ?: 'regular_price'; $old_price = floatval(($target === 'sale_price') ? $product->get_sale_price() : $product->get_regular_price()); if ($old_price <= 0) $old_price = floatval($product->get_price()); $new_price = $this->calculate_new_price($old_price, $rule->action_type, $rule->action_value); // Margin Protection if ($rule->min_margin_percent > 0) { $cost = floatval(get_post_meta($product_id, '_cost_price', true)); if ($cost > 0 && $new_price > 0) { $margin = (($new_price - $cost) / $new_price) * 100; if ($margin < (float)$rule->min_margin_percent) { continue; // Skip if it hurts profit } } } if ($target === 'sale_price') { $product->set_sale_price($new_price); } else { $product->set_regular_price($new_price); // If regular price becomes lower than sale price, clear sale price if ($product->get_sale_price() && $new_price <= $product->get_sale_price()) { $product->set_sale_price(''); } } $product->save(); // Record history $this->history->record( get_current_user_id() ?: 0, $product->get_id(), $target, $old_price, $new_price, 'auto_' . $rule_id . '_' . time(), 'automation' ); $affected_count++; } return $affected_count; } private function calculate_new_price($old, $type, $val_str) { $old = floatval($old); $is_percent = (strpos($val_str, '%') !== false); $val = floatval(str_replace('%', '', $val_str)); if ($type === 'discount') { return $is_percent ? $old * (1 - ($val / 100)) : max(0, $old - $val); } else { return $is_percent ? $old * (1 + ($val / 100)) : $old + $val; } } }