Skip to content

Commit

Permalink
Merge pull request #353 from aadyanthaya/hpos-compatibility
Browse files Browse the repository at this point in the history
Making plugin HPOS compatibility
  • Loading branch information
shivaenigma authored Nov 1, 2023
2 parents 24f7af6 + cc72dad commit 6fd649d
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 8 deletions.
6 changes: 6 additions & 0 deletions blockonomics-woocommerce.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down
19 changes: 11 additions & 8 deletions php/Blockonomics.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
else if (strpos($addr_meta_value, $address) === false) {
$wc_order->update_meta_data( $addr_meta_key, $addr_meta_value. ', '. $address );
}
$wc_order->save();
}

public function create_new_order($order_id, $crypto){
Expand Down Expand Up @@ -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);
else if (strpos($txid_meta_value, $txid) === false){
$wc_order->update_meta_data($txid_meta_key, $txid_meta_value.', '. $txid);
}
$wc_order->save();
}

public function update_paid_amount($callback_status, $paid_satoshi, $order, $wc_order){
Expand Down

0 comments on commit 6fd649d

Please sign in to comment.