提交重力表单后显示woocommerce产品

时间:2018-11-09 10:30:57

标签: wordpress hook-woocommerce gravity-forms-plugin

下面的代码将打印属于同一类别的产品,即$ field_two将包含该类别。

add_action( 'gform_after_submission_1', 'access_entry_via_field', 10, 2 );

function access_entry_via_field( $entry, $form ) {

    $field_one = $_POST['input_1'];
    $field_two = $_POST['input_6'];

    $items = array("age"=>"$field_one", "skin_type"=>"$field_two");

    $args = array(
        "category" => array("$field_two"),
    );

    $products = wc_get_products($args);

    var_dump($products); exit();

}

提交重力表格后,如何显示产品?

2 个答案:

答案 0 :(得分:1)

尝试使用此过滤器。 gform_confirmation而不是gform_after_submission

https://docs.gravityforms.com/gform_confirmation/

更新:要在确认页面上显示woocommerce产品,请使用此方法(只需将数字替换为产品ID)即可:

echo do_shortcode('[products ids="1, 2, 3, 4, 5"]');

答案 1 :(得分:0)

要实现此目的,您必须更改表格的确认消息,在该消息中您将获得条目的值,以便在过滤结果后使用它们

add_filter( 'gform_confirmation_1', 'custom_confirmation_message', 10, 4 );
function custom_confirmation_message( $confirmation, $form, $entry, $ajax ) {
   $field_one = $entry["1.1"];
   $field_two = $entry["1.6"];

   $items = array("age"=>"$field_one", "skin_type"=>"$field_two");

   $args = array(
       "category" => array("$field_two"),
    );
    $products = wc_get_products($args);

    $confirmation .= 'Thanks for contacting us! We will get in touch with you shortly.';
    $confirmation .= $products;

return $confirmation;
}