感谢stillatmylinux的掌舵。
如果有人需要类似的东西,下面是我最后使用的代码
// Woocommerce Percentage Saved
function percentager_shortcode($atts)
{
// override default attributes with user attributes
$percentager_atts = shortcode_atts([
\'reg\' => \'500\',
\'sale\' => \'200\'
], $atts);
$added_up = round( ( ( $percentager_atts[\'reg\'] - $percentager_atts[\'sale\'] ) / $percentager_atts[\'reg\'] ) * 100 );
// start output
$o = \'\';
// Words
$o .= esc_html__($added_up, \'percentager\') . \'% Off\';
// return output
return $o;
}
function percentager_shortcodes_init()
{
add_shortcode(\'percentager\', \'percentager_shortcode\');
}
add_action(\'init\', \'percentager_shortcodes_init\');
然后,旋转滑块中使用的短代码:
[percentager reg=“{{meta:\\u regular\\u price}}}”sale=“{{{meta:\\u sale\\u price}}}}”]