Search for products only in parent class - wordpress

How do I edit the search form below to search only in a specific category on woocommerce?
<form role="search" method="get" id="searchform" action="http://url-is-here.com">
<div>
<label class="screen-reader-text" for="s">Search for:</label>
<input type="text" value="" name="s" id="s" placeholder="Search for products" />
<input type="submit" id="searchsubmit" value="Search" />
<input type="hidden" name="post_type" value="product" />
</div>
</form>

Did you try:
<form role="search" method="get" id="searchform" action="http://url-is-here.com">
<div>
<label class="screen-reader-text" for="s">Search for:</label>
<input type="text" value="" name="s" id="s" placeholder="Search for products" />
<input type="submit" id="searchsubmit" value="Search" />
<input type="hidden" name="post_type" value="product" />
<input type="hidden" name="cat" id="cat" value="5" />
</div>
</form>
This should limit the results to category with an id of 5.

Related

Why this is showing me nothing in Wordpress?

Why this is show me nothing??
I'm totally lost =(
<?php function calc_shortcode(){ ?>
<div>
<form>
<h3>Price High</h3>
<input name="priceHigh" type="text" />
<h3>Price Low</h3>
<input name="priceLow" type="text" />
<h3>Price Up</h3>
<input name="priceUp" type="text" />
<h3>Price Down</h3>
<input name="priceDown" type="text" /></br>
<input name="submit" type="submit" value="Calculate" class="btn btn-primary" />
</form>
</div>
<?php
}
add_shortcode('calc_pat', 'calc_shortcode');
Thanks for helping guys!
To use shortcode you need to call it. Read more here https://developer.wordpress.org/reference/functions/add_shortcode/ and https://developer.wordpress.org/reference/functions/do_shortcode/
echo do_shortcode('[calc_pat]');
The php labels are wrongly placed there, try doing this:
<?php
function calc_shortcode(){
<div>
<form>
<h3>Price High</h3>
<input name="priceHigh" type="text" />
<h3>Price Low</h3>
<input name="priceLow" type="text" />
<h3>Price Up</h3>
<input name="priceUp" type="text" />
<h3>Price Down</h3>
<input name="priceDown" type="text" /></br>
<input name="submit" type="submit" value="Calculate" class="btn btn-primary" />
</form>
</div>
}
add_shortcode('calc_pat', 'calc_shortcode');
?>
Check if that works
Please give try to below code, it should work:
function calc_shortcode(){
echo '<div>
<form>
<h3>Price High</h3>
<input name="priceHigh" type="text" />
<h3>Price Low</h3>
<input name="priceLow" type="text" />
<h3>Price Up</h3>
<input name="priceUp" type="text" />
<h3>Price Down</h3>
<input name="priceDown" type="text" /></br>
<input name="submit" type="submit" value="Calculate" class="btn btn-primary" />
</form>
</div>';
}
add_shortcode('calc_pat', 'calc_shortcode');
you can also add ob_start(); and ob_get_clean();
Try below code :
<?php function calc_shortcode()
{
ob_start();
?>
<div>
<form>
<h3>Price High</h3>
<input name="priceHigh" type="text" />
<h3>Price Low</h3>
<input name="priceLow" type="text" />
<h3>Price Up</h3>
<input name="priceUp" type="text" />
<h3>Price Down</h3>
<input name="priceDown" type="text" /></br>
<input name="submit" type="submit" value="Calculate" class="btn btn-primary" />
</form>
</div>
<?php
echo ob_get_clean();
die();
}
add_shortcode('calc_pat', 'calc_shortcode');

How to get pop up box after comment submitted in custom comment box?

I made custom file to add comment on posts, this file only contains a comment box. Now I want to show pop up dialogue box when user post a comment, this is my form
<form action="https://m.punjabidharti.com/wp-comments-post.php" method="post" id="commentform">
<p>
<input type="text" name="author" id="author" class="textarea" value="" size="22" tabindex="1" />
<label for="author">
Name </label>
(required)
</p>
<p>
<input type="text" name="email" id="email" value="" size="22" tabindex="2" class="textarea" />
<label for="email">
E-mail </label>
(required)
</p>
<p>
<label for="comment"><strong>Your Comment</strong></label>
<br />
<textarea name="comment" id="comment" cols="50" rows="10" tabindex="4" class="textarea"></textarea>
</p>
<p>
<input name="submit" id="submit" type="submit" tabindex="5" value="submit" class="Cbutton" />
<input type="hidden" name="comment_post_ID" value="<?php echo $_GET["img"]; ?>" />
</p>
<p style="display: none;"><input type="hidden" id="akismet_comment_nonce" name="akismet_comment_nonce" value="9dc14cd05a" /></p>
<p style="display: none;"><input type="hidden" id="ak_js" name="ak_js" value="165" /></p>
<p>Comment moderation is enabled. Your comment may take some time to appear.</p>
</form>

