提交重力表单后显示 woocommerce 产品
Show woocommerce product after gravity form submission
下面的代码将打印属于同一类别的产品,即 $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();
}
重力表提交后,如何展示产品??
试试这个过滤器。 gform_confirmation
而不是 gform_after_submission
.
https://docs.gravityforms.com/gform_confirmation/
更新:要在确认页面上显示 woocommerce 产品,请使用此(只需将数字替换为产品 ID):
echo do_shortcode('[products ids="1, 2, 3, 4, 5"]');
为了实现这一点,您必须更改您获取条目值的表单的确认消息,以便在过滤结果后使用它们
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;
}
下面的代码将打印属于同一类别的产品,即 $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();
}
重力表提交后,如何展示产品??
试试这个过滤器。 gform_confirmation
而不是 gform_after_submission
.
https://docs.gravityforms.com/gform_confirmation/
更新:要在确认页面上显示 woocommerce 产品,请使用此(只需将数字替换为产品 ID):
echo do_shortcode('[products ids="1, 2, 3, 4, 5"]');
为了实现这一点,您必须更改您获取条目值的表单的确认消息,以便在过滤结果后使用它们
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;
}