Search code examples
phpwordpresswoocommercedivide

Divide a number that is being echoed by 2


I'm using a composite product plugin for Woocommerce and Wordpress and am simply trying to make the price echoed in the highlighted line divide by 2 and display that value (the divided value instead of the whole value).

Here is the code:

            <option data-title="<?php echo get_the_title( $product_id ); ?>" value="<?php echo $product_id; ?>" <?php echo selected( $selected_value, $product_id, false ); ?>><?php

            if ( $quantity_min == $quantity_max && $quantity_min > 1 )
                $quantity = ' &times; ' . $quantity_min;
            else
                $quantity = '';

            echo get_the_title( $product_id ) . $quantity;

        ->->    echo $product->get_composited_item_price_string( $component_id, $product_id );

        ?>
        </option>     

Here is the line that I would like to be divided by two and then displayed (there are arrows next to it above).

echo $product->get_composited_item_price_string( $component_id, $product_id );

Thanks in advance for any help you can provide, it's much appreciated!


Solution

  • depending on what you want ( a float or an integer ) use the following :

    echo intval($product->get_composited_item_price_string( $component_id, $product_id )) / 2;
    
    echo floatval($product->get_composited_item_price_string( $component_id, $product_id )) / 2;