Tag Info

Hot answers tagged

4

You could check to see if the 'WooCommerce' class exists, then run the code that requires WooCommerce. <?php if ( class_exists( 'WooCommerce' ) ) { // code that requires WooCommerce } else { // you don't appear to have WooCommerce activated } ?>


4

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


3

Use get_current_blog_id() to check the current site. To run on site 2 only, use this: function new_meta_values($order_id) { if ( 2 !== get_current_blog_id() ) return; /* the rest of the function code */ }


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

You should check WooCommerce -> Settings -> Emails (tab) and On the "New Order" sub-link you'll need to add your clients email there, otherwise Woo will use the default admin email address.


3

Your $scr in your wp_register_script() function is wrong. Given that your functions.php is inside your plugin, and your removeArrows.js is in the root of your plugin, your $scr should look like this plugins_url( '/removeArrows.js' , __FILE__ ) Another point of note, it is always good practice to load your scripts and styles last. This will ensure that it ...


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


3

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


3

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


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

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


2

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


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

There is no actions/filters to hook to. You need to override standard WC_Email_Customer_New_Account class and implement your own logic. To do it you need to create your own class which will inherit that class and register it. class WPSE8170_Email_Customer_New_Account extends WC_Email_Customer_New_Account { function trigger( $user_id, $user_pass = '', ...


2

i currently work on a woocommerce v2.1.12 shop and it seems they chaged that behavior. my ajax url to add items to the cart has to look like this: ?add-to-cart=[PRODUCT-ID]&variation_id=[VARIATION-ID]&attribute_[ATTRIBUTE-NAME]=[ATTRIBUTE-SLUG]&attribute_[ATTRIBUTE-NAME]=[ATTRIBUTE-SLUG] example: ...


2

i think this is what you need: $args = array( 'orderby' => 'name', 'hide_empty' => 1 ); $category_terms = get_terms( 'product_cat', $args ); foreach($category_terms as $cat_term){ echo $cat_term->name; } btw: woocommerce is offtopic here!


2

You should be able to do this with the same filter that is talked about here. The full-size images are being kept by WordPress. It's not really a WooCommerce thing. As well as the settings for images in WooCommerce you will also need to set minimum image size in WordPress's Settings>Media... Then this script (see the link above for complete discussion) ...


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


1

Your code actually looks good, according to the WooCommerce Documentation. It may simply be related to usage in a child theme, but I think that would still work. For reference, here is what I use to replace the default WooCommerce CSS files. This only disables the "general" styling (colors, buttons, etc) but keeps the structuring and responsive design. ...


1

WooCommerce has it's own loop (eg this is their "Products Loop" that it loves to use, your theme may not support it and/or conflict with it. One way to rule this out is to use their themes (I know, shock, horror) fortunately they have some free themes you can use, if only for testing purposes.


1

Don't do it. You will need the original images to regenerate the smaller version when you will want to change the theme, and disk space is so cheap there is no real need to conserve it. A better alternative is to limit image upload size and force the user to photoshop the image before uploading, something that most likely will also improve the result of ...


1

This happened to me. I installed a thumbnail regenerater plugin, this seemed to do the job for me.


1

Finally I got the code. Using below code, you can pick your OnSale products that are either Simple Product On Sale or Variable Product On Sale. Keep in mind that this code will pick every post in which you added sale price in the below image mentioned column . So avoid adding the price in this column (Shown in attached Image) if your sale price is same as ...


1

According to The Codex on wp_set_object_terms() get set by passing in a slug instead of the actual Term Name: wp_set_object_terms( $object_id, $terms, $taxonomy, $append ); $terms (array/int/string) (required) The slug or id of the term (such as category or tag IDs), will replace all existing related terms in this taxonomy. To clear or remove all ...


1

Glad you got it to work! Per my comment, WooCommerce takes Post Meta into consideration whenever deciding whether or not to add a Product to the Shop Catalog. It seems you were able to make it show up by updating the product visibility: update_post_meta( $new_product_post_id, '_visibility', 'visible' ); I'm not 100% familiar with WooCommerce so should it ...


1

Thanks, I use foreach ( $terms as $term ) { $term_link = get_term_link( $term ); echo '<li><a href="' . esc_url( $term_link ) . '">' . $term->name . '</a></li>'; } It works perfectly.


1

Probably $attribute is declared as private in the super class, so you can't access it directly from subclasses.



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