I think the main issue here is that the calling context of hooks (eg. targets of add_action) are not the same as the functions.php inline code. Also, function parameters come from the calling context, not just because there is a variable of that name in the same file.
This “function enqueue_product_modals($product) ” will not work.
As for use of Woo globals, I believe all of them are deprecated.
Here is how global $product gets set:
includes/wc-template-functions.php:140: unset( $GLOBALS['product'] );
includes/wc-template-functions.php:150: $GLOBALS['product'] = wc_get_product( $post );
includes/wc-template-functions.php:152: return $GLOBALS['product'];
So, you can see the “going forward” way to get the WC_Product object for a given post.
Related Posts:
- Call global variable array() in woocommerce child/template
- Where to get information about array fields in $_REQUEST?
- Cleanest/Fastest way to avoid calling and retrieving data from the database multiple times?
- How to modify a global variable in a function and use it on another function?
- What is the alternative code to if (isset ($_POST) && !empty ($_POST) to avoid warnings?
- Changing the order of custom fields in the dashboard for Woocommerce variable products [closed]
- Custom global variable not working in function
- Hide payment method based on user role AND minimum cart value
- Best way to use variables in multiple functions?
- Reduce Stock Based on Custom Variation Field Rather than Attribute (Working Script)
- How can one use variables in a template or template part without polluting the global scope?
- How to set and use global variables? Or why not to use them at all
- Woocommerce get selected shipping zone id for the current user
- Variables declared in header not available in other includes
- How to change “Shipping Calculator “field label on Cart Page – woocommerce? [closed]
- Filter the blog title displayed in the header
- How to show order data by multiple ID?
- Problem with Woocommerce REST API Authentication
- Remove General Tab and Plugin Tab in Settings in Woocommerce
- WooCommerce – Display variation custom field value [closed]
- Woocommerce HTML email option unavailable
- How to add SVG icon above product tab title
- When would you use $_post instead of $post?
- How to change / delete product short description in Woocommerce
- How to trash multiple post/product programmatically
- OrderItem get_total() returns lower value than $order_item->get_product()->get_price() * quantity
- Setting up 2 SMTP accounts: 1 for wordpress and 1 for woocommerce
- WooCommerce – Reset quantity input field when variation changes
- Custom Text in WooCommerce Order Processing Email Based on Products
- woocommerce subscriptions – get expiration date [closed]
- Automatically remove a canceled order in Woocommerce
- How can I apply_filters from inside a function?
- Pass Category Name, Description and Photo into variables to pass to jQuery
- Different Minimum Order Amounts based on Shipping Zone [closed]
- Displaying Woocommerce Product Category in WordPress
- Displaying custom taxonomy on WooCommerce product page
- Change “add to cart” button color based on Woocommerce product category [closed]
- Add to cart function not working for first product when cart is empty [closed]
- Woocommerce : Can’t get product info in loop
- WooCommerce custom product dimensions
- PHP, Creating a dynamic variable
- Variable not staying set
- Is there a way to hook or call a custom woocomerce template that is not part of the default templates of woocommerce?
- get taxonomy thumbnail and use it as a variable in code
- Single Quotes in .php file doesn’t load website
- Apply class to every third list item? [duplicate]
- How to upload WP user avatar on woocommerce account page [closed]
- How to relocate paypal button gateway on checkout page in woocommerce
- How to pass a variable to get_template_part that’s updated every time the template part is called?
- How to rename woocommerce-billing-fields
- Insert page content into another page with a changed variable
- Only show size attributes in product box woocommerce when available
- How to access or parse key/values that have “string”
- How do I run code every 24 hours?
- Woocommerce Product_cat for current category page
- Create a package of products as one Item in woocommerce?
- After disabling WPML multi currency, the currency is still handled by the WPML
- How do i wrap woocomerce attribute in list?
- Removing files programmatically
- WooCommerce “Checkout Now” button [closed]
- WordPress is removing query variables like page, p from the URL of a custom static page
- Woocommerce. Get a list of products in the current category on the archive page and product page
- How can I enter on the Thank you page in woocommerce the discount code I assigned to the product category?
- Woocommerce append shipping method form
- PHP function for horizontal Woocommerce thumbnails and badges
- Can’t pass var from php wp_ajax into ajax script : result undefined or null
- Set ACF on order during checkout
- WooCommerce display price before add to cart [closed]
- Get the same SKU from woocommerce itself for simple and variable products
- Woocommerce checkout page – custom field checkbox value into email
- WooCommerce function not working correctly after moving from the functions.php into a class
- Filter for product subcategory listing page load
- WooCommerce – template_redirect if is_checkout AND order has been paid?
- AJAX to add to cart multiple products woocommerce
- Make WooCommerce product categories only show images on homepage
- ACF under category name in shop page [closed]
- WooCommerce Quantity in Dropdown menu instead of clasic [closed]
- WP_Query To Display Product Of Brand On Taxonomy Page
- Hot to edit WooCOmmerce dashboard?
- WooCommerce subcategories help
- WooCommerce multiple custom fields code
- Search function not working
- loop to return tags in woocommerce in alphabetical order?
- How to have more than one ID included in the exclude command?
- wp_query beginner
- Woocommerce custom field on emails outputs ‘Array’
- Where can I find the declaration of `$_wp_theme_features`?
- WordPress using get_term to retreive slug not working as expected
- Can’t make product images clickable
- WooCommerce – Print Processing orders [closed]
- Hide cart when empty [closed]
- If I define a variable in header.php, how do I make it available to templates?
- Order woo products, but first products must be with acf fields
- Suppress errors when using global function
- Use ajax response in PHP function
- Warning: Attempt to read property “term_id” on int – Woocommerce
- Grabbing value of input field inside of array
- How to set variable to specific field when querying
- WooCommerce Checkout Cart [closed]
- Woocommerce – add tracking code to another email template