This website uses cookies to personalize your experience. By using this website you agree to our cookie policy.

Advanced Description Field

Home Forums Product Support Forums Ajax Search Pro for WordPress Support Advanced Description Field

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #25839
    proha31proha31
    Participant

    Hello, thanks for the great plugin.

    1) I use “_stock” in Advanced Description Field. It works, but zeros are added to the value: 50.000000 or 0.000000. How to remove zeros in value?

    2) Is it possible to use “if-then-else” in Advanced Description Field? I want show Out of Stock message, if “_stock” is 0.

    Thanks, Prokhor.

    #25840
    Ernest MarcinkoErnest Marcinko
    Keymaster

    Hi,

    Can you please copy/paste your current advanced content field here? Thank you!

    #25841
    proha31proha31
    Participant

    <p>SKU: <b>{_sku}</b> | In stock: <b>{_stock}</b>

    #25842
    Ernest MarcinkoErnest Marcinko
    Keymaster

    Hi,

    I assume you probably want to display the stock information whenever the stock is > 0. I have constructed a quick custom code snippet that you should try for that. Try adding this custom code to the functions.php in your theme/child theme directory. Before editing, please make sure to have a full site back-up just in case!

    add_filter( 'asp_results', 'asp_add_stock_count', 10, 1 );
    function asp_add_stock_count($results) {
    	foreach ( $results as $k => &$r ) {
    		$stock = get_post_meta($r->id, '_stock', true);
    		if ( $stock > 0 ) {
    			$stock = intval($stock);
    			$r->content .= " | In stock: $stock</b>"; 
    		}
    	}
    	
    	return $results;
    }

    This should also force the number value to integer, removing the extra zeros.

    #25859
    proha31proha31
    Participant

    Thank you very much, you helped me a lot, everything works! I just rated 5 stars for the plugin.

    #25863
    Ernest MarcinkoErnest Marcinko
    Keymaster

    You cannot access this content.

Viewing 6 posts - 1 through 6 (of 6 total)
  • You must be logged in to reply to this topic.