From 7cc620d4c966506ed84c3e936fb1b2330f128536 Mon Sep 17 00:00:00 2001 From: Reinhold Kainhofer <reinhold@kainhofer.com> Date: Thu, 8 Dec 2016 00:16:37 +0100 Subject: [PATCH] Add support for PayPal (invoice number needs to be passed to PP) Fixes #14. --- ordernumbers_woocommerce.php | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/ordernumbers_woocommerce.php b/ordernumbers_woocommerce.php index 82a2ff4..df655f9 100644 --- a/ordernumbers_woocommerce.php +++ b/ordernumbers_woocommerce.php @@ -65,6 +65,9 @@ class OpenToolsOrdernumbers extends OpenToolsOrdernumbersBasic { // Custom table widget for custom variable definitions: Hooks for creating and storing values add_action( 'woocommerce_admin_field_ordernumber_variables', array( $this, 'admin_field_variables' ) ); add_action( 'pre_update_option_ordernumber_variables', array( $this, 'update_option_variables')); + + // SUPPORT FOR BUILT-IN PLUGINS AND PAYMENT METHODS: + $this->paypal_invoicenumber_init(); // THIRD-PARTY PLUGIN SUPPORT // Install hooks for third-party plugin support: @@ -330,6 +333,18 @@ class OpenToolsOrdernumbers extends OpenToolsOrdernumbersBasic { $reps = apply_filters( 'opentools_ordernumber_replacements', $reps, $details, $nrtype); } + +// PAYPAL SUPPORT + protected function paypal_invoicenumber_init() { + add_filter ('woocommerce_paypal_args', array( &$this, 'paypal_arguments'), 10, 2/*<= Also get the order object! */); + } + + public function paypal_arguments($vals, $order) { + if ($this->invoicenumbers_activated()) { + $vals['invoice'] = $this->get_or_create_number($order->order_id, $order, 'invoice'); + } + return $vals; + } // THIRD-PARTY PLUGIN SUPPORT -- GitLab