Tag Info

Hot answers tagged

7

An attachment is a Post The posts table contains information on the attachemnt 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 include WP_Query, ...


5

Looks like I figured it out. I used get_term_link. And I was getting an error because I was using it this way: get_term_link( $woo_cat_id, 'product_cat' ); Which gave me this error: Object of class WP_Error could not be converted to string So I went this route instead with the slug and it worked: $prod_cat_args = array( 'taxonomy' => ...


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

While this question is probably technically off topic since it relates to woo, there's definitely some stuff that could be answered that will help other users in the future, plus, I really have been there with the multi-day frustration stuff and would have killed for a life line. There's a few things at play here, what you're looking at in the code you ...


3

The solution: $query = array( 'post_status' => 'publish', 'post_type' => 'product', 'posts_per_page' => 10, 'meta_query' => array( 'key' => '_price', 'value' => array(50, 100), 'compare' => 'BETWEEN', 'type' => 'NUMERIC' ), ); $wpquery = WP_Query($query); // return 10 products ...


3

Ok, worked it out via a little workaround. Add a new sorting function in Woocommerce, something like: https://gist.githubusercontent.com/bekarice/0df2b2d54d6ac8076f84/raw/wc-sort-by-postmeta.php works nicely, but remove the bit about meta values and keys since we're not sorting by custom fields (though that could be a good workaround too). Change the ...


3

Okay, based on answers on link above (where I got the old code and there are people that help to answered), I put the modification code for my website. I tried it and it's working like charm. Change: add_action( 'woocommerce_product_after_variable_attributes', 'variable_fields', 10, 2 ); Into : add_action( 'woocommerce_variation_options', ...


3

Looking further into the WooCommerce source, they fortunately, provide a filter named woocommerce_product_data_tabs which will allow you to conditional unset tabs. I've provided an example below: add_filter('woocommerce_product_data_tabs', function($tabs) { /** * The available tab array keys are: * * general * inventory * ...


2

You should be able to get the current product id using the using the $post global variable and use that with the WooCommerce function get_product() to the the product object and test its product type. public function __construct() { add_action( 'add_meta_boxes', array( $this, 'add_meta_box' ) ); } public function add_meta_box( $post_type ) { ...


2

WooCommerce Reviews is not a commenting board. You cannot create comment threads and reply to each other. I think I've found a very good solution for you. There is a free wordpress plugin which adds a new tub "Discussions" and opens powerful commenting board to do any type of discussions and comments on product page. This plugin name is "WooDiscuz". This is ...


2

Those options do not appear from the core but, they're are part of the Jetpack plugin. You should check with Jetpack files. Off-topic: I personally would prefer to disable these on Woocommerce pages. Hope this helps


2

In modern WordPress toolbar is considered mandatory part of admin. That is WordPress is explicitly opinionated about not letting you to disable it. While you still can kind of hack it out, it's unnecessary struggle. If you need a blank page there is no reason to struggle with blanking admin interface for it. You could simply use wp-admin/admin-post.php to ...


2

You need to delay the firing of your code, otherwise your conditionals will evaluate false (the request won't have been parsed yet). Use the action wp_enqueue_scripts: function wpse_182357_enqueue_scripts() { // Your code } add_action( 'wp_enqueue_scripts', 'wpse_182357_enqueue_scripts' ); Update: Missed the root of the problem - is_page_template() ...


2

I just made it for a client, you'll have to do it on the pre_get_posts action. That means you will add parameters to the Wordpress query before it returns the posts. Add this to functions.php: // advanced search functionality function advanced_search_query($query) { if($query->is_search()) { // category terms search. if ...


2

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'];


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

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

There is Woocommerce conditional tag for single product page Try if(is_product()) instead of if ( is_page_template( 'single-product.php' ))


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

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


1

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


1

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.


1

WordPress default importer will not work for WooCommerce product attributes. There is a plugin available to import WooCommerce products which handles import for products as well as their attributes. I'll not paste the plugin URL here since it's a third party plugin, but if you google for 'WooCommerce import', you will easily get that plugin.


1

You need to explode the comma separated string to get the array of IDs. Follow the below code. $cookie_array = $_COOKIE["your-results"]; // Test output echo $cookie_array; $cookie_array = array_map( 'absint', (array) explode(',', $cookie_array) ); $sug_args = array( 'post_type' => 'product', 'post__in' => $cookie_array, ); ...


1

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


1

Woocommerce stores 'order' metakeys in the table wp_woocommerce_termmeta. The mechanism it uses is the same as menu_order for posts. Check this thread for reference. Thanks


1

First is showing the attachment file path, second is file attributes size, type, height, width etc. Thanks attachment in wp_post shows the attachment basic details title, time, author etc. wp_postmeta shows attachment all other details for example attachment would be text, pdf, image etc so it having different meta data for different types of posts. ...



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