Factory.php
1 week ago
MulticurrencyHooks.php
1 week ago
SharedHooks.php
1 week ago
class-wcml-wc-subscriptions.php
1 week ago
SharedHooks.php
35 lines
| 1 | <?php |
| 2 | |
| 3 | namespace WCML\Compatibility\WcSubscriptions; |
| 4 | |
| 5 | use WC_Cart; |
| 6 | |
| 7 | class SharedHooks implements \IWPML_Action { |
| 8 | |
| 9 | private $recurring_carts; |
| 10 | |
| 11 | public function add_hooks() { |
| 12 | add_action( 'init', [ $this, 'init' ], 9 ); |
| 13 | } |
| 14 | |
| 15 | public function init() { |
| 16 | if ( ! is_admin() ) { |
| 17 | add_action( 'woocommerce_before_calculate_totals', [ $this, 'maybe_backup_recurring_carts' ], 1 ); |
| 18 | add_action( 'woocommerce_after_calculate_totals', [ $this, 'maybe_restore_recurring_carts' ], 200 ); |
| 19 | } |
| 20 | } |
| 21 | |
| 22 | public function maybe_backup_recurring_carts( $cart ) { |
| 23 | if ( ! empty( $cart->recurring_carts ) ) { |
| 24 | $this->recurring_carts = $cart->recurring_carts; |
| 25 | } |
| 26 | } |
| 27 | |
| 28 | public function maybe_restore_recurring_carts( $cart ) { |
| 29 | if ( ! empty( $this->recurring_carts ) ) { |
| 30 | $cart->recurring_carts = $this->recurring_carts; |
| 31 | $this->recurring_carts = null; |
| 32 | } |
| 33 | } |
| 34 | } |
| 35 |