search through multiple categories

I like to search the word through unique multiple categories.
I prepared this code.
<form role="search" class="cat-search" action="<?php bloginfo('url'); ?>" method="get">
<input type="checkbox" value="0" name="cat" id="cat0" /><label for="cat0">all categories</label>
<input type="checkbox" value="1" name="cat" id="cat1" /><label for="cat1">category 1</label>
<input type="checkbox" value="2" name="cat" id="cat2" /><label for="cat2">category 2</label>
<input type="checkbox" value="3" name="cat" id="cat3" /><label for="cat2">category 3</label>
<input type="checkbox" value="4" name="cat" id="cat4" /><label for="cat2">category 4</label>
<input type="checkbox" value="5" name="cat" id="cat5" /><label for="cat2">category 5</label>
<input name="s" size="25" type="text" placeholder="search after select categories" />
<input type="submit" class="cat-search" value="search" />
</form>
When I try to search "word" with categories 1 and 2, url is becoming like this.
/?cat=1&cat=2&s=word
Is there any way to change it to this url?
/?cat=1,2&s=words
jQuery Comes handy with these,
remove name attributes on all those checkboxes and add hidden input for cat, then populate its value based on checkboxes
<form role="search" class="cat-search" action="<?php bloginfo('url'); ?>" method="get">
<input type="checkbox" value="0" id="cat0" class="cats"/><label for="cat0">all categories</label>
<input type="checkbox" value="1" id="cat1" class="cats"/><label for="cat1">category 1</label>
<input type="checkbox" value="2" id="cat2" class="cats"/><label for="cat2">category 2</label>
<input type="checkbox" value="3" id="cat3" class="cats"/><label for="cat3">category 3</label>
<input type="checkbox" value="4" id="cat4" class="cats"/><label for="cat4">category 4</label>
<input type="checkbox" value="5" id="cat5" class="cats"/><label for="cat5">category 5</label>
<input type="hidden" id="cat" name="cat" />
<input name="s" size="25" type="text" placeholder="search after select categories" />
<input type="submit" class="cat-search" value="search" />
</form>
Then your jQuery to assign value to hidden inputs when checkboxes are click
$('body').on('click', '.cats', function() {
var cats = $('.cats:checked').map( function() {
return this.value;
}).get().join(",");
$('#cat').val( cats );
});
Just a note, the comma (,) in the url will be encoded and would look something like
yoursite.com/?cat=0%2C1%2C2%2C3%2C4&s=bah
although this shouldn't matter if you're processing the value on php

Set a Virtual Page View with Universal GA

This is my HTML from. and i'm trying to set a Virtual Page View when submitting the form but i just can't make it work.
Pls advice
<form id="frmContact" action="post.php" method="post">
<div class="form-right-pnl">
<input type="text" class="required name" size="40" placeholder="×©× ×ž×œ×:" name="full_name">
<input type="text" class="required phone" size="40" placeholder="טלפון:" name="phone">
<input type="text" class="required email" size="40" placeholder='דו×"ל:' name="email">
<span>מ×שר קבלת ×—×•×ž×¨×™× ×¤×¨×¡×•×ž×™×™×</span>
<input type="checkbox" class="radio_btn" name="selling_a_property" checked value="Yes"/>
</div>
<div class="form-left-pnl" id='basic-modal'>
<input class="ddl_list" type="submit" value="" onClick=”_gaq.push([‘_trackEvent’, ‘Forms’, ‘Submit’]);” />
</div>
<div class="clear"></div>
</form>
Change this line
<input class="ddl_list" type="submit" value="" onClick=”_gaq.push([‘_trackEvent’, ‘Forms’, ‘Submit’]);” />
for
<input class="ddl_list" type="submit" value="" onClick=”_gaq.push(['_trackPageview', '/virtual-page-view-on-click-submit-button']);” />

WP e-commerce remove button

For adding a product to cart by id I've got this code:
<form class="product_form" enctype="multipart/form-data" action="<?php bloginfo('url');?>" method="post" name="1" id="product_143">
<input type="hidden" value="add_to_cart" name="wpsc_ajax_action">
<input type="hidden" value="143" name="product_id">
<button>+</button>
Is there a code to remove a item by id?
I've tried this:
<form action="<?php bloginfo('url');?>" method="post" class="adjustform remove">
<input type="hidden" name="quantity" value="0">
<input type="hidden" name="key" value="0">
<input type="hidden" name="wpsc_update_quantity" value="true">
<input type="submit" value="-">
</form>
But this removes the first item in the cart.

Resources