I use wordpress and woocommerce (an e-commerce plugin) to set up a shopping cart. In my functions.php, I store the data in a variable as follows:
add_action( 'woocommerce_before_calculate_totals', 'add_custom_price' ); function add_custom_price( $cart_object ) { foreach ( $cart_object->cart_contents as $key => $value ) { $newVar = $value['data']->price; } }
I need to be able to use $newVar in another function so that I can repeat the result in a different area of ββthe page. For example, if I had the following function, how would I use $newVar inside it?
add_action( 'another_area', 'function_name' ); function function_name() { echo $newVar; }
How can i do this?
source share