• Resolved edaas

    (@edaas)


    Hi,

    I have a shortcode for displaying the price of a product (variant) → [woocommerce_price id=”XXXX”]. I use it in text and in some pricing tables.

    I have monthly and yearly subscriptions.

    I ould love to compare the monthly prices next to each other, so the discount for yearly is more prominent.

    Is it possible to create another shortcode that divides [woocommerce_price id=”XXXX”] by 12?

    This is my current shortcoode

    function so_30165014_price_shortcode_callback( $atts ) {
        $atts = shortcode_atts( array(
            'id' => null,
        ), $atts, 'bartag' );
    
        $html = '';
    
        if( intval( $atts['id'] ) > 0 && function_exists( 'wc_get_product' ) ){
             $_product = wc_get_product( $atts['id'] );
             $html = "€ = " . $_product->get_price();
        }
        return $html;
    }
    add_shortcode( 'woocommerce_price', 'so_30165014_price_shortcode_callback' );

    Thanks in advanced!
    – Jan

Viewing 1 replies (of 1 total)
  • Plugin Support mouli a11n

    (@mouli)

    @edaas
    Unfortunately I am not a developer but looking at your code, do you think that something like this would get close:

    $price = $_product->get_price();
    $price = ($price/12);
    $html = “€ = ” . $price;

    I hope that helps you to figure it out.
    Feel free to get back to us if you have further questions.

Viewing 1 replies (of 1 total)
  • The topic ‘Can I apply mathematic formula on values from shortcodes?’ is closed to new replies.