如果客户woocommerce订单失败,我想重定向到自定义wordpress页面。
我已经找到并实现了以下代码,该代码在付款成功后重定向到一个新页面。
是否可以添加到此代码中,以便将失败的订单发送到另一个特定的url?
add_action( 'woocommerce_thankyou', 'bbloomer_redirectcustom');
function bbloomer_redirectcustom( $order_id ){
$order = wc_get_order( $order_id );
$url = 'https://yoursite.com/custom-url';
if ( ! $order->has_status( 'failed' ) ) {
wp_safe_redirect( $url );
exit;
}
}发布于 2020-02-02 18:17:43
根据您拥有的代码,您可以使用$order->has_status( 'failed' )
所以你得到了:
function action_woocommerce_thankyou( $order_id ) {
// Get $order object
$order = wc_get_order( $order_id );
// Is a WC_Order
if ( is_a( $order, 'WC_Order' ) ) {
// Settings
$url1 = 'https://yoursite.com/custom-url-1';
$url2 = 'https://yoursite.com/custom-url-2';
// Compare
if ( ! $order->has_status( 'failed' ) ) {
wp_safe_redirect( $url1 );
exit;
} else {
wp_safe_redirect( $url2 );
exit;
}
}
}
add_action( 'woocommerce_thankyou', 'action_woocommerce_thankyou', 10, 1 );代码位于活动子主题(或活动主题)的functions.php文件中。在Wordpress 5.8.1和WooCommerce 5.8.0中进行测试和工作
https://stackoverflow.com/questions/60027399
复制相似问题