PluginProbe ʕ •ᴥ•ʔ
CommerceBird – AI Command Center, ERP Integrations & B2B for WooCommerce (Zoho, Exact Online). / 2.3.7
CommerceBird – AI Command Center, ERP Integrations & B2B for WooCommerce (Zoho, Exact Online). v2.3.7
3.0.3 3.0.2 3.0.1 trunk 2.2.14 2.2.15 2.2.16 2.2.17 2.2.18 2.2.19 2.3.0 2.3.1 2.3.10 2.3.11 2.3.12 2.3.13 2.3.14 2.3.2 2.3.3 2.3.4 2.3.5 2.3.6 2.3.7 2.3.8 2.3.9 2.4.0 2.4.1 2.4.2 2.4.3 2.4.4 2.4.5 2.4.6 2.5.0 2.5.1 2.5.2 2.6.0 2.6.1 2.6.2 2.6.3 2.6.4 2.6.5 2.7.0 2.7.1 2.7.2 2.7.3 2.7.4 2.7.5 2.7.6 2.7.7 2.7.8 2.7.9 2.7.91 2.7.92 2.7.93 2.8.0 2.8.1 2.8.2 2.8.3 2.8.4 2.8.5 2.9.0 2.9.1 2.9.2 2.9.3 3.0.0
commercebird / includes / classes / class-common.php
commercebird / includes / classes Last commit date
apis 1 year ago purchase-orders 1 year ago zoho-crm 1 year ago zoho-inventory 1 year ago class-api-handler-zoho.php 1 year ago class-auth-zoho.php 1 year ago class-common.php 1 year ago class-plugin.php 1 year ago class-wc-api.php 1 year ago index.php 1 year ago
class-common.php
89 lines
1 <?php
2
3 /**
4 * Common class function.
5 */
6 if ( ! defined( 'ABSPATH' ) ) {
7 exit;
8 }
9
10 if ( ! class_exists( 'CMBIRD_Common_Functions' ) ) {
11 class CMBIRD_Common_Functions {
12
13
14 public function __construct() {
15 }
16
17 /**
18 * Function to clear all orphan data.
19 */
20 public function clear_orphan_data() {
21 global $wpdb;
22 // Delete orphaned product variations
23 $deleted_variations = absint(
24 $wpdb->query(
25 "DELETE products
26 FROM {$wpdb->posts} products
27 LEFT JOIN {$wpdb->posts} wp ON wp.ID = products.post_parent
28 WHERE wp.ID IS NULL AND products.post_type = 'product_variation';"
29 )
30 );
31 // Delete orphaned postmeta
32 $deleted_postmeta = absint(
33 $wpdb->query(
34 "DELETE pm
35 FROM {$wpdb->postmeta} pm
36 LEFT JOIN {$wpdb->posts} wp ON wp.ID = pm.post_id
37 WHERE wp.ID IS NULL;"
38 )
39 );
40 // Return the number of deleted entries (orphaned variations + orphaned postmeta)
41 return $deleted_variations + $deleted_postmeta;
42 }
43
44 /**
45 * Get the tax class based on the tax percentage.
46 *
47 * @param float $percentage The tax percentage.
48 * @return string|false The tax class if found, or standard if not found.
49 */
50 public function get_tax_class_by_percentage( $percentage ) {
51 // $fd = fopen( __DIR__ . '/get_tax_class_by_percentage.txt', 'a+' );
52
53 global $wpdb;
54 // Determine the number of decimal places in the provided percentage
55 $decimal_places = strlen( substr( strrchr( $percentage, '.' ), 1 ) );
56
57 // Round the percentage to the determined number of decimal places
58 $rounded_percentage = round( $percentage, $decimal_places );
59 $tax_rates = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}woocommerce_tax_rates WHERE ROUND(tax_rate, %d) = %f", $decimal_places, $rounded_percentage ) );
60
61 // If tax rates are found
62 if ( $tax_rates ) {
63 // Get the tax class from the first matching tax rate
64 $tax_class = $tax_rates[0]->tax_rate_class;
65 return $tax_class;
66 } else {
67 // Return null if no tax rates match the provided percentage
68 return 'standard';
69 }
70 }
71
72 /**
73 * Send email to admin.
74 *
75 * @param string $subject The subject of the email.
76 * @param string $message The message body of the email.
77 *
78 * @return void
79 */
80 public function send_email( $subject, $message ) {
81 $admin_email = get_option( 'admin_email' );
82 $headers = array( 'Content-Type: text/html; charset=UTF-8' );
83
84 // Send the email
85 wp_mail( $admin_email, $subject, $message, $headers );
86 }
87 }
88 }
89