在wordpress中,我使用的是联系表格7.我想创建一个订单。但订单数量必须至少有2个产品。当人们订购少于两种产品时,他们必须得到一条不可能的消息。
人们可以订购共6种不同的产品。每种产品都可以根据需要订购。
任何想法如何使我的工作?
答案 0 :(得分:0)
以下代码:
add_filter( 'wpcf7_validate_number*', 'custom_number_confirmation_validation_filter', 20, 2 );
function custom_number_confirmation_validation_filter( $result, $tag ) {
$tag = new WPCF7_Shortcode( $tag );
$var1 = isset( $_POST['your_number1'] ) ? trim( $_POST['your_number1'] ) : '';
$var2 = isset( $_POST['your_number2'] ) ? trim( $_POST['your_number2'] ) : '';
$var3 = isset( $_POST['your_number3'] ) ? trim( $_POST['your_number3'] ) : '';
$var4 = isset( $_POST['your_number4'] ) ? trim( $_POST['your_number4'] ) : '';
$var5 = isset( $_POST['your_number5'] ) ? trim( $_POST['your_number5'] ) : '';
$var6 = isset( $_POST['your_number6'] ) ? trim( $_POST['your_number6'] ) : '';
$varNumber = '2';
if ( $var1 + $var2 + $var3 + $var4 + $var5 + $var6 < $varNumber) {
$result->invalidate( $tag, "Order a minimum of 2!" );
}
return $result;}
将your_number#替换为联系表格7中的字段名称