Hot answers tagged

7

An attachment is a Post The posts table contains information on the attachment post. In WordPress every uploaded media has it's own post entry, where post_type is 'attachment' and post_status is 'inherit'. In fact, you can get attachment post types using functions used to get other post types, like post, page or any CPT. That includes WP_Query, ...


5

You should use 'orderby' => 'meta_value_num' and 'meta_key' => 'rating' as specified by the WordPress Codec. Using meta_value_num with the assumption your ratings are numeric values Reference: Orderby Parameters


4

Your code is deprecated in latest version. You should use this code to get the width: $size = wc_get_image_size( 'shop_catalog' ); $placeholder_width = $size['width'];


4

I know this post is old, but to keep this question updated: As of WooCommerce 2.4.4 woocommerce_process_product_meta_variable no longer works, and it must be changed to woocommerce_save_product_variation So, Change: add_action( 'woocommerce_process_product_meta_variable', 'save_variable_fields', 10, 1 ); Into: add_action( ...


4

Have tried your code and it works fine and infact it also gives out the details of each product in the orders. The code which i tried $filters = array( 'post_status' => 'any', 'post_type' => 'shop_order', 'posts_per_page' => 200, 'paged' => 1, 'orderby' => 'modified', 'order' => 'ASC' ); $loop = new ...


4

I solve This To get the current category ID. $cate = get_queried_object(); $cateID = $cate->term_id; echo $cateID; and it works like a charm.


4

Here's my code for creating a subscription -- it took a lot of trial and error to figure it all out. Best of luck! function create_test_sub() { $email = 'test@test.com'; $start_date = '2015-01-01 00:00:00'; $address = array( 'first_name' => 'Jeremy', 'last_name' => 'Test', 'company' => '', 'email' ...


4

Seems like there are a lot of meta keys you can order by (here is a list I’ve found). However I couldn’t find anything rating related. I searched for rating in the WooCommerce source code and found this line: includes/abstracts/abstract-wc-product.php#L1087 So here is what finally worked for me in the context of using the WooCommerce PHP REST API client: ...


4

WooCommerce allows you to override its default templates. All templates are located in a woocommerce/templates folder. All you have to do is to create a woocommerce folder within your theme’s directory, and in this folder duplicate the files you’d like to override. If you want to update the markup then you will need to copy archive-product.php and ...


3

Your edit got me to this idea, there indeed is no function called »woocommerce«, there is a class »WooCommerce« though. One thing to be aware of is, that the check has to late enough, so that plug-ins are actually initialized, otherwise - obviously - the class won't exists and the check returns false. So your check should look like this: if ( class_exists( ...


3

To check if woocommerce or anyother plguin is active, paste the following code on the template where you want to display the message. if ( in_array( 'woocommerce/woocommerce.php', apply_filters( 'active_plugins', get_option( 'active_plugins' ) ) ) ) { echo 'WooCommerce is active.'; } else { echo 'WooCommerce is not Active.'; }


3

Change your args to be like this: $meta_query = WC()->query->get_meta_query(); $meta_query[] = array( 'key' => '_featured', 'value' => 'yes' ); $args = array( 'post_type' => 'product', 'stock' => 1, 'showposts' => 6, 'orderby' => 'date', 'order' => 'DESC', 'meta_query' ...


3

There is almost never a scenario where executing PHP code entered from the wysiwyg editor is a good idea. It opens up a whole bunch of security issues. The best way to achieve what you are looking for is to setup a custom short code that will return the link you are interested in. Add something like this to your functions.php file in your theme. ...


3

seems woocommerce doesn't have any filters when registering their endpoints, https://github.com/woothemes/woocommerce/blob/master/includes/class-wc-query.php#L84 so you need to add your new endpoint on init hooks, just like this add_action( 'init', 'add_endpoint' ); function add_endpoint(){ add_rewrite_endpoint( 'license', EP_ROOT | EP_PAGES ); } ...


3

OK so I had a variation of this same problem myself and I'll walk you through it. All works fine, except for one thing: WooCommerce custom product attributes are not displayed instantly in dropdown/select filters on the website. However, 'manually' pressing Update on the Wordpress-page does the job. When displaying attributes woocommerce does this ...


3

The code you have provided is incomplete. Not sure if that is the only code you are using to achieve what you want. So, besides first code block which you have provided, bellow I am adding all rest of the code which is required to show the new field on backend in 'Order Details' box and make it editable through custom fields. Please note, in your second code ...


3

You may need to include a tax_query for the Woocommerce taxonomy (called 'product_cat'): $tax_query = array( array( 'taxonomy' => 'product_cat' ), ); $query->set( 'tax_query', $tax_query ); } return $query; } However, you'll have to ensure that you can return posts AND pages AND product categories and also ...


