Replace the Price with Sold tag for sold ClassiPress Ads

Currently, ClassiPress theme displays a “Sold” warning on the single ad page. But it’s not reflected on the ad in loops and doesn’t show any warning or sold tag.

Following code snippet replaces the Price with Sold tag for ads marked sold.

ClassiPress Sold Tag
ClassiPress Sold Tag example

You can add it in a custom plugin or child theme functions.php file or use Code Snippets plugin (more details in the instruction).

/**
 * Adds the ad price field in the loop before the ad title.
 *
 * For sold ads replaces price with SOLD tag.
 *
 * @return void
 */
function arthemes_ad_loop_price() {
	global $post;

	if ( APP_POST_TYPE !== $post->post_type ) {
		return;
	}

	// Display Price tag for non-sold ads.
	if ( 'yes' !== $post->cp_ad_sold ) {
		cp_ad_loop_price();
		return;
	}
?>
	<div class="price-wrap sold-wrap">
		<span class="tag-head"><span class="post-price"><?php esc_html_e( 'Sold', APP_TD ); ?></span></span>
	</div>
<?php
}
remove_action( 'cp_listing_item_head', 'cp_ad_loop_price', 9 );
add_action( 'cp_listing_item_head', 'arthemes_ad_loop_price', 9 );

/**
 * Adds inline styles after the main theme CSS file.
 */
function arthemes_add_sold_tag_styles() {
	$css = "
		.price-wrap.sold-wrap .tag-head {
			background: transparent;
			border: 1px solid #565656;
			color: #565656;
			text-transform: uppercase;
			padding: 0 10px 0 10px;
		}
		.price-wrap.sold-wrap .tag-head:after {
			display:none;
		}
	";

	wp_add_inline_style( 'at-main', $css );
}
add_action( 'wp_enqueue_scripts', 'arthemes_add_sold_tag_styles' );