Php 如何在Wordpress中访问另一个函数和插件中的变量

Php 如何在Wordpress中访问另一个函数和插件中的变量,php,wordpress,woocommerce,Php,Wordpress,Woocommerce,我试图从一个函数中访问另一个函数中的变量,但结果一无所获 第一个功能是: add_action( 'woocommerce_admin_order_data_after_billing_address', 'display_custom_field_on_order_edit_pages', 10, 1 ); function display_custom_field_on_order_edit_pages( $order ){ global $my_field_name; $my_field_

我试图从一个函数中访问另一个函数中的变量,但结果一无所获

第一个功能是:

add_action( 'woocommerce_admin_order_data_after_billing_address', 'display_custom_field_on_order_edit_pages', 10, 1 );
function display_custom_field_on_order_edit_pages( $order ){
global $my_field_name;
$my_field_name = get_post_meta( $order->get_id(), 'my_field_name', true );
if( $my_field_name == 1 )
    echo '<p><strong>Фирменный пакет: </strong> <span style="color:red;">Добавить</span></p>';
    global $form_name;
$form_name = "Test form 1";
echo $form_name;
}

是否有其他方法来声明全局变量?或者以其他方式访问其他插件中的$form\u name?

您可以设置如下全局变量:

$GLOBALS['foo']='bar'

然后,您应该能够从以下其他函数中访问该变量:

$foo=$GLOBALS['foo']


阅读有关PHP中全局变量的更多信息

您可以设置如下全局变量:

$GLOBALS['foo']='bar'

然后,您应该能够从以下其他函数中访问该变量:

$foo=$GLOBALS['foo']

阅读有关PHP中全局变量的更多信息

if( function_exists( 'YITH_PDF_Invoice' ) ){
if( ! function_exists( 'yith_ywpi_print_document_notes' ) ){
    function yith_ywpi_print_document_notes( $notes, $document ){
        if( is_object( $document ) && ! empty( $document->order ) && $document->order instanceof WC_Order){
            /**
             * @var $order WC_Order
             */
            $order = $document->order;
            $shipping_info = $form_name;
            $notes .= $shipping_info;
           }
        return $notes;

    }
}
add_filter( 'yith_ywpi_print_document_notes', 'yith_ywpi_print_document_notes', 10, 2 );