• Resolved Goudie

    (@goudie35)


    Hello,

    Thank you again for this plugin. I am using automatic schemas and I can’t find how to use the “current” price. I can choose only regular price (even if it’s on sale) or sale price (even if it’s not on sale anymore). How to do that ? I looked at the list of hooks (thanks for that by the way) but my knowledge is limited and I couldn’t get the current price…

Viewing 4 replies - 1 through 4 (of 4 total)
  • 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 2 years ago by Goudie.
    Thread Starter Goudie

    (@goudie35)

    Oops… I see in my logs I have some PHP fatal errors (even if I can’t see them when browsing website ??)

    PHP Fatal error: Uncaught Error: Call to a member function is_on_sale() on null ...

    But it seems working fine … I’m confused

    • This reply was modified 2 years ago by Goudie.
    Thread Starter Goudie

    (@goudie35)

    Unfortunately I can’t edit my previous posts. I understood that the problem appears when a product is added to the cart. Here is the code that seems works, however if it could be checked by the creator of the plugin (or someone who knows better than me)…

    add_filter('seopress_schemas_mapping_select', 'sp_schemas_mapping_select');
    function sp_schemas_mapping_select($select) {
    	$select['Custom'] = [
    		'currentprice' => __('Current price', 'wp-seopress-pro'),
    	];
    	return $select;
    }
    add_filter('seopress_schemas_dyn_variables', 'sp_schemas_dyn_variables');
    function sp_schemas_dyn_variables($vars) {
    	$vars[] = 'currentprice';
    	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) {
    		if( $product->is_on_sale() ) {
            	$values[] = $product->get_sale_price();
    		}
    		else {
    			$values[] = $product->get_regular_price();
    		}
    	}
    	return $values;
    }
    Plugin Author Benjamin Denis

    (@rainbowgeek)

    Hi,

    schemas is a premium feature.

    To respect www.ads-software.com guidelines, please open a support ticket here (if it’s not already done):
    https://www.seopress.org/account/your-tickets/

    Thank you for understanding,

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Schema and regular/sale price’ is closed to new replies.