如何解决在WooCommerce下订单后显示成功的自定义通知
我需要在结帐页面上检查付款是否成功,并显示消息:“您的付款已成功”,然后重定向到“谢谢”页面(该页面由插件Woo Product定制)工具)。我一直试图在Woo文档上找到钩子,但是到目前为止还没有运气。我拥有的最新代码是:
add_action( 'woocommerce_after_checkout_validation','message_after_payment' );
function message_after_payment(){
global $woocommerce;
$order = wc_get_order( $order_id );
if ( $order->has_status('processing') ){
wc_add_notice( __("Your payment has been successful","test"),"success" );
}
}
如何实现?
解决方法
提交订单(下订单)后,您将无法在结帐页面上显示“成功”通知。您可以在“已收到订单(谢谢)”页面中进行操作。同样在您的代码中,class CustomPage(models.Model):
title = models.CharField(max_length=20,blank=True)
subtitle = models.CharField(max_length=50,blank=True)
slug = models.SlugField(max_length=500,blank=True)
content = RichTextField()
displayOnFooter = models.BooleanField(default=False)
def __str__(self):
return f'{self.title}'
def get_absolute_url(self):
return reverse('custom-page',kwargs={'slug': self.slug})
未定义……
因此,右钩子是使用const [form] = Form.useForm();
const [,forceUpdate] = useState();
useEffect(() => {
forceUpdate({});
},[]);
<Form.Item shouldUpdate={true}>
{() => (
<Button
type="primary"
htmlType="submit"
disabled={!form.isFieldsTouched(false) ||
form.getFieldsError().filter(({ errors }) => errors.length).length}>
Log in</Button>)}
</Form.Item>
函数的$order_id
:
woocommerce_before_thankyou
代码进入活动子主题(或活动主题)的functions.php文件中。经过测试,可以正常工作。
添加:显示自定义html消息而不是Woocommerce通知
只需替换代码行:
wc_print_notice()
例如:
add_action( 'woocommerce_before_thankyou','success_message_after_payment' );
function success_message_after_payment( $order_id ){
// Get the WC_Order Object
$order = wc_get_order( $order_id );
if ( $order->has_status('processing') ){
wc_print_notice( __("Your payment has been successful","woocommerce"),"success" );
}
}
您可以根据需要在短信中添加自己的html。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。