• Resolved teeboy4real

    (@teeboy4real)


    Hello,

    Please how can I display the text (promoted) or (sponsored) for paid listings I am using the woocommerce addon to handle payments.

    Thanks

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

    (@gwin)

    Hi,
    where exactly do you want to show this text and which ads should have it?

    Thread Starter teeboy4real

    (@teeboy4real)

    I want to display the text in the ad directory and ad details page and only premium(paid) ads should have it.

    Plugin Author Greg Winiarski

    (@gwin)

    If the paid ad is also featured then you can display such text on the ads list by adding the code below in your theme functions.php file

    
    add_action( "adverts_list_after_title", function( $post_id ) {
        $post = get_post( $post_id );
        if( $post->menu_order < 1 ) {
            return;
        }
        echo '<span style="position:absolute; top: 5px; right: 5px; background: silver; ">Promoted</span>';
    } );
    

    It is possible to display it on the Ad details page as well, but how to do that depends on where you would actually like to show it?

    Thread Starter teeboy4real

    (@teeboy4real)

    1. Will the code work also for paid ads that are not featured?

    2. In the ad details page I want it to display below the Price or below the author

    Also please add a CSS class so I can style the text

    Plugin Author Greg Winiarski

    (@gwin)

    Hi,
    1. this will work only with featured ads if you want it to work with any paid Ad then it is possible, but i would need to know if you are using Payments Module or WooCommerce integration to charge users?

    2. there isn’t a filter or action to do that so the only way to have this label there would be to insert the code directly in the wpadverts/templates/single.php template file, but note the changes you will make in the single.php will be overwritten on WPAdverts update.

    Thread Starter teeboy4real

    (@teeboy4real)

    I want it to work with any paid ad. I am using the woocommerce integration to charge users.

    Thanks

    Plugin Author Greg Winiarski

    (@gwin)

    To show the badge on any paid Ad you can replace the code i sent previously with the one below

    
    add_action( "adverts_list_after_title", function( $post_id ) {
        $pricing_id = get_post_meta( $post_id, "payments_listing_type", true );
        $product = wc_get_product( $pricing_id );
    
        if( ! is_object( $product ) ) {
            return;
        }
    
        if($product->get_price() > 0) {
            echo '<span class="promoted-item-badge" style="position:absolute; top: 5px; right: 5px; background: silver; ">Promoted</span>';
        }
    } );
    
    Thread Starter teeboy4real

    (@teeboy4real)

    Thanks so much the code worked perfectly.
    I hope a filter or action is added in future versions of WP Adverts so the second request can be added in single-php

    teeboy4real:

    This is what I use in the detail section on the ad listing page. It works for me, but if there’s a problem using this I’m sure Greg will let us know.

    add_action( "adverts_tpl_single_details", function( $post_id ) {
        $pricing_id = get_post_meta( $post_id, "payments_listing_type", true );
        $product = wc_get_product( $pricing_id );
    
        if( ! is_object( $product ) ) {
            return;
        }
    
        if($product->get_price() > 0) {
            echo '<div align="right"><span class="promoted-item-badge" style="background: silver; padding: 5px 7px; font-size: 17px; text-align: center; color: #fff; border: none; border-radius: 15px; max-width: 277px; ">Promoted</span></div>';
        }
    } );

    Greg:

    How do I fix this in mobile view? maybe put it before the price

    screenshot
    https://www.screenpresso.com/cloud/sFoqd/

    Thanks
    Norman

    Plugin Author Greg Winiarski

    (@gwin)

    Hi,
    the “promoted” text is aligned with absolute units so it impossible fit it exactly next to the price (as the price box width will change depending on how long the price is).

    In the list view on mobile devices, i would advise aligning it either to left or right with no margins, i think this is the best you can do with the filter available in [adverts_list].

    Thread Starter teeboy4real

    (@teeboy4real)

    Hi

    This css code worked for me

    .promoted-item-badge {
        background: #00aac4 !important;
        padding: 1px 8px 2px 8px;
        color: #fff;
        border-radius: 2px;
        font-size: 13px;
        font-weight: 500;
    }
    
    .advert-item-col-1 .promoted-item-badge {
        background: none !important;
        color: #00aac4;
        font-size: 14px;
        font-weight: 500;
        position: inherit !important;
        margin-left: 5px;
    }
    • This reply was modified 4 years, 5 months ago by teeboy4real.
    Thread Starter teeboy4real

    (@teeboy4real)

    @gwin

    What if you only want to display the text for only paid FEATURED ADS using the code below. How can I apply the code to only FEATURED ADS using the woocommerce integration instead of any paid ads.

    add_action( "adverts_list_after_title", function( $post_id ) {
        $pricing_id = get_post_meta( $post_id, "payments_listing_type", true );
        $product = wc_get_product( $pricing_id );
    
        if( ! is_object( $product ) ) {
            return;
        }
    
        if($product->get_price() > 0) {
            echo '<span class="promoted-item-badge" style="position:absolute; top: 5px; right: 5px; background: silver; ">Promoted</span>';
        }
    } );

    Thanks

    Thread Starter teeboy4real

    (@teeboy4real)

    I tried the code below it seemed to work, but now how can I apply the code below to the ad details pages using (adverts_tpl_single_details) instead of (adverts_list_after_title)

    add_action( "adverts_list_after_title", function( $post_id ) {
        $pricing_id = get_post_meta( $post_id, "payments_listing_type", true );
        $product = wc_get_product( $pricing_id );
        $post = get_post( $post_id );
    
        if( ! is_object( $product ) ) {
            return;
        }
    	
    	if( $post->menu_order < 1 ) {
            return;
        }
    
        if($product->get_price() > 0) {
            echo '<span class="promoted-item-badge" style="position:absolute; top: 5px; right: 5px; background: silver; ">Promoted</span>';
        }
    } );

    Thanks

    • This reply was modified 4 years, 5 months ago by teeboy4real.
    Plugin Author Greg Winiarski

    (@gwin)

    First, update your code to look like this

    
    function print_promoted_badge( $post_id ) {
        $pricing_id = get_post_meta( $post_id, "payments_listing_type", true );
        $product = wc_get_product( $pricing_id );
        $post = get_post( $post_id );
    
        if( ! is_object( $product ) ) {
            return;
        }
    	
    	if( $post->menu_order < 1 ) {
            return;
        }
    
        if($product->get_price() > 0) {
            echo '<span class="promoted-item-badge" style="position:absolute; top: 5px; right: 5px; background: silver; ">Promoted</span>';
        }
    }
    add_action( "adverts_list_after_title", "print_promoted_badge" );
    

    Now you can display the badge before the gallery or after the content table by adding to it (at the end) one the lines below

    
    add_action( "adverts_tpl_single_top", "print_promoted_badge" );
    add_action( "adverts_tpl_single_details", "print_promoted_badge" );
    
    Thread Starter teeboy4real

    (@teeboy4real)

    Thank you so much Greg

    The problem is now solved thanks for your patience

Viewing 15 replies - 1 through 15 (of 15 total)
  • The topic ‘How to display the text (promoted) in only paid ads’ is closed to new replies.