so this problem has been persisting over the week, i cam here to seeek some help. i have a type of filter set up that searched through the products through the peoduct shortcode in woocomerce and shoows the results. i recieve the data via form and filter throught php. im using checkboxes with array[] names btw example:
<form>
<input type="checkbox" name="piecenum[]" id="piece2" class="nodisplay" value="1 piece">
<input type="checkbox" name="piecenum[]" id="piece3" class="nodisplay" value="2 piece">
<input type="checkbox" name="piecenum[]" id="piece1" class="nodisplay" value="1 piece">
<a href="#filtertop"><input type="submit" name="filtersubmission" value="Apply Filters" class="filtersubmit"></a>
</form>
i then use some php security and then filter
//[product_filter_shop]
function product_filter_shop() {
if ( isset( $_POST['filtersubmission'] ) ) {
// Validate and sanitize input data
$brand_names = filter_var($_POST['brandsfiltername'], FILTER_SANITIZE_STRING);
$season_type = filter_var($_POST['seasonfiltername'], FILTER_SANITIZE_STRING);
$occasion_type = filter_var($_POST['ocassionsfiltername'], FILTER_SANITIZE_STRING);
$material_type = filter_var($_POST['materialfiltername'], FILTER_SANITIZE_STRING);
$embroidery_type = filter_var($_POST['embrdfiltername'], FILTER_SANITIZE_STRING);
$piece_num = filter_var($_POST['piecenum'], FILTER_SANITIZE_STRING);
// Sanitize input data
$brand_names = wp_kses($brand_names, 'post');
$season_type = wp_kses($season_type, 'post');
$occasion_type = wp_kses($occasion_type, 'post');
$material_type = wp_kses($material_type, 'post');
$embroidery_type = wp_kses($embroidery_type, 'post');
$piece_num = wp_kses($piece_num, 'post');
// Setting none and all filters
$all = 'All'; // Define the $all variable
if (strpos($season_type, $all)!== false) {
$season_type = 'Seasons: All Seasons';
}
if (strpos($occasion_type, $all)!== false) {
$occasion_type = 'Occasions: All';
}
//combining some arrays
$attribute_filters = array_merge(...[$season_type, $occasion_type, $material_type, $embroidery_type, $piece_num]);
$args = array(
'category' => $brand_names,
'category_operator' => 'AND'
);
$results = do_shortcode("} category_operator={$args['category_operator']}]");
return $results;
}
else {
// if no filteration occurs
$nofilter = do_shortcode('');
return $nofilter;
}
}
add_shortcode('product_filter_shop', 'product_filter_shop');
i then paste the shortcode in to a page. I know the shortode is working becuse the else{} of the first statement works and i have tried some echos which show up after form submission. But when the first if statement is true and it does do_shortcode
and returns $results it triggers a crtickal error on the page. I tried to get a filtered list of peoducts through the shortcode in woocomerce. But it triggerse a critical error on the page Please can anybody help, i would be very grateful,
Thank you
Asma Mohsin is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
7