• Resolved eirikv

    (@eirikv)


    Hi,

    Just wounder if it’s an easy task to make a snippet adding an extra field
    so I can add “before Price” when I need it, and display it below or beside the
    (field) price in listings templates

    Preferable showing the field adding the correct thousands Separator and
    currency from settings
    (and not only https://docs.wpcasa.com/article/snippet-add-custom-text-from-before-price/)

    Not to over-complicate, it does not need to be searchable

    I use categories to put the listing in “reduced” category.

    • This topic was modified 7 years ago by eirikv.
    • This topic was modified 7 years ago by eirikv.
Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author WPSight

    (@wpsight)

    Hello @eirikv,

    It actually depends what you define as “easy”. Basically you can use the below code and it technically does what you need:

    <?php
    
    /**
     * Add custom text (from) before price
     */
    
    add_filter( 'wpsight_get_listing_price_before', 'custom_get_listing_price_before' );
    
    function custom_get_listing_price_before( $value ) {
    
    	$custom = get_post_meta( get_the_ID(), '_my_custom_field_name', true );
      
      	if( $custom )
            $value .= '<small>' . $custom . '</small> ';
            
        return $value;
      
    }

    This code basically checks if there is a custom field with the name _my_custom_field_name and returns the value if available. You can use the default custom fields metabox in your listing editor to add this field/value manually. If you want to have a proper custom field in the listing price metabox you need to add it with some additional custom code.

    Note: The code above hasn’t been tested, so please use at your own caution. Also: It is a very basic example, you might need to build on top of that.

    All the best

    Thread Starter eirikv

    (@eirikv)

    Thank you very much. Are you available to make some customization?

    As you said, it is a very basic example, I and might need to build on top of that.

    There is a couple of things I would like to get help with ??

    Plugin Author WPSight

    (@wpsight)

    Yes sure. Simply drop us a line through our contact form and let us know what exactly you need.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Adding an addtional field for “Before price”’ is closed to new replies.