Wordpress 提交重力表后显示woocommerce产品
下面的代码将打印属于同一类别的产品,即,$field_two将包含该类别Wordpress 提交重力表后显示woocommerce产品,wordpress,hook-woocommerce,gravity-forms-plugin,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 =
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\u确认
而不是gform\u提交后
更新:要在确认页面上显示woocommerce产品,请使用此选项(只需将数字替换为产品ID):
为了实现这一点,您必须更改表单的确认消息,在表单中您可以获得条目的值,以便在过滤结果后使用它们
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;
}
使用您的答案,我可以重定向到相应的产品页面,但我想在提交重力表后在同一页面中显示产品。感谢联系我们!我们将很快与您联系。array这意味着代码正在运行,但问题在于产品查询,这取决于您所拥有的……请尝试替换为显示最后10种产品的更一般的查询,例如:$args=array('limit'=>10,)$产品=wc\U get\U产品($args);
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;
}