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

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

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

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

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.


2

You can add this snippet below to your themes functions file to create the message you want displayed. (For all Woocommerce conditional options, visit their codex here: http://docs.woothemes.com/document/conditional-tags/) add_filter ('the_content', 'royal_woocommerce_maintenance'); function royal_woocommerce_maintenance($content) { if( is_woocommerce() ...


2

Woocommerce does hijack the main query on the shop page / product queries, so it's possible that you're used to referencing your custom fields within the loop or in some other context where the global $post is the page you are on, but in this case the contents of $post will be Woocommerce products and not the page. If this is for your base shop page you ...


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

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

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

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

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 Woocommerce conditional tag for single product page Try if(is_product()) instead of if ( is_page_template( 'single-product.php' ))


1

The syntax for adding an action in WordPress WITHIN a class is somewhat different. Your code will have to look somewhat more like the following... class MyPluginClass { public function __construct() { add_action( 'init', array( $this, 'sample_insert_category') ); } public function sample_insert_category() { ...


1

Not sure what the WC_Email class does exactly, but if the $headers argument is an array of headers, then you're almost there. To interpolate a variable value into a string in PHP you don't have to do the <?php ... stuff because it'll be rendered as is. Instead, you can use: $headers = array( "Reply-To: {$order->billing_email}" ); Or: $headers = ...


1

It's on the Tax settings page and is wp_options.woocommerce_price_display_suffix in the database. Please use the official site for WooCommerce and third-party plugin support, rather than StackExchange.


1

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


1

Another option would be to use the current_screen hook add_action( 'current_screen', 'my_admin_listing_custom_styles' ); function my_admin_listing_custom_styles() { $current_screen = get_current_screen(); if( 'edit' == $current_screen->base && 'product' == $current_screen->post_type) { // Run some code, only on the admin ...


1

I finally tried using var_dump() on $item and $_product, which are both used in the email-order-items.php template. $_product revealed a post object, which itself has a post_excerpt property, which looks like it holds the contents of the "Product Short Description" from the WooCommerce product form. So, to add the description beneath the item name, I added ...


1

Simply add an extra line before your for loop. For example: function get_color_dropdown($taxonomies, $args){ $myterms = get_terms($taxonomies, $args); $output ="<select onChange='window.location.href=this.value'>"; $output .= "<option value='default'>Shop by Color --></option>"; foreach($myterms as $term){ ...


1

This script is localized and registered, so you're going to need to use wp_deregister_script() instead of wp_dequeue_script(). Also, you need to use the function add_action() instead of add_filter() for this. Think of add_action as a way to inject run-able code into an existing function and think of add_filter as a way to manipulate the returned output of an ...


1

This is really a vanilla PHP/HTML question, but for what it's worth: <?php if ( $email = get_post_meta( $order->id, '_billing_email', true ) ) : ?> <li> <span><?php _e( 'Email:', 'dokan' ); ?></span> <a href="mailto:<?php echo esc_attr( $email ) ?>"><?php echo esc_html( $email ) ...


1

Do you by chance have the WooTax plugin installed and activated? I was having this issue a few months back and that ended up being the culprit. I uninstalled, reinstalled, reconfigured and everything was back to normal.


1

The reason copying those messed up your site was probably because of id mismatches. That is, posts with the ids of the stuff you're importing already exists. Regardless, since woocommerce stores orders as a custom post type, your safest bet here is probably the built in wordpress post import/export tool. 1. In the wordpress backend for the old site ...



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