From 5ab49590900a33c437c1abcc644bc596efeebbf9 Mon Sep 17 00:00:00 2001 From: Aishwarya adyanthaya <91294460+aadyanthaya@users.noreply.github.com> Date: Sat, 28 Oct 2023 17:08:38 +0100 Subject: [PATCH 1/3] Changed legacy order api to support HPOS --- blockonomics-woocommerce.php | 6 ++++++ php/Blockonomics.php | 15 +++++++++------ 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/blockonomics-woocommerce.php b/blockonomics-woocommerce.php index 445c5948..bd12b4d8 100755 --- a/blockonomics-woocommerce.php +++ b/blockonomics-woocommerce.php @@ -572,6 +572,12 @@ function bnomics_async_scripts($url) register_activation_hook( __FILE__, 'blockonomics_activation_hook' ); add_action('admin_notices', 'blockonomics_plugin_activation'); +add_action( 'before_woocommerce_init', function() { + if ( class_exists( \Automattic\WooCommerce\Utilities\FeaturesUtil::class ) ) { + \Automattic\WooCommerce\Utilities\FeaturesUtil::declare_compatibility( 'custom_order_tables', __FILE__, true ); + } +} ); + global $blockonomics_db_version; $blockonomics_db_version = '1.4'; diff --git a/php/Blockonomics.php b/php/Blockonomics.php index 5af6b1a9..2d565e0a 100755 --- a/php/Blockonomics.php +++ b/php/Blockonomics.php @@ -515,15 +515,17 @@ public function create_and_insert_new_order_on_underpayment($order){ // Save the new address to the WooCommerce order public function record_address($order_id, $crypto, $address){ + $wc_order = wc_get_order( $order_id ); $addr_meta_key = 'blockonomics_payments_addresses'; - $addr_meta_value = get_post_meta($order_id, $addr_meta_key); + $addr_meta_value = $wc_order->get_meta($addr_meta_key); if (empty($addr_meta_value)){ - update_post_meta($order_id, $addr_meta_key, $address); + $wc_order->update_meta_data( $addr_meta_key, $address ); } // when address meta value is not empty and $address is not in it else if (strpos($addr_meta_value[0], $address) === false) { - update_post_meta($order_id, $addr_meta_key, $addr_meta_value[0]. ', '. $address); + $wc_order->update_meta_data( $addr_meta_key, $addr_meta_value[0]. ', '. $address ); } + $wc_order->save(); } public function create_new_order($order_id, $crypto){ @@ -783,15 +785,16 @@ public function check_callback_secret($secret){ public function save_transaction($order, $wc_order){ $txid_meta_key = 'blockonomics_payments_txids'; - $txid_meta_value = get_post_meta($order['order_id'], $txid_meta_key); + $txid_meta_value = $wc_order->get_meta($txid_meta_key); $txid = $order['txid']; if (empty($txid_meta_value)){ - update_post_meta($wc_order->get_id(), $txid_meta_key, $txid); + $wc_order->update_meta_data($txid_meta_key, $txid); } // when txid meta value is not empty and $txid is not in it else if (strpos($txid_meta_value[0], $txid) === false){ - update_post_meta($wc_order->get_id(), $txid_meta_key, $txid_meta_value[0].', '. $txid); + $wc_order->update_meta_data($txid_meta_key, $txid_meta_value[0].', '. $txid); } + $order->save(); } public function update_paid_amount($callback_status, $paid_satoshi, $order, $wc_order){ From 4fb7c831c46375b38917d1857e825cddb2e5dad4 Mon Sep 17 00:00:00 2001 From: Aishwarya adyanthaya <91294460+aadyanthaya@users.noreply.github.com> Date: Mon, 30 Oct 2023 19:35:28 +0000 Subject: [PATCH 2/3] Save function --- php/Blockonomics.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/php/Blockonomics.php b/php/Blockonomics.php index 2d565e0a..b6a38615 100755 --- a/php/Blockonomics.php +++ b/php/Blockonomics.php @@ -794,7 +794,7 @@ public function save_transaction($order, $wc_order){ else if (strpos($txid_meta_value[0], $txid) === false){ $wc_order->update_meta_data($txid_meta_key, $txid_meta_value[0].', '. $txid); } - $order->save(); + $wc_order->save(); } public function update_paid_amount($callback_status, $paid_satoshi, $order, $wc_order){ From cc72dad515084768eff8207a7c3b1691fdff33b4 Mon Sep 17 00:00:00 2001 From: Aishwarya adyanthaya <91294460+aadyanthaya@users.noreply.github.com> Date: Mon, 30 Oct 2023 20:32:56 +0000 Subject: [PATCH 3/3] Update_meta_data fix The data are in the form of string instead of array so had to change the $txid_meta_value instead of $txid_meta_value[0]. --- php/Blockonomics.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/php/Blockonomics.php b/php/Blockonomics.php index b6a38615..e913f98e 100755 --- a/php/Blockonomics.php +++ b/php/Blockonomics.php @@ -522,8 +522,8 @@ public function record_address($order_id, $crypto, $address){ $wc_order->update_meta_data( $addr_meta_key, $address ); } // when address meta value is not empty and $address is not in it - else if (strpos($addr_meta_value[0], $address) === false) { - $wc_order->update_meta_data( $addr_meta_key, $addr_meta_value[0]. ', '. $address ); + else if (strpos($addr_meta_value, $address) === false) { + $wc_order->update_meta_data( $addr_meta_key, $addr_meta_value. ', '. $address ); } $wc_order->save(); } @@ -791,8 +791,8 @@ public function save_transaction($order, $wc_order){ $wc_order->update_meta_data($txid_meta_key, $txid); } // when txid meta value is not empty and $txid is not in it - else if (strpos($txid_meta_value[0], $txid) === false){ - $wc_order->update_meta_data($txid_meta_key, $txid_meta_value[0].', '. $txid); + else if (strpos($txid_meta_value, $txid) === false){ + $wc_order->update_meta_data($txid_meta_key, $txid_meta_value.', '. $txid); } $wc_order->save(); }