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: wordpress
WordPress how to display user_meta array as a table?
I have tried posting this on Wordpress stackoverflow, but haven’t got any answers. This is PHP + Wordpress question, so maybe someone here could help. Ok, so I’m building a “Transactions” table for a user using user_meta array. I’m new to this and trying to figure things out. Basically, in practice I know how to store array to user_meta. My
Increment variable date in PHP
I am grabbing the post published date (WordPress) and trying to add 2 days to it to create a post expiry date. But I am throwing the following error: Notice: A non well formed numeric value encountered Here is my code: Can anyone point out my error here please? Answer When using slashes to separate your date parts PHP assume
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
WooCommerce database query : Get product category image path+name from thumbnail_id
I am trying to list all my Woocommerce Product Categories | category name | category slug | … | … | category image path+name | Using this query below, gets me most of the way: I have: From here I can’t work out how or where to JOIN the thumbnail_id to get my image path+name. edit: I have done a
Posts not ordering by post__in
I am trying to display 3 blog posts that have been selected by the user in the admin. The order should go gridItem1, gridItem2 then gridItem3. I have set out my query below but it shows the selected posts but in date order not in the order I have outlined. I have searched other posts and added in the ‘surpress_filters’
Modifying URLs on a WP webpage depending on the incoming request URL parameters
I have a specific task where I have to alter the URLs contained within a WP webpage, based on the parameter of the incoming URL request. Let’s say I have a webpage https://example.com/prefix, on that page, there are several links that point to another page, say https://example2.com/prefix So whenever someone gets redirected to https://example.com/prefix with a certain URL parameter, let’s
WordPress how to get the post thumbnail inside a figure tag
I am running a query loop and want that ‘if’ the post has a featured image, it needs to be inside a <figure> tag. But the featured image’s <img> tag is appearing before the <figure> tag. What could be the reason? The problem can be better understood with this image: Answer It’s because you’re using the_post_thumbnail function which echo the
Limit number of words in Woocommerce description (using php)
I edited my Child Theme’s functions.php to display the short description of my WooCommerce products under the product title. I had this code that works fine and limits the number of characters to 165, then adds “…” at the end of the excerpt. However, I don’t want the words to break after 165 characters. Therefore, I was wondering if there
WordPress how to show all posts in the index page and exclude sticky posts
Since Wordpress sticky posts feature allow the post checked as sticky in post publish panel to be placed at the top of the front page of posts. I want to show all posts in index without sticky posts: Answer You could use pre_get_posts action hook to manipulate the query. Since you need to modify the query on your index.php, the