更新时间:2023-11-09 23:26:22
You could make the variable global:
function add_custom_price( $cart_object ) {
global $newVar;
foreach ( $cart_object->cart_contents as $key => $value ) {
$newVar = $value['data']->price;
}
}
function function_name() {
global $newVar;
echo $newVar;
}
Or, if $newVar
is already available in the global scope you could do:
function function_name($newVar) {
echo $newVar;
}
// Add the hook
add_action( 'another_area', 'function_name' );
// Trigger the hook with the $newVar;
do_action('another_area', $newVar);