When using the Cryptomus payment gateway z on your WordPress website to accept cryptocurrency payments, you might encounter an issue where the ‘Back to Store’ button redirects users to the wrong page. Fortunately, this is a common issue that can be resolved by following a few simple steps. In this article, we will provide a step-by-step guide to fixing the issue.
Understanding the Issue
The ‘Back to Store’ button is intended to take users back to your store after a payment attempt. However, if it redirects to an incorrect page, it might confuse users or disrupt their shopping experience. This issue typically occurs due to misconfigured URLs in the payment gateway’s code.
Step-by-Step Solution
Step 1: Access Your Hosting or File Manager
To fix the issue, you need access to the file where the redirect URL is set.
- If you have hosting access:
- Navigate to public_html > wp-content > plugins > cryptomus > Src > gateway.php.
- If hosting access is unavailable:
- Use a WordPress plugin like File Manager to access and edit the file.
Step 2: Locate the Function
Once you open the gateway.php file, search for the following function:public function process_payment($order_id)
Line No: 274
This function controls various aspects of the payment process, including the redirect URL for the ‘Back to Store’ button.
Step 3: Replace the Code
public function process_payment($order_id) {
// Head-to-head payment checking
if ($this->h2h == "yes") {
$order = wc_get_order($order_id);
$order->update_status(PaymentStatus::WC_STATUS_PENDING);
$order->save();
wc_reduce_stock_levels($order_id);
WC()->cart->empty_cart();
return ['result' => 'success', 'redirect' => home_url('/cryptomus-pay?order_id=' . $order_id . '&step_id=1')];
} else {
$order = wc_get_order($order_id);
$order->update_status(PaymentStatus::WC_STATUS_PENDING);
$order->save();
wc_reduce_stock_levels($order_id);
WC()->cart->empty_cart();
try {
// Payment creation
$payment = $this->payment->create([
'amount' => $order->get_total(),
'currency' => $order->get_currency(),
'order_id' => (string)$order_id,
'url_return' => 'https://khairulcoder.com/', // "Back to Store" button redirect URL
'url_success' => $this->get_return_url($order), // Redirect to the thank you page after successful payment
'url_callback' => get_site_url(null, "wp-json/cryptomus-webhook/$this->merchant_uuid"),
'is_payment_multiple' => true,
'lifetime' => (int)$this->lifetime * 3600,
'subtract' => $this->subtract,
]);
// Redirect to payment URL if successful
return ['result' => 'success', 'redirect' => $payment['url']];
} catch (\Exception $e) {
// If payment fails
$order->update_status(PaymentStatus::WC_STATUS_FAIL);
wc_increase_stock_levels($order);
$order->save();
}
// If no errors
// If you want to directly redirect here:
return [
'result' => 'success',
'redirect' => 'https://khairulcoder.com/' // Your custom redirect URL
];
}
}
Replace the existing function code with the following updated code. Be sure to update the url_return
and redirect
fields with the correct URL for your store:
Replace https://your-custom-url.com/
with the URL you want the ‘Back to Store’ button to redirect to.
Step 4: Save and Test
- Save the file after replacing the code.
- Test the payment gateway on your website to ensure the ‘Back to Store’ button now redirects to the correct page.
Important Tips
- Backup Your Website:
Always create a backup of your site before making changes to the code. This ensures you can restore it if anything goes wrong. - Seek Expert Help if Needed:
If you’re not comfortable editing code, consider hiring a Professional developer or watch tutorials on the process.
Conclusion
Fixing the ‘Back to Store’ button redirection issue in the Cryptomus payment gateway is straightforward when following these steps. By correctly configuring the redirect URL, you can provide your customers with a seamless payment experience. Don’t forget to test the changes thoroughly before making the site live.