Schema and regular/sale price | WordPress.org

[ad_1]

Thread Starter
Goudie

(@goudie35)

Wow! I nailed it all by myself!

Using the documentation hook and a basic conditional. Here is the complete code used (in functions.php) to add the “Real price” option in the list:

add_filter('seopress_schemas_mapping_select', 'sp_schemas_mapping_select');
function sp_schemas_mapping_select($select) {
	$select['Custom'] = [
		'realprice' => __('Real price', 'wp-seopress-pro'),
	];
	return $select;
}
add_filter('seopress_schemas_dyn_variables', 'sp_schemas_dyn_variables');
function sp_schemas_dyn_variables($vars) {
	$vars[] = 'realprice';
	return $vars;
}
add_filter('seopress_schemas_dyn_variables_replace', 'sp_schemas_dyn_variables_replace');
function sp_schemas_dyn_variables_replace($values) {
	global $product;
	if( $product->is_on_sale() ) {
        $values[] = $product->get_sale_price();
    }
    else {
		$values[] = $product->get_regular_price();
	}
	return $values;
}

PS: Adding this default variable would be a good idea (maybe I missed something? 😳)

  • This reply was modified 1 minute ago by Goudie.

 

This site will teach you how to build a WordPress website for beginners. We will cover everything from installing WordPress to adding pages, posts, and images to your site. You will learn how to customize your site with themes and plugins, as well as how to market your site online.

Buy WordPress Transfer