PluginProbe ʕ •ᴥ•ʔ
TaxCloud for WooCommerce / 8.4.11
TaxCloud for WooCommerce v8.4.11
8.4.11 8.4.10 8.4.9 trunk 6.0.11 6.0.12 6.0.13 6.0.14 6.1.0 6.1.1 6.1.2 6.2.0 6.2.1 6.2.2 6.2.3 6.2.4 6.2.5 6.2.6 6.3.0 6.3.1 6.3.10 6.3.11 6.3.12 6.3.13 6.3.2 6.3.3 6.3.4 6.3.5 6.3.6 6.3.7 6.3.8 6.3.9 7.0.0 7.0.1 7.0.10 7.0.11 7.0.12 7.0.13 7.0.2 7.0.3 7.0.4 7.0.5 7.0.6 7.0.7 7.0.8 7.0.9 8.0.0 8.0.1 8.0.10 8.0.11 8.0.12 8.0.13 8.0.14 8.0.15 8.0.16 8.0.17 8.0.2 8.0.3 8.0.4 8.0.5 8.0.6 8.0.7 8.0.8 8.0.9 8.1.0 8.1.1 8.2.0 8.2.1 8.2.2 8.2.3 8.2.4 8.3.0 8.3.1 8.3.2 8.3.3 8.3.4 8.3.5 8.3.6 8.3.7 8.3.8 8.4.0 8.4.1 8.4.2 8.4.3 8.4.4 8.4.5 8.4.6 8.4.7 8.4.8
simple-sales-tax / includes / integrations / class-sst-adp.php
simple-sales-tax / includes / integrations Last commit date
class-sst-adp.php 4 months ago class-sst-composite-products.php 1 month ago class-sst-deposits-for-wc.php 11 months ago class-sst-dokan.php 8 months ago class-sst-subscriptions.php 3 months ago class-sst-wc-vendors.php 8 months ago class-sst-wcfm.php 8 months ago class-sst-wcmp.php 8 months ago
class-sst-adp.php
101 lines
1 <?php
2
3 if ( ! defined( 'ABSPATH' ) ) {
4 exit; // Exit if accessed directly.
5 }
6
7 /**
8 * Advanced Dynamic Pricing Integration Worker Proxy.
9 *
10 * This proxy extends ADP's WcNoFilterWorker to ensure that WooCommerce
11 * calculation hooks are always preserved, even in cases where ADP
12 * calls calculateTotals() without appropriate flags and filters.
13 *
14 * @since 8.4.4
15 */
16 class SST_ADP_Worker_Proxy extends \ADP\BaseVersion\Includes\WC\WcNoFilterWorker {
17 /**
18 * Overrides calculateTotals to always include 'allow_totals_hooks' flag.
19 *
20 * @param WC_Cart $wcCart
21 * @param array $flags
22 */
23 public function calculateTotals( &$wcCart, ...$flags ) {
24 if ( ! in_array( self::FLAG_ALLOW_TOTALS_HOOKS, $flags ) ) {
25 $flags[] = self::FLAG_ALLOW_TOTALS_HOOKS;
26 }
27 return parent::calculateTotals( $wcCart, ...$flags );
28 }
29 }
30
31 /**
32 * Advanced Dynamic Pricing Integration.
33 *
34 * Prevents ADP from removing WooCommerce calculation hooks that are required
35 * for SST to function correctly.
36 *
37 * @author Simple Sales Tax
38 * @package SST
39 * @since 8.4.4
40 */
41 class SST_ADP {
42
43 /**
44 * Constructor.
45 */
46 public function __construct() {
47 add_filter( 'adp_calculate_totals_flags_for_cloned_cart_before_process', array( $this, 'inject_worker_proxy' ), 10, 5 );
48 add_filter( 'adp_flags_for_final_calculate_totals', array( $this, 'add_allow_totals_hooks_flag' ) );
49 }
50
51 /**
52 * Injects a WorkerProxy into the CartProcessor using reflection.
53 *
54 * This ensures that EVERY call to calculateTotals within the processor
55 * will respect the 'allow_totals_hooks' flag, including unfiltered calls.
56 *
57 * @param array $flags
58 * @param object $worker
59 * @param bool $first
60 * @param object $clonedCart
61 * @param object $processor
62 * @return array
63 */
64 public function inject_worker_proxy( $flags, $worker, $first, $clonedCart, $processor ) {
65 try {
66 $reflection = new ReflectionClass( $processor );
67 if ( $reflection->hasProperty( 'wcNoFilterWorker' ) ) {
68 $property = $reflection->getProperty( 'wcNoFilterWorker' );
69 $property->setAccessible( true );
70 $current_worker = $property->getValue( $processor );
71 if ( ! ( $current_worker instanceof SST_ADP_Worker_Proxy ) ) {
72 $property->setValue( $processor, new SST_ADP_Worker_Proxy() );
73 }
74 }
75 } catch ( Exception $e ) {
76 // Log the error
77 SST_Logger::debug(
78 __( 'ADP Integration Error:', 'simple-sales-tax' ),
79 $e->getMessage()
80 );
81 }
82
83 return $this->add_allow_totals_hooks_flag( $flags );
84 }
85
86 /**
87 * Adds the 'allow_totals_hooks' flag to ADP's calculation flags.
88 *
89 * @param array $flags ADP calculation flags.
90 * @return array
91 */
92 public function add_allow_totals_hooks_flag( $flags ) {
93 if ( is_array( $flags ) && ! in_array( 'allow_totals_hooks', $flags ) ) {
94 $flags[] = 'allow_totals_hooks';
95 }
96 return $flags;
97 }
98
99 }
100
101 new SST_ADP();