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

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 ...


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

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

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

The problem with your approach is that woocommerces product category is a custom taxonomy called product_cat. But with cat you are addressing the built-in category. Taxonomies can be addressed with a tax query, simplified example below: function wpse188669_pre_get_posts( $query ) { if ( ! is_admin() && ...


4

There are approx. 10,000 items returned by the query. That's your problem right there. No matter what you do inside the loop, WordPress is still loading 10,000 post objects into memory. Batch it up and sprinkle a little magic in your query arguments: $args = array( 'fields' => 'ids', // MAGIC! Just get an array of id's, no objects ...


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

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( ...


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

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

It's Simple. Step 1: Create a replica of the instance. Step 2: Import the old .sql file which contained one day lost orders data. Step 3: Use https://wordpress.org/plugins/woocommerce-simply-order-export/ plugin and export CSV or XML of 1 day data which you have lost. Step 4: Install the above plugin in the LIVE instance and import the CSV or XML ...


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

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.'; }


2

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' ...


2

In woocommerce/includes/class-wc-ajax.php there is a method on the WC_AJAX class responsible for loading variations called load_variations, it contains only one hook, which is a filter, named woocommerce_ajax_admin_get_variations_args which fires early in the method. However if you are looking for something client side, then ...


2

To change the heading that appears in the body (message) of the email template you can use the following filter: 'woocommerce_email_heading_' . $this->id where $this->id equates to the id class property that is set within the email class of the specified type. For example, to change the heading of the "New Order" email you would do the following: ...


2

The answer is "Yes"! I just discovered that there is a "Any size" option where I set the colour and that's it for all sizes. Phew!


2

Most parts of your code were unnecessary. Assuming you get the correct set of posts with your get_posts(), you can just loop through those posts, and update the meta. You also had a confusion of the variables and objects in your loop, and you tried to update/get information passing a post object instead of an $id. $children = get_posts( array( ...


2

Your website looks working properly. If still, there are some strings not translating then you need to add appropriate Dutch strings for missing strings. For that you can use tool poedit. Further reference: Translating with poedit


2

The get_adjacent_post() function has multiple arguments. The fourth and last one is the taxonomy, which per default is 'category': $post_prev = get_adjacent_post( true, '', true, 'product_cat' ); $post_next = get_adjacent_post( true, '', false, 'product_cat' );


2

If the code you have provided is the only code you are using to achieve what you want then thats incomplete code. Below is the tested version of code which works well. I hope this helps: /* Add the field to the checkout */ add_action('woocommerce_after_order_notes', 'my_custom_checkout_field'); function my_custom_checkout_field( $checkout ) { echo ...


2

The default relation for a meta query is AND, so when you have two conditions they will be treated as such: $meta_query[] = array( 'key' => '_stock', 'value' => '0.000000', 'compare' => 'NOT IN' ); $meta_query[] = array( 'key' => '_backorders', 'value' => 'no', 'compare' => '!=' ); Get all ...


2

Disabled elements don't fire mouse events, so you have to wrap a div around the button and catch the event.


2

This is because you're doing it too early. You need to wrap your code in the necessary hook so that it occurs at the correct time. Because you don't tell get_field the ID of the current post, it needs to know which post to get the field from, and it does this by referencing the global variable $post, which gets set when you call the_post, or by WP Core ...


2

If you look at woocommerce/templates/content-single-product.php you'll see that the product summary is constructed using hooks with different priorities. Here's the relevant section: <?php /** * woocommerce_single_product_summary hook * * @hooked woocommerce_template_single_title - 5 * @hooked ...


2

You have a typo in $_SESSION['odertype'], should be $_SESSION['ordertype']. You are also ASSIGNING a value instead of testing it for equivalency, try ==. If in doubt you can always use var_dump($_SESSION) to get all the values stored there.


2

Following @Burgi's answer, the correct snippet should be: function jk_woocommerce_quantity_input_args( $args, $product ) { if ( isset( $_SESSION['ordertype'] ) && // Never assume an array index exists $_SESSION['ordertype'] == 'local_delivery' && // Note == "same as" operator, not = "assign" ...



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