where does $checkout in form-checkout.php woocommerce come from?

Closed. This question is off-topic. It is not currently accepting answers.Your question should be specific to WordPress.

Closed. This question is off-topic. It is not currently accepting answers.

Your question should be specific to WordPress. Generic PHP/JS/SQL/HTML/CSS questions might be better asked at Stack Overflow or another appropriate Stack Exchange network site. Third-party plugins and themes are off-topic for this site; they are better asked about at their developers' support routes.

Closed 4 years ago.

Improve this question

I am trying to figure out how to pass variables across files in wordpress and came across this little code here in form-checkout.php woocommerce.

do_action( 'woocommerce_before_checkout_form', $checkout );

// If checkout registration is disabled and not logged in, the user cannot checkout.
if ( ! $checkout->is_registration_enabled() && $checkout->is_registration_required() && ! is_user_logged_in() ) {
    echo esc_html( apply_filters( 'woocommerce_checkout_must_be_logged_in_message', __( 'You must be logged in to checkout.', 'woocommerce' ) ) );
    return;
}

The variable $checkout is not defined in the file, seems to come from different file but I cannot find any include which tracks the variable to its origin.

Just wondering how to pass variables across files without include or require, Not sure if this is wordpress specific or PHP related, but if anybody could help, I would really appreciate it.

Thanks in advance !!

Closed. This question is off-topic. It is not currently accepting answers.

Your question should be specific to WordPress. Generic PHP/JS/SQL/HTML/CSS questions might be better asked at Stack Overflow or another appropriate Stack Exchange network site. Third-party plugins and themes are off-topic for this site; they are better asked about at their developers' support routes.

Closed 4 years ago.

Improve this question

I am trying to figure out how to pass variables across files in wordpress and came across this little code here in form-checkout.php woocommerce.

do_action( 'woocommerce_before_checkout_form', $checkout );

// If checkout registration is disabled and not logged in, the user cannot checkout.
if ( ! $checkout->is_registration_enabled() && $checkout->is_registration_required() && ! is_user_logged_in() ) {
    echo esc_html( apply_filters( 'woocommerce_checkout_must_be_logged_in_message', __( 'You must be logged in to checkout.', 'woocommerce' ) ) );
    return;
}

The variable $checkout is not defined in the file, seems to come from different file but I cannot find any include which tracks the variable to its origin.

Just wondering how to pass variables across files without include or require, Not sure if this is wordpress specific or PHP related, but if anybody could help, I would really appreciate it.

Thanks in advance !!

Share Improve this question asked Jul 1, 2020 at 7:53 QuestoQuesto 31 bronze badge
Add a comment  | 

1 Answer 1

Reset to default 0

It's set by the code that includes the template, and is in-scope when the file is included - from the include documentation:

When a file is included, the code it contains inherits the variable scope of the line on which the include occurs. Any variables available at that line in the calling file will be available within the called file, from that point forward.

form-checkout isn't used in isolation, it's included from another class with wc_get_template:

wc_get_template( 'checkout/form-checkout.php', array( 'checkout' => $checkout ) );

and that argument becomes $checkout: wc_get_template calls extract on that array before it does the actual include to generate $checkout in-scope.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1742302884a4418366.html

相关推荐

  • where does $checkout in form-checkout.php woocommerce come from?

    Closed. This question is off-topic. It is not currently accepting answers.Your question should be specific to WordPress.

    21小时前
    10

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信