这个问题与...有关thankyou page
。
我创建了自己的自定义“谢谢”布局,其简短代码为
[custom-thankyou-054]
。
-
通常,当您完成订单后,结帐页面会告诉您Thank you. Your order has been received.
有关订单的详细信息。
我不想显示所有这些细节。我设计了一个简单但更具交互性的布局,我想改用它。
我想知道是否有做这个的钩子?
我知道在下订单后可以重定向到另一个页面的钩子。
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;
}
}
不幸的是,这不是我的情况。我希望用户继续使用,checkout page
但在下订单后只能使用自定义布局更改其内容,例如:
add_action( '??????????', 'change_checkout_page_content_after_placing_order');
function change_checkout_page_content_after_placing_order( $order_id ){
return do_shortcode('[custom-thankyou-054]');
}
那可能吗?
您做错了,但您已经足够接近了。
不要直接使用Elementor将元素添加到您的结帐页面。既然你只是想添加的顶部和结算形式的地板元件,那么你可以使用钩子做woocommerce_before_checkout_form
了结帐表单的顶部,并woocommerce_after_checkout_form
在结账表单底部。
如果您真的想使用Elementor设计结帐表单顶部和底部的元素,那么我建议按照创建感谢模板然后使用其短代码的方式进行操作。
例如,您创建了一个为结帐表单的顶部和底部设计的模板,而短代码类似于[my-top-design]
和[my-bottom-design]
。然后转到您的function.php
并执行以下操作。
/** This will add your template designed for the top of the checkout form **/
add_action('woocommerce_before_checkout_form', 'custom_top_checkout_form');
function custom_top_checkout_form(){
echo do_shortcode('[my-top-design]');
/**You can also insert an html tag here instead of the shortcode of your template..**/
// echo '<h2>Some top elements...</h2>';
}
/** This will add your template designed for the bottom of the checkout form **/
add_action('woocommerce_after_checkout_form', 'custom_bottom_checkout_form');
function custom_bottom_checkout_form(){
echo do_shortcode('[my-bottom-design]');
/**You can also insert an html tag here instead of the shortcode of your template..**/
// echo '<h2>Some bottom elements...</h2>';
}
下订单后,所有结帐表单(包括顶部和底部元素)都将消失,并将其替换为Thankyou页面。
现在,在您的thankyou页面上,您可以使用WooCommerce模板overlay覆盖它。
复制:
/wp-content/plugins/woocommerce/templates/checkout/thankyou.php。
进入您的活动主题,应该是这样的:/wp-content/themes/activetheme/woocommerce/checkout/thankyou.php
然后,thankyou.php
使用简码再次编辑和删除自定义的感谢模板替换中不必要的信息。
将会是这样。
<?php
defined( 'ABSPATH' ) || exit;
?>
<div class="woocommerce-order">
<?php if ( $order ) :
do_action( 'woocommerce_before_thankyou', $order->get_id() ); ?>
<?php if ( $order->has_status( 'failed' ) ) : ?>
<p class="woocommerce-notice woocommerce-notice--error woocommerce-thankyou-order-failed"><?php esc_html_e( 'Unfortunately your order cannot be processed as the originating bank/merchant has declined your transaction. Please attempt your purchase again.', 'woocommerce' ); ?></p>
<p class="woocommerce-notice woocommerce-notice--error woocommerce-thankyou-order-failed-actions">
<a href="<?php echo esc_url( $order->get_checkout_payment_url() ); ?>" class="button pay"><?php esc_html_e( 'Pay', 'woocommerce' ); ?></a>
<?php if ( is_user_logged_in() ) : ?>
<a href="<?php echo esc_url( wc_get_page_permalink( 'myaccount' ) ); ?>" class="button pay"><?php esc_html_e( 'My account', 'woocommerce' ); ?></a>
<?php endif; ?>
</p>
<?php else : ?>
<?php
//your custom template here...
echo do_shortcode('[custom-thankyou-054]');
?>
<?php endif; ?>
<?php else : ?>
<p class="woocommerce-notice woocommerce-notice--success woocommerce-thankyou-order-received"><?php echo apply_filters( 'woocommerce_thankyou_order_received_text', esc_html__( 'Thank you. Your order has been received.', 'woocommerce' ), null ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?></p>
<?php endif; ?>
</div>
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句