[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.
