Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions blockonomics-woocommerce.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,12 @@ function blockonomics_woocommerce_init()
add_action('woocommerce_email_customer_details', 'nolo_bnomics_woocommerce_email_customer_details', 10, 1);
add_filter('woocommerce_payment_gateways', 'woocommerce_add_blockonomics_gateway');
add_filter('clean_url', 'bnomics_async_scripts', 11, 1 );
add_action('init', 'custom_rewrite_rules');

/* Custom Rewrite Rule */
function custom_rewrite_rules() {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let us show_order . Also don't hardcode wc-api=WC_Gateway_Blockonomics let us use WC()->api_request_url else it won't work for WC < 3.0

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We cannot use WC()->api_request_url because add_rewrite_rule requires the url to start with index.php. All wordpress urls can be accessed in this manner.
In later versions of woocommerce, they added their own rewrite rules to change the url, however, we still need to access the original page with the form index.php?wc-api=WC_Gateway_Blockonomics

add_rewrite_rule( 'crypto/?$', 'index.php?wc-api=WC_Gateway_Blockonomics', 'top' );
}

/**
* Add this Gateway to WooCommerce
Expand Down
3 changes: 2 additions & 1 deletion php/WC_Gateway_Blockonomics.php
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,8 @@ public function process_payment($order_id)
update_option('blockonomics_orders', $blockonomics_orders);
$order_url = WC()->api_request_url('WC_Gateway_Blockonomics');
$order_url = add_query_arg('show_order', $address, $order_url);

$order_url = str_replace('wc-api/WC_Gateway_Blockonomics', 'crypto', $order_url);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there is no need to first add WC()->api_request_url and then replace it. We should directly use show_order

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We do not have any way to directly access show_order as we are not creating any page or post type. We still have to use WC()->api_request_url('WC_Gateway_Blockonomics') to fetch the correct url.


update_post_meta($order_id, 'blockonomics_address', $address);

return array(
Expand Down