1

Woocommerce 的 Gravity Forms 产品插件在购物车和结帐中显示用户的表单输入。我想在用户的“帐户”页面中显示这些表单字段及其订单。我已经尝试了一个星期,似乎无法将正确的 php 代码放在一起。我怎样才能做到这一点?

我的代码是这样的:

$form_id = RGFormsModel::get_form_id('Domains');
$form = GFFormsModel::get_form_meta($form_id);
$field = GFFormsModel::get_field($form, 1);
$leads = RGFormsModel::get_leads($form['id']);

foreach($leads as $lead)
{
    foreach($field as $field_id)
    {
        $value = rgar($lead, (string) $field_id);
        echo $value;
    }
}

这将返回我想要的字段的所有条目,但是,我只想返回与该特定产品一起提交的条目。帮助?

这是一个快速示例,可以清楚地说明我在寻找什么。用户购买一件衬衫,并从附在产品上的重力表中选择大号。在购物车和结帐页面上,它在产品标题下方显示“尺寸:大”。我想将相同的文本与他们的订单一起添加到“我的帐户”页面。

4

2 回答 2

0

我解决类似问题的方法在编码实践中可能不是最好的,但它确实有效。它从 Gravity Forms 获取与订单相关的自定义数据,并将其显示在 WooCommerce 个人订单页面的送货地址下:

<?php
add_action('woocommerce_admin_order_data_after_shipping_address', 'ips_show_signs_in_admin_under_shipping', 10, 1);
/*
function to put in functions.php of the theme to add custom gravityforms data to customer order page in admin area.
*/
function ips_show_signs_in_admin_under_shipping($order)
{
    global $woocommerce, $post;
    $order_items = $order->get_items(apply_filters('woocommerce_admin_order_item_types', array( 'line_item')));
    foreach($order_items as $item_id => $item)
    {
        if ($metadata = $order->has_meta($item_id)) //not a comparison, so one equal sign. so if there is any data in there it would assign it and thus making it true, if no data it would be false
        {
            foreach($metadata as $meta)
            {
                // Skip hidden woocommerce core fields just in case
                if (in_array($meta['meta_key'], apply_filters('woocommerce_hidden_order_itemmeta', array(
                    '_qty',
                    '_tax_class',
                    '_product_id',
                    '_variation_id',
                    '_line_subtotal',
                    '_line_subtotal_tax',
                    '_line_total',
                    '_line_tax',
                    )))) continue;
                if (is_serialized($meta['meta_value'])) continue; // Skip serialised meta since we dont need it incase its in there
                $meta['meta_key'] = esc_attr($meta['meta_key']); //just to make sure there is no surprises in there
                $meta['meta_value'] = esc_textarea($meta['meta_value']); // using a textarea check for surprises (sql injection)
                if ("Signpost Address" === $meta['meta_key']) //here comes the custom data from gravity forms
                {
                   echo $meta['meta_value']; //this is what i was after from gravity forms collected with order
                }
            } //closes --- foreach($metadata as $meta)
        } //closes --- if ($metadata = $order->has_meta($item_id))
    } //closes --- foreach($order_items as $item_id => $item)
} //closes --- function
?>

编辑:此代码搜索订单元数据

于 2013-11-07T20:51:43.807 回答
0

我在我的functions.php文件中添加了上面的代码,不幸的是这对我不起作用。我已经到处寻找解决方案,这似乎正是我所追求的。如果那是我的重力形式选项之一,我是否只需将“路标地址”替换为“毯子尺寸”?

于 2014-02-27T00:13:43.643 回答