• Resolved captaincrispycrunch

    (@captaincrispycrunch)


    Hi Greg,

    We are using the “Empty Field Text”-Option to insert the text “negotiable”.
    But in case someone whats to give away something for free, the user should be able to input 0,00€.

    Is there any workaround or filter?

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author Greg Winiarski

    (@gwin)

    Hi,
    hmm i am afraid the WPAdverts is not really prepared for such use case.

    I would suggest something else. Using Custom Fields extension you can add a checkbox field with label “The price is negotiable” then using adverts_get_the_price or adverts_empty_price filter it will be possible to check if the checkbox was checked and then show negotiable.

    I think this actually might make more sense as the user might want to enter $100 as a price but also mark it as negotiable?

    Thread Starter captaincrispycrunch

    (@captaincrispycrunch)

    Hi Greg,

    thanks for your suggestion, it inspired me to take another approach.
    I created an additional category called “Free Give Away” which hides the pricing field in the add-form when selected.

    But the second part gave me a hard time, couldn’t figure out how to filter for the category/taxo ID (568). So I took a part of code from the single.php, to use it as div class, to change the “empty field text” into “give away” with a jQuery match.

    Not my proudest moment but it works.
    Maybe you could give me a bump into the right direction ??

    
    <?php $advert_category = get_the_terms($post_id, 'advert_category') ?>
    <?php if (!empty($advert_category)): ?> 
    
          <?php foreach ($advert_category as $c): ?>    
          <div class="<?php echo join(" / ", advert_category_path($c)) ?>">
    
                <?php $price = get_post_meta(get_the_ID() , "adverts_price", true) ?>
                <?php if ($price): ?>
                <div class="advert-price"><?php echo esc_html(adverts_get_the_price(get_the_ID() , $price)) ?></div>
                <?php elseif (adverts_config('empty_price')): ?>
                <div class="advert-price adverts-price-empty">
                <?php echo esc_html(adverts_empty_price(get_the_ID())) ?></div>
                <?php endif; ?>
                </div>
          
          <?php endforeach; ?>  
             
    <?php endif; ?>
    
    Plugin Author Greg Winiarski

    (@gwin)

    Hi,
    hmm so if i understand correctly, when Ad is assigned to the category with id 568 the empty price text should show?

    If so then you should be able to do that using the code below

    
    add_filter( "get_post_metadata", function( $value, $object_id, $meta_key ) {
        if( ! is_singular( 'advert' ) && ! is_page( adverts_config( "ads_list_id" ) ) ) {
            return $value;
        }
        if( $meta_key == "adverts_price" ) {
            $terms = wp_get_post_terms( $object_id, 'advert_category', array( 'fields' => 'ids' ) );
            if(in_array( 568, $terms )) {
                return 0;
            }
        }
        return $value;
    }, 10, 3 );
    

    If you want to differentiate between empty price and Ad assigned to category with ID 568 then you can change line return 0; to return -1 and additionally use the below code

    
    add_filter( "adverts_get_the_price", function( $price, $price_raw, $post_id ) {
        if( $price_raw == -1 ) {
            $price = "Negotiable.";
        }
        return $price;
    }, 1000, 3 );
    
    Thread Starter captaincrispycrunch

    (@captaincrispycrunch)

    Thanks, I was able to make it work.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘0,00€ converts to “Empty Field Text” ?’ is closed to new replies.