Im trying to show an ‘out of stock message’ on the single product page for products that are out of stock. I have this code in my functions.php I get the following error: Notice: stock was called incorrectly. Product properties should not be accessed directly. Backtrace: require(‘wp-blog-header.php’), require_once(‘wp-includes/template-loader.php’), include(‘/plugins/woocommerce/templates/single-product.php’), wc_get_template_part, load_template, require(‘/themes/mytheme/woocommerce/content-single-product.php’), do_action(‘woocommerce_single_product_summary’), WP_Hook->do_action, WP_Hook->apply_filters, woocommerce_template_single_add_to_cart, do_action(‘woocommerce_simple_add_to_cart’), WP_Hook->do_action, WP_Hook->apply_filters, woocommerce_simple_add_to_cart,
Tag: product
Hide product stock for certain products on single product pages in WooCommerce
I try to add a option to hide the product stock info but only on certain single product pages. We do not want to hide this info for every product. We want to have a option in the product edit view where we can select if this should be the case for that current product. Unfortunately my code below is
Add to cart validation based on product attribute in WooCommerce
I’m trying to add a filter when a customer adds a product to the cart, to allow it or not. We just need to compare one attribute of the WooCommerce products. If cart is empty : Add to cart ok If cart has 1 or more items : check Attribute XXX value of products If Attribute value is the same
Show product titles to specific delimiter on WooCommerce category archive pages
My products have titles that include the delimiter | after which I enter some SEO keywords. Example product title Samsung UE55AU7172 | Smart 4K UHD 55 Can I force WooCommerce to show the product titles up to that delimiter in product category pages only? For example, the above product title in the product category page would be Samsung UE55AU7172. Answer
Add sale badge to product thumbnail on single product page and shop archive pages in WooCommerce
I use the following code to add a small badge topleft of every product with -%off. On my product page and it works. However when i try to do it on category page to all product listings with the following code: It does not work, there doesn’t seem to be any adjustment. Can I get some guidance into it? Answer
Add a specific word next to quantity input field for specific products on WooCommerce cart page
I have two products – ‘counseling’ and ‘testing’, and I want to display a specific word (‘sessions’ and ‘testings’) next to (or under) the quantity input field for each of them on the shopping cart page, but I can’t find a hook for this. How this can be achieved? Right now I display a generic word (‘items’) for both products,
Remove product (item) from WooCommerce checkout page using AJAX
I have added a removal link to the checkout for each product. This part works fine. Problem is; upon removal, the page is “scrolled to top”. I would like to change this by adding AJAX to the removal process. I’ve tried, but without success. In other words; when clicking on the removal link, the refresh should happen in the background
Change “add to cart” button text for products that have “no price” and “out of stock”
I want to change the “add to cart” text button for products that meet the following conditions: empty price out of stock The intention is to change the text to “Not available right now” Here is an example image to clarify my question This is the code that I use. But I can’t make it work. Any ideas of where
How to target an array of Product IDs in WooCommerce?
I’m using the code below to change a product price to text (Contact for Pricing) when the price field is left empty: It works for one product, but I’m having trouble getting it to work for multiple products. How do I target an array of product ids? Answer For an array of product IDs use in_array() conditional function as follows:
Add, update or remove product custom field in WooCommerce
I use the following lines to save a Value to the database. I have one question regarding this code, when I delete input it still keeps it. The only way to delete that is to put (space) as input. $…