【发布时间】:2020-10-18 12:37:23
【问题描述】:
如果您从产品类别“特殊”购买产品,您应该从 /checkout/ 重定向到 /newcheckout/。
当我运行此代码时,没有任何重定向/发生,所以我不确定故障出在哪里:
/*
* Redirect payment gateway based on category.
*/
function ace_disable_payment_gateway_category( $gateways ) {
// Categories that'll redorect the payment gateway
$category_slugs = array( 'special');
$category_ids = get_terms( array( 'taxonomy' => 'product_cat', 'slug' => $category_slugs, 'fields' => 'ids' ) );
$url = '/newcheckout/'; // New checkout URL
// Check each cart item for given category
foreach ( WC()->cart->get_cart() as $item ) {
$product = $item['data'];
if (is_page('checkout') {
if ( $product && array_intersect( $category_ids, $product->get_category_ids() ) ) {
wp_safe_redirect( $url ) // Redirect to newcheckout
break;
}
}
}
return $gateways;
}
add_filter( 'woocommerce_available_payment_gateways', 'ace_disable_payment_gateway_category' );
【问题讨论】:
标签: php wordpress redirect woocommerce checkout