07-27-2023, 08:40 AM
I am using wordpress and woocommerce ( an e-commerce plugin) to customize a shopping cart. Within my functions.php I am storing data in a variable like so:
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 a different function so I can echo the result on a different area of the page. For instance, if I had the following function, how would I use `$newVar` within it?
add_action( 'another_area', 'function_name' );
function function_name() {
echo $newVar;
}
How can I do this?
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 a different function so I can echo the result on a different area of the page. For instance, if I had the following function, how would I use `$newVar` within it?
add_action( 'another_area', 'function_name' );
function function_name() {
echo $newVar;
}
How can I do this?