Display the text (promoted) in only paid ads
-
Hello,
Please this code no longer works
/* ------------------------------------------------------------------------- * * Display PPROMOTED BADGE in Ads /* ------------------------------------------------------------------------- */ 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" );
function print_single_page_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="single-promoted-item-badge" style="background: silver; text-align: center; color: #fff; border: none; ">Promoted Ad</span>'; } } add_action( "adverts_tpl_single_top", "print_single_page_promoted_badge", 50 );
I have this code in my functions.php file
// Disable WPAdverts will use of default Page template on category pages add_action("init", "klein_wpadverts_init", 20); function my_theme_wpadverts_init() { remove_filter('template_include', 'adverts_template_include'); }
/** * Loads WPAdverts templates from current child theme or child-theme directory. * */ function override_templates( $tpl ) { $upload_dir = wp_upload_dir(); $dirs = array(); // first check in parent theme directory $dirs[] = get_stylesheet_directory() . "/wpadverts/"; // if nothing else use default template $dirs[] = ADVERTS_PATH . "/templates/"; // use absolute path in case the full path to the file was passed $dirs[] = dirname( $tpl ) . '/'; $basename = basename( $tpl ); foreach($dirs as $dir) { if( file_exists( $dir . $basename ) ) { return $dir . $basename; } } } add_action("adverts_template_load", "override_templates");
I am using the latest version of woocommerce and wpadverts, the code stopped working after using two custom files
1. list-item.php
2. single.php
Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
- The topic ‘Display the text (promoted) in only paid ads’ is closed to new replies.