Skip to content

Commit

Permalink
fix dynamic property depracation notice
Browse files Browse the repository at this point in the history
  • Loading branch information
Sidsector9 committed Jan 9, 2024
1 parent fd8a73c commit 66f3963
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 19 deletions.
13 changes: 8 additions & 5 deletions includes/Framework/PaymentGateway/Payment_Gateway.php
Original file line number Diff line number Diff line change
Expand Up @@ -1616,11 +1616,12 @@ public function get_payment_method_image_url( $type ) {
*
* @since 3.0.0
* @param int|WC_Order_Square $order the order or order ID being processed
* @return \WC_Order object with payment and transaction information attached
* @return WC_Order_Square object with payment and transaction information attached
*/
public function get_order( $order ) {
if ( is_numeric( $order ) ) {
$order = new WC_Order_Square( $order );
/** @var WC_Order_Square $order */
$order = wc_get_order( $order );
}

// set payment total here so it can be modified for later by add-ons like subscriptions which may need to charge an amount different than the get_total()
Expand Down Expand Up @@ -1748,7 +1749,8 @@ public function get_capture_handler() {
*/
public function get_order_for_capture( $order, $amount = null ) {
if ( is_numeric( $order ) ) {
$order = new WC_Order_Square( $order );
/** @var WC_Order_Square $order */
$order = wc_get_order( $order );
}

// add capture info
Expand Down Expand Up @@ -1998,11 +2000,12 @@ public function maybe_refund_gift_card( $order ) {
* @param \WC_Square_Order|int $order order being processed
* @param float $amount refund amount
* @param string $reason optional refund reason text
* @return \WC_Order|\WP_Error object with refund information attached
* @return WC_Order_Square|\WP_Error object with refund information attached
*/
protected function get_order_for_refund( $order, $amount, $reason ) {
if ( is_numeric( $order ) ) {
$order = new WC_Order_Square( $order );
/** @var WC_Order_Square $order */
$order = wc_get_order( $order );
}

// add refund info
Expand Down
19 changes: 19 additions & 0 deletions includes/Handlers/Order.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ public function __construct() {
add_action( 'woocommerce_admin_order_data_after_billing_address', array( $this, 'render_admin_missing_billing_details_notice' ) );
add_action( 'before_woocommerce_pay_form', array( $this, 'render_missing_billing_details_notice' ), 10, 1 );
add_filter( 'woocommerce_order_email_verification_required', array( $this, 'no_verification_on_guest_save' ) );
add_filter( 'woocommerce_order_class', array( $this, 'load_custom_order_class' ), 999 );
}

/**
Expand Down Expand Up @@ -1052,4 +1053,22 @@ public function no_verification_on_guest_save( $email_verification_required ) {

return $email_verification_required;
}

/**
* Loads the class `WC_Order_Square` to handle deprecated
* dynamic properties notice for PHP 8.2+.
*
* @since x.x.x
*
* @param string $classname Order classname.
*
* @return string
*/
public function load_custom_order_class( $classname ) {
if ( '\Automattic\WooCommerce\Admin\Overrides\Order' === $classname ) {
return '\WooCommerce\Square\WC_Order_Square';
} else {
return $classname;
}
}
}
17 changes: 3 additions & 14 deletions includes/WC_Order_Square.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@

namespace WooCommerce\Square;

class WC_Order_Square extends \WC_Order {
use Automattic\WooCommerce\Admin\Overrides\Order;

class WC_Order_Square extends Order {
/**
* Holds the Square customer ID.
*
Expand Down Expand Up @@ -79,17 +81,4 @@ class WC_Order_Square extends \WC_Order {
* @var object
*/
public $refund;

/**
* Wrapper around wc_get_order().
*
* @since 4.3.1
*
* @param mixed $the_order Post object or post ID of the order.
*
* @return bool|WC_Order|WC_Order_Refund|WC_Order_Square
*/
public static function wc_get_order( $the_order ) {
return \wc_get_order( $the_order );
}
}

0 comments on commit 66f3963

Please sign in to comment.