I am changing the text of the Add to cart button on shop pages in WooCommerce for specific products: If I have two or more IDs that need to have the same button text, how can I add an array of these ids into my function? Answer You can use in_array() PHP conditional function like: It should work. Also you
Tag: product
Display content on WooCommerce single products based on product categories when they have child categories
I am trying to display the test div below on any product page that is in the category cat1title or cat2title. Using the hook below, which I thought was correct, I should be seeing this div on the page but I am not seeing it at all. The page displays just fine but no div. No errors in the console
Filter a custom product loop to get products from a category in WooCommerce
I have this function which calls me all products type “promotion_package” in WooCommerce: I would like to get only products from “vip” product category. I tried using $product->get_categories() to find “vip” category, but it didn’t worked. How can I show only products from “vip” category? Answer You can try has_term() conditional function for ‘product_cat’ procuct category taxonomy as follows: It
Woocommerce Additional Information Tab: Adding product custom field value
I have the following code working to create the Additional information tab in woocommerce with my own values however I want to pull the information from the built-in product custom field. This is the current code I use to output the custom field, how do I output this in Value 1 in functions.php file in the working code above? Answer
Add the ean code (gtin) in the structured data of the product (Schema.org) in WooCommerce
I am using this snippet to display ean value for gtin in Woocommerce’s product schema: This works but I need to set “identifier_exists” markup to products that don’t have the custom field ean set. How can I modify my snippet to show the ean value in the markup if it exists, and add the identifier_exists attribute = false to products
Issue when adding product description at WooCommerce checkout
I’m trying to display the product description at WooCommerce checkout. I’m using: It takes the product short description and displays it below the product. It almost works perfectly, but it displays a colon (:) at the end of the description and the colon remains even if there is no short description. Result: I can’t figure out why it appears any
Check if customer has purchased something and add product to cart in WooCommerce
The code below auto add a product to cart in WooCommerce: The answer Checking if customer has already bought something in WooCommerce allows to check if user has already make a purchase or not with a custom conditional function has_bought(). So what I would like is to check if the customer has ordered before and: If it’s their first order,
How to make a redirection to checkout on a custom add to cart button in WooCommerce
I’m using WooCommerce and added the following code to functions.php: What I would expect is that when a user adds a product to their basket: this code will redirect the user to the checkout page without actually adding the product to the basket. However, it still adds the product to the basket. What is wrong with this code? Background: I’m
Issue with WooCommerce WC_Product set_category_ids() method in ACF “acf/save_post” hook
I have a problem assigning a product category to a Woocommerce product that I create with Php. (Environment is Wordpress 5.6.1, Woocommerce 5.0, Php 7.4.14, ACF Pro 5.9.5, Oxygen 3.6.1) All other attributes for the product gets saved while creating it, and I can see that the product object get updated with the category id prior to saving. However, when
Get only one product category term for a WooCommerce product
I have a mystery with the categories from WooCommerce. For different products I have multiple categories. For example the product Nike Air Red I connect this product with two categories Brands->Nike and Shoes->Red Brands and Shoes are main categories and Nike and Red are subcategories. On the product page I have the following code The output is NikeRed Is there