It is all fine. You just need to declare variable global first then you can set the value of this and access globally.
function my_free_shipping( $is_available ) {
global $woocommerce, $product_notfree_ship;
// set the product ids that are $product_notfree_ship
$product_notfree_ship = array( '1', '2', '3', '4', '5' );
Then again declare it globally when using again in another file
global $product_notfree_ship;
if ( is_single($product_notfree_ship) ) {
echo 'Additional Shipping Charges Apply';
} else {
echo 'FREE SHIPPING on This Product';
}
This is how global variable works.
Related Posts:
- global $product is empty string when passed into function
- Where to get information about array fields in $_REQUEST?
- How to store the_title() into a variable to reutrn the value, not just echo it
- Cleanest/Fastest way to avoid calling and retrieving data from the database multiple times?
- Listing and displaying WooCommerce Shipping Zones in the frontend? [closed]
- Using a variable in is_page(array())
- 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?
- How to access or parse key/values that have “string”
- Changing the order of custom fields in the dashboard for Woocommerce variable products [closed]
- Dynamically adding filters
- Convert a column of a table containing an Array as response in HTML
- Custom global variable not working in function
- Hide payment method based on user role AND minimum cart value
- How can I show how much water got saved on this order (making use of the number of items bought) on a thank-you-page?
- Best way to use variables in multiple functions?
- Reduce Stock Based on Custom Variation Field Rather than Attribute (Working Script)
- PHP Use Declared array Variable inside already Declared Array
- Grabbing value of input field inside of array
- How can one use variables in a template or template part without polluting the global scope?
- How to add product in woocommerce with php code [closed]
- How to add date range in woocommerce with code
- Creating custom Woocommerce attribute taxonomies from a plugin
- Metabox repeating fields – radio buttons not saving correctly
- How can merge two arrays values in one array and save in database
- WooCommerce: How to display item meta data in email confirmation using woocommerce_order_item_meta_end
- How to get the original price of the product in woocommerce?
- How to Remove a Filter from the Admin List Table?
- Compare two meta key values against each other inside the get_posts array?
- Woocommerce, recognize the loop of related products
- Remove commas from WooCommerce checkout addresses fields
- WooCommerce Link to Product Category
- using woocommerce_template_single_add_to_cart in shop-loop – javascript issues [closed]
- Can an array be used as a meta_query value?
- Writing scripts using WordPress / WooCommerce classes?
- How to make custom total price reactive in navigation
- Change description on specific WooCommerce product status change
- Woocommerce – Filter Variable Products by Variation Attributes and Variations Regular Price
- How to add a second ‘place order’ button in WooCommerce [closed]
- Create shortcodes within foreach loop (using array)
- Woocommerce redirect thankyou page based on product ID doesn’t empty Cart
- tracking number field in Woocommerce order [closed]
- WooCommerce Related Products by Attribute
- Image as Sales Badge
- Pass variable from one function to another
- Woocommerce product variation backorder
- Status 400 for AJAX POST Request with admin-ajax.php
- WooCommerce: How can I get orders with a custom ID in order meta data object?
- How to add specific meta tags to head of cart and checkout pages in woocommerce?
- Woocommerce change prices for a certain country [closed]
- Extend Woocommerce Widget Class – WC_Widget_Product_Categories
- persist a variable set in header.php all the way down to footer.php
- Remove item in Checkout
- Woocommerce – get_items() returns empty array
- Include js script ONLY on woocommerce product category pages? [closed]
- WP_Query multiple post results
- Convert Featured products loop into Recent products loop?
- How to reference PHP in Javascript
- echo var into wp_query
- Payment field disappears on custom Paypal plugin
- Creating a brand attribute as a variable
- How do I set a hidden field to a value?
- How to remove Login from in my account page
- I am having errors with checkout on wordpress
- How to access specific product id on other pages/posts?
- Programmatically add a product to the cart and set price to zero when buying from certain category
- I want to show cart items number if any or nothing, simple CART text
- How to retrieve quantity input field by id in woocommerce
- Using zip code to display custom data in Admin Order Details
- How can I update the price when someone enters postcode or zip code in woocommerce checkout page?
- ACF – Get ID of relationship field in flexible content
- How do I remove an action hook inside a class that is called by another class?
- i want add conditional for add category in wordpress
- Woocommerce remove menu item on myaccount dashboard
- append data to mysql table via submit button coded in php – not working
- random woocommerce categories are not showing when count enabled?
- PHP – Woocommerce 3.2 Add variable shipping insurance with multiple “else if ” conditions
- how to display woocomerce description of each category in wordpress? [closed]
- WordPress 3.0 PHP Error – notice WordPress_product_Type was called incorrectly
- WooCommerce – Add product category below product price [closed]
- woocommerce plugin bugs
- Adding my own custom template page but got white page
- Custom Taxonomy Link Text Echo Name Not Slug
- Page returning ID from array, how to return the correct values for post in acf wordpress
- Woocommerce Price Text
- Unserializeing multiple column values that are stored in one database results variable
- get_permalink returning first letter
- Ajax Load More or View More functionality for woocommerce category layout by template overriding
- wc_add_notice not working on cart page
- ACF | WooCommerce | Theme Development | How to include a /template-part/ that makes use of ACF’s on a custom WooCommerce homepage?
- Woocommerce – Shipping tax class based on cart items not using the highest tax available
- How do I update product shipping using PHP in WooCommerce?
- How can I edit the WooCommerce Mini DropDown Cart to read as follows
- WordPress 6.1.1 UTF8 Slug Limit Increase
- How to group by column a and sum column b and c in a php array
- Woocommerce Convert existing order to the cart
- How to change shipping method title based on cart amount?
- How to add SKU and remove product title from WooCommerce url?
- Product Search in search.php
- using custom pages for myaccount in woocommerce