【问题标题】:Remove pricing fields from gravity form从重力表单中删除定价字段
【发布时间】:2016-11-05 08:15:07
【问题描述】:

我正在使用来自产品插件的重力。在发送邮件时,Woo-commerce 将 Gform 数据嵌入到产品中并发送给客户和管理员。我也想将该电子邮件发送给版主,但不想向他显示价格和折扣。为此,我正在使用 WP 提前通知,其中包含一个电子邮件模板。我可以从中删除 TOTAL 价格字段,但无法从重力表单数据中删除总价格。它显示产品的价格以及产品名称。例如

Selected City: XXX
Selected Product : Packets ($10.00)
Quantity : 1
Tax : 5% = $0.05
Total : $9.95
Mode of Payment: Credit Card

所有这些数据都来自数组“gravity_form_history”。我通过覆盖数组索引来手动隐藏价格。但, 我的主管希望我给出一个通用的解决方案。如果他使用 gforms 添加更多产品,那么他只需在某处输入字段名称,仅隐藏/删除该字段的价格/值,而不是标签)。他不想玩代码。

有什么解决办法吗?

【问题讨论】:

    标签: php wordpress gravity-forms-plugin


    【解决方案1】:

    解决方案如果有人需要。

    我使用了 woocommerce 的“$item_meta”数组来捕获 gform 数据。

    foreach ($item_meta->meta as $arraydata => $arrayvalue)
                    {
    
                        if (    $arraydata == "_qty" ||
                                $arraydata  == "_tax_class" ||
                                $arraydata  == "_product_id" ||
                                $arraydata  == "_gravity_forms_history" ||
                        // all values above are general and will be there in default customer email.
                        // below arraydata is from gravity form
                                $arraydata  == "Total" ||
                                $arraydata  == "Delivery charges")
                        {}
                    else
                        {
                            $string = preg_replace("/\d+\.\d+/", "", $arrayvalue[0]); 
                            $string = str_replace('($)', '', $string);
                            // printing Filds : Value
                             echo $arraydata.": ".$string."<br>";
                        }
    
                    }
    

    这将从 gform 返回带有值的字段,除了 if 条件中提到的那些。 preg_replace 用于从值中删除产品价格、折扣价格和百分比、税金(如果适用)。例如它会改变

    Selected Product : Headphones ($25.45), Mouse ($15.00), Keyboard(with backlight) ($45.00)
    Total Price : $85.45
    Payment Gateway: Credit Card
    

    Selected Product : Headphones , Mouse , Keyboard(with backlight)
    Payment Gateway: Credit Card
    

    发生这一切的文件将通过 Wordpress Advance Notification 插件向特定的电子邮件地址发送一封电子邮件。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-12-12
      • 1970-01-01
      • 2020-09-23
      • 1970-01-01
      • 2012-12-20
      • 2016-01-30
      相关资源
      最近更新 更多