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 get default variation ID (woocommerce)
- How do I fix Undefined variable using $_POST in function?
- Change WooCommerce currency programmatically on AJAX request
- How to add custom attribute to all outofstock and all instock products automatically?
- Site infected by link
- How to empty price of simple and variable product when product changed into out off stock
- Woocommerce – if selected attribute term equals
- split 1 cart item into instock and back ordered
- AJAX to add to cart multiple products woocommerce
- Adding product permalink on admin order page throwing error
- Make WooCommerce product categories only show images on homepage
- How do I remove an action hook inside a class that is called by another class?
- How to create loop inside wordpress function?
- How to change the value of a variable using input field?
- ACF under category name in shop page [closed]
- Need to forward Data from WooCommerce Webhook sent to same site WordPress REST API custom endpoint
- Add Product Permalink in woocommerce admin order page
- Add Shortcode to ::before class
- How to override WooCommerce Order Item Meta with data from Cart?
- sessionStorage saves input value in browser but it is not loaded in the form field
- Woocommerce textarea format ignored
- How to auto-generate random numbers in username?
- i want add conditional for add category in wordpress
- Remove generated category and tag class names from woocommerce product & blog listings markup
- Adding a widget under an ‘Add to Cart’ button through a PHP snippet
- WooCommerce Quantity in Dropdown menu instead of clasic [closed]
- How to get total gross revenue for current month in the woocommerce dashboard status widget
- Add custom attribute to product’s HTML to woocommerce cart page
- Change WooCommerce template for PDF – access to custom field
- WooCommerce get products based on the taxonomy
- WP_Query To Display Product Of Brand On Taxonomy Page
- Woocommerce Add custom “Add to cart button” in single page with tags
- Reverse Cross-Sells (WooCommerce)
- Woocommerce remove menu item on myaccount dashboard
- How can i style “echo apply_filters”
- Hot to edit WooCOmmerce dashboard?
- How to find php variable of wordpress theme settings
- How to echo a PHP code into WooCommerce variation product?
- How can I add another row to the total field in WooCoommerce cart, checkout and recipe mail?
- WooCommerce subcategories help
- Get Billing Email from WooCommece Checkout and Pass to Fullstory JS
- Woocommerce custom attributes list help
- WooCommerce multiple custom fields code
- Get all woocommerce product names with price and show using core php
- Search function not working
- loop to return tags in woocommerce in alphabetical order?
- Woocommerce Related Product by 2 taxonomy
- append data to mysql table via submit button coded in php – not working
- random woocommerce categories are not showing when count enabled?
- Add custom ID attribute to all woocommerce products on archive pages
- Put a span class in the shortened product title
- How to properly create multiple conditions to redirect users roles to different pages
- Add missing alt tag to featured images for “storefront” theme
- WooCommerce – Add Shipping class below each product in Shopping Cart page
- Hide price excluding tax when price is empty
- How to limit functionality of a woocommerce plugin to only certain user role?
- Add class to all meta boxes for a custom post type
- WooCommerce Custom Tab with ACF Repeater Field
- PHP – Woocommerce 3.2 Add variable shipping insurance with multiple “else if ” conditions
- How can i put php code on the wordpress page?
- Sort WooCommerce data with WP-CRON?
- Woocommerce variable products are being added to the card on the homepage (ajax)
- Display specific main Sub Nav on Woocommerce product pages
- How to have more than one ID included in the exclude command?
- Clone the “proceed to cart” button and place it above checkout on the cart page, but only appear display size is 320px
- I was wondering if it’s possible to implement card.js on WordPress
- wp_query beginner
- Global filter not working
- how to display woocomerce description of each category in wordpress? [closed]
- Use PHP code in Menu Admin Section
- Woocommerce variation with radio button + price
- Passing parameter from the current URL to redirect to another url
- WordPress 3.0 PHP Error – notice WordPress_product_Type was called incorrectly
- Display text of price (minus 20%) on every product page in a sentence.
- WooCommerce – Add product category below product price [closed]
- Undefined variable & issue with smof_data
- Pulling a variable into the wp_nav_menu function
- How to detect if a revision was made by woocommerce or wordpress?
- Need Quick Help With Product Category Page
- WooCommerce remove_action and add_action [closed]
- woocommerce plugin bugs
- Woocommerce custom field on emails outputs ‘Array’
- How do I prevent a folder from reappearing in my home directory?
- Display product attributes for current product
- Where can I find the declaration of `$_wp_theme_features`?
- jQuery doesn’t work in my php snippet
- Adding my own custom template page but got white page
- Child theme functions.php file change database entries
- Getting the date_diff function return the difference in days