在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文件中。经过测试,可以正常工作。

enter image description here


添加:显示自定义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。

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...