php Woocommerce -下订单后将用户重定向到自定义感谢页面

m2xkgtsf  于 2024-01-05  发布在  PHP
关注(0)|答案(2)|浏览(130)

我需要一点帮助与woocommerce自定义.我需要重定向后,用户的顺序是完成自定义页面,我在我的插件使用此代码,但似乎不工作

  1. public function redirect_customer_after_order()
  2. {
  3. if( is_checkout() && isset( $wp->query_vars['order-received'] ) ){
  4. wp_safe_redirect( site_url( 'riepilogo-ordine' ) );
  5. exit;
  6. }
  7. }
  8. add_action( 'template_redirect', array( $this, 'redirect_customer_after_order' ) );

字符串
我已经尝试下订单,但我的自定义woocommerce elementor页面将不会显示,我会看到默认的woocommerce感谢页面。我还注意到,这个钩子将被忽略

  1. remove_action( 'woocommerce_order_details_after_order_table', 'woocommerce_order_again_button' );


它将简单地删除再次订购按钮,我已经把它放在我的插件的__construct()里面.我如何才能解决这两个问题?

kmbjn2e3

kmbjn2e31#

正确的钩子:使用woocommerce_thankyou而不是template_redirect在WooCommerce中更可靠的重定向

  1. public function redirect_customer_after_order( $order_id ) {
  2. wp_safe_redirect( site_url( 'riepilogo-ordine' ) );
  3. exit;
  4. }
  5. add_action( 'woocommerce_thankyou', array( $this, 'redirect_customer_after_order' ) );

字符串
正确的钩子优先级:使用更高的优先级,以确保您的代码在WooCommerce的

  1. remove_action( 'woocommerce_order_details_after_order_table', 'woocommerce_order_again_button', 10 );

ycl3bljg

ycl3bljg2#

请尝试此代码重定向自定义谢谢你页

  1. add_action( 'woocommerce_thankyou', 'custom_thankyou_cb');
  2. function custom_thankyou_cb( $order_id ){
  3. $order = wc_get_order( $order_id );
  4. $url = 'https://yoursite.com/custom-custom-thankyou-page';
  5. if ( ! $order->has_status( 'failed' ) ) {
  6. wp_safe_redirect( $url );
  7. exit;
  8. }
  9. }

字符串
`

相关问题