3

I think you are on the right track, wp_cache_delete was what finally helped me get an auto-signup with auto-login plugin working... I have this from there: wp_cache_delete($current_user->ID, 'users'); wp_cache_delete($current_user->user_login, 'userlogins'); Then see what roles you get after that with: $current_user = wp_get_current_user();


2

If you define your own empty function, then it can cause a problem when the plugin tries to load its same function. The simplest way around this is to use PHP's built-in function_exists() method wrapped around the function call. If that function is defined (like inside the plugin) it'll run the call. If not, it's skips over it without a second thought. if ( ...


2

This is not that complicated, here is a code snippet that will get you started: if(is_user_logged_in()) { //We only need these products to check $products_to_check = array(81,82,83,84); $customer_bought = array(); //Get all orders made by the current user in the last 365 days $customer_orders = get_posts( apply_filters( ...


2

Woo Commerce is off topic as its a plugin and not specifically related to WordPress but what you can do is copy over the single-product.php template to a WooCommerce folder in your child theme. change the file name and modify the file, then use single_template or template_include with the correct conditional tag. single_template function ...


2

Cron/Scheduled tasks and a DB crawl is your friend It would need to be a plugin, you could assign it a wp_cron interval even, not much unlike the one suggested above but with the addition of checking any 'post_content' like field (you will need to identify these, dependent upon your WP environment) for the image's URI/URL. This has the potential to be ...


2

This will definitly remove word category . Add this code in functions.php.As you already know woocommerce_template_single_meta is the hook responsible for meta information of the single-product. File is present in /woocommerce/templates/single-product/meta.php. Either you can use the following code to edit the html of meta.php or you can copy the file ...


2

If this is a true page, then you can get the ID of that specific page with get_queried_object_id(). This works and will return the ID on the specific pages, single, category, taxonomy, tag and author pages where it is used. True date and time archives and the homepage will not have ID's You can do the following $page_id = get_queried_object_id(); echo ...


2

Do you really need to know the ID, for that see @PieterGoosens's answer, or do you just need to know if you are at the post type product archive? The latter can easily be achieved by using is_post_type_archive(): if ( is_post_type_archive( 'product' ) ) { // code }


2

Technically speaking, Woocommerce products are just another WordPress post object with a customized post type (which is product in this case). If you take a look at the create_product function inside class-wc-api-products.php, you'll see this line: // Attempts to create the new product $id = wp_insert_post( $new_product, true ); So the API ends up using ...


2

It seems that the OP have managed to solve his/her problem by doing this, which can be found at Different menus for logged-in users. if ( is_user_logged_in() ) { wp_nav_menu( array( 'theme_location' => 'logged-in-menu' ) ); } else { wp_nav_menu( array( 'theme_location' => 'logged-out-menu' ) ); } The more shorter way to achieve that is by ...


2

Orders are just regular posts: wp_delete_post($order_id,true);


2

As explained in their documentation WooCommerce provides a templating structure. Copying WC in your theme won't get you anywhere. Create a woocommerce folder in your theme. Copy any template inside the templates folder of WC inside your woocommerce theme folder. Beware you need to keep the structure from templates folder intact in your woocommerce theme ...


2

Unfortunately, it's not possible with all plugins. This is a feature the developer has to provide on their own. Usually how it works is the plugin will look for the template file in the child theme first. If it's not found there, it looks for the template in the parent theme. Finally, if it's not found in either of those places, it uses the template ...



Only top voted, non community-wiki answers of a minimum length are eligible