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 get default variation ID (woocommerce)
- Get check box values inside array for use in posting form data
- Display one random image from Media Library
- How do I change the “login” label in My Account page to “Registered Customer”
- How do I programmatically add ‘reviews_allowed’ to WooCommerce product?
- Customize the “Available for back order” text for specific variation
- How to remove the replace the product image by video on shop page conditionally
- How can I update the price when someone enters postcode or zip code in woocommerce checkout page?
- Add to cart quantity dynamic
- How to get content on a blank basket/cart page in a custom theme with woocommerce
- Woocommerce checkout page – custom field checkbox value into email
- WooCommerce function not working correctly after moving from the functions.php into a class
- How to display MySQL table data which is stored as an array?
- Filter for product subcategory listing page load
- Global variable doesnt’t pass to another function
- Woocommerce – get daily sales meta
- Custom woocommerce payment gateway – Form
- Exclude category from woocommerce product category list
- WooCommerce REST API AJAX Auth – 401 response
- Looping through and combining calls to Woocommerce REST API
- get_filtered_term_product_counts – Get product terms if any products
- Adding new divs with custom classes to products on WooCommerce shop page [closed]
- Edit woocommerce_product_archive_description using hook
- Get x numbers of a woocommerce category products using Wp_Query
- Get product price in a different currency using WooCommerce Currency Switcher
- Discount in the specific product title using keyword ( Woocoommerce )
- How to import woocommerce custom fields data into another site?
- Including user data in “new user notification email”
- Get field value and use as variable in php
- Place product field value as variable in php
- Set notification if is two product category in cart
- WooCommerce – template_redirect if is_checkout AND order has been paid?
- ACF – Get ID of relationship field in flexible content
- 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?
- Replace an array (with identical values) with another array in the_content
- 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
- Show the subcategory name based on current product
- 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
- How to filter specific element of an array in wordpress/php?
- 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]
- WP post meta – for loop inside for loop
- 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?
- get_category_parents to array
- How to find php variable of wordpress theme settings
- Notice : Array to string conversion on array_intersect user meta
- 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
- Combine multiple queries, array_unique returns nothing