我需要一些有关 woocommerce 定制的帮助。我需要在订单完成后将用户重定向到自定义页面,我在我的插件中使用此代码,但似乎不起作用
public function redirect_customer_after_order()
{
if( is_checkout() && isset( $wp->query_vars['order-received'] ) ){
wp_safe_redirect( site_url( 'riepilogo-ordine' ) );
exit;
}
}
add_action( 'template_redirect', array( $this, 'redirect_customer_after_order' ) );
我已尝试下订单,但我的自定义 woocommerce elementor 页面将不会显示,我将看到默认的 woocommerce 谢谢页面。我还注意到这个钩子会被忽略
remove_action( 'woocommerce_order_details_after_order_table', 'woocommerce_order_again_button' );
它将简单地删除再次订购按钮,我已将其放置在我的插件的
__construct()
中。我该如何解决这两个问题?
正确的 Hook:使用 woocommerce_thankyou 而不是 template_redirect 在 WooCommerce 中实现更可靠的重定向
public function redirect_customer_after_order( $order_id ) {
wp_safe_redirect( site_url( 'riepilogo-ordine' ) );
exit;
}
add_action( 'woocommerce_thankyou', array( $this, 'redirect_customer_after_order' ) );
正确的 Hook 优先级:使用更高的优先级来确保您的代码在 WooCommerce 之后运行
remove_action( 'woocommerce_order_details_after_order_table', 'woocommerce_order_again_button', 10 );