我有一个很好的代码,可以在购买任何产品后重定向到一个定制的谢谢页面.
add_action( 'woocommerce_thankyou', 'updated_redirectcustom');
function updated_redirectcustom( $order_id ){
$order = wc_get_order( $order_id );
$url = '/thank-you/';
if ( ! $order->has_status( 'failed' ) ) {
wp_safe_redirect( $url );
exit;
}
}
我决定为几个特定的产品变体实现到另一个页面的定制重定向,但不幸的是,我更改的代码不起作用,所有订单仍然被重定向到/Thank-you/URL:
add_action( 'woocommerce_thankyou', 'updated_redirectcustom');
function updated_redirectcustom( $order_id ){
$order = wc_get_order( $order_id );
$url = '/thank-you/';
if ( ! $order->has_status( 'failed' ) ) {
wp_safe_redirect( $url );
exit;
}
if( ! $order_id ) {
return;
}
if ( is_a( $order, 'WC_Order' ) ) {
// False
$redirection = false;
// Loop through order items
foreach ( $order->get_items() as $item_key => $item ) {
// Product ID(s)
$product_ids = array( $item->get_product_id(), $item->get_variation_id() );
// Product ID in array
if ( in_array( 12345, 123456, $product_ids ) ) {
$redirection = true;
}
}
}
if ( $redirection ) {
wp_safe_redirect( home_url( '/thank-you-2/' ) );
exit;
}
}
我哪里错了?