New answers tagged

0

Try adding this code to your functions.php file: if(!is_page(array('checkout','cart')) && !WC()->cart->is_empty()) { WC()->cart->empty_cart(); }


0

You need to override two WC templates. Create a folder woocommerce (if it doesn't already exist) under your theme's folder. From the plugins/woocommerce/templates directory copy over the files emails/plain/email-order-details.php emails/email-order-details.php and keep the same folder structure. Consult WC documentation on that one. In your versions of ...


0

WC()->cart->get_cart() will return an array of current cart items. array( $cart_item_key => $cart_item, $cart_item_key => $cart_item, ... ) Keys $cart_item_key are unique and you need to use one in order to remove item from cart like that: WC()->cart->remove_cart_item( $cart_item_key );


0

I'm not sure what you're trying, but this code should do the job. add_action( 'template_redirect', 'remove_product_from_cart' ); function remove_product_from_cart() { // Run only in the Cart or Checkout Page if( is_cart() || is_checkout() ) { // Set the product ID to remove $prod_to_remove = 58; // Cycle through each ...


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


0

So far I've found the following tables to save the attributes, maybe this could be helpful for you. The following show the tables and a few rows as example:


0

Problem is on cart page has_term is false because it is checking if cart page have terms 12-pack or 6-pack. You also need to provide post object/ID to has_term() as a third parameter. Updated code:- function input_set_all_values( $args, $product ) { if (( has_term('6-pack', 'criteria', $product->post ) ) ) { $args['step'] = 6; ...


1

The best practice for editing a Woocommerce theme is similar to Wordpress as you should use Hooks and Filters when possible. https://docs.woothemes.com/document/introduction-to-hooks-actions-and-filters/ But if you do need to edit a template Woocommerce outlines this on their website as well: https://docs.woothemes.com/document/template-structure/ You just ...


1

It's a bit hard to tell without knowing what shop theme you are using but I'll try anyways…  The code <?php wc_get_template_part( 'content', 'product' ); ?> is basically calling the template file content-product.php. I would however not recommend you alter the default file. On a standard woocommerce install you will find that default template file ...


-2

<?php $args = array( 'post_type' => 'product', 'posts_per_page' => 10); $loop = new WP_Query( $args ); while ( $loop->have_posts() ) : $loop->the_post(); global $product; echo '<br /><a href="'.get_permalink().'">' . woocommerce_get_product_thumbnail().' '.the_title().'</a><br />'; endwhile; wp_reset_query(); ?> ...


0

The way htaccess rewrite works (wp uses this), this drives the very first match on the list to load the targeted rewrite of URL. So answer to your question is YES, keep longer/elaborated rules at top, followed by less longer structures; alternatively you can write conditions (rewrite cond ) to match rules per blockwise.


0

A hook that run before process as below : add_action( 'woocommerce_before_checkout_process', 'initiate_order' , 10, 1 ); function initiate_order($order_id){ // otp logic } Even SMS Referance : https://docs.woothemes.com/document/twilio-sms-notifications/ http://hookr.io/actions/woocommerce_before_checkout_process/


0

Why dont you create a custom field "customsort" and then assign values to them? You could use this code: add_filter('woocommerce_get_catalog_ordering_args', 'my_woocommerce_catalog_orderby'); function my_woocommerce_catalog_orderby( $args ) { $args['meta_key'] = '_customsort'; $args['orderby'] = 'meta_value'; $args['order'] = 'asc'; return ...


0

Adjust the single-product-reviews.php template file and add a conditional check. How to limit users to one comment per post


0

The answer is to serialize the data you want to be hidden for sure.


0

add_action('pre_get_posts','search_filter_exc_posts'); function search_filter_exc_posts($query) { // Verify that we are on the search page & this came from the search form if($query->query_vars['s'] != '' && is_search()) { $q_tax_query = $query->query_vars["tax_query"]; // append product categories to current tax ...


0

get_variation_price gets min. by default. You need to pass min max and adjust it to your needs like so: // Main Price $prices = array( $product->get_variation_price( 'min', true ), $product->get_variation_price( 'max', true ) ); $price = $prices[0] !== $prices[1] ? sprintf( __( '%1$s', 'woocommerce' ), wc_price( $prices[0] ) ) : ...


0

My customer wanted "free shipping" over orders 100 < so I used a custom woocommerce/cart/cart-shipping.php Take a look at the contents of it, might help you: https://gist.github.com/eminozlem/ab93b3d91413e59eb86e8601c418656d


2

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


0

FTP Download review-order.php from: wp-content/plugins/woocommerce/templates/checkout Copy and Paste the code for td class="product-remove" that you got from cart.php into review-order.php after td class="product-total".../td Now override review-order.php by copying it to: yourtheme/woocommerce/checkout/review-order.php. Now it will allow users to ...


0

You can get the terms and then create an array of term ids which you pass as include parameter to get terms with menu order parameter and woocommerce will handle the rest like this: $terms = get_the_terms($post->ID, 'product_highlights'); if (!empty($terms) && is_array($terms)) { $post_terms = array(); foreach ($terms as $term) { ...


0

404 Possible Error Cases with Permalinks check your apache config and make sure the directory is right. restart the apache process along with MYSQL/similar. make sure mod_rewrite is enabled Apache mod_rewrite for Ubuntu/Debian: sudo a2enmod rewrite sudo service apache2 restart Similliar to mod_rewrite for Nginx by .htaccess: a simpler way is ...


1

You need first to buy WooCommerce Quick View plugin, because woocommerce lightbox plugin doesn't work without it. Please read this: Woocommerce single product show in modal…? And if you go to the wordpress page of woocommerce lightbox plugin, you will see that is a complementary plugin.


0

In your child theme's 'functions.php' file, you need to use the 'remove_action( 'widgets_init', '$name' ); script. For instance, in your twentytwelve-child theme's 'functions.php' file, use: remove_action( 'widgets_init', 'twentytwelve_widgets_init' ); //necessary to replace parent theme's code and then hook your new widget in your child theme's function ...


0

I think it was pagination causing the problem. Not sure whether this is a WooCommerce bug or is intentional, but by default on the single product page a relational link is added to a next product. (I can't see why that is there because I would have thought only one product should ever be displayed, but I'm probably missing something.) So that meant some ...


1

Customizer Controls can be displayed based on context. With active_callback API introduced in WordPres 4.0, you can control where to show your specific options. Add your customizer options like this with the optional active_callback argument. $wp_customize->add_control( 'wc_cart_page_option', array( 'label' => esc_html__( 'Cart Page Options' ...


0

You need to limit yourself to the main loop and this can be done by checking if is_main_query returns true. This might not be enough as that hook/filter was probably designed with the intention of augmenting the summery and therefor might be called more then once even during execution of the main loop itself. You have two option here Use a much better ...


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


0

I think you have to use add_action() with something like this: add_action( 'woocommerce_edit_account_form', 'custom_address_to_edit' ); function custom_address_to_edit( $address ) { global $wp_query; if ( isset( $wp_query->query_vars['edit-address'] ) && $wp_query->query_vars['edit-address'] != 'billing' ) { return ...


0

The idea here is to order your products by a custom fields. You can add a custom field for your products and fill it with numbers or letters. Then you can use this field for ordering your products by numerically or alphabetically, depending on your initial choice. There is this snippet of code you can use: ...


0

Depending on your situation I don't recommend or condone doing this, but the answer to your question is to take a look at the $wpdb class and the dbDelta() function. This is the interface WordPress provides for adding custom tables. Be careful though, with great power comes great responsibility. Using $wpdb bypasses many of the built-in WordPress security ...


0

I think I have answer to my own question. After loading data into wp_woocommerce_attribute_taxonomies as part of the function detailed above, it is necessary to create serailised array of attributes and their meta data, and post it into wp_options.As far as I can tell wp_options contains a range of transient data used by wordpress as a way to improve ...


0

Yes and no, WP_Query fetches posts, it doesn't display them. You can query for WooCommerce products as they're a custom post type. Just create a query object, and specify the post_type parameter to use the post type WooCommerce uses, then loop over them, displaying them and grabbing the post meta such as the SKU as you go along. How you would do that, and ...


0

All the data like different prices of a product custom post type are store (for each product) in postmeta table. To find the post id of all products you have to use this query on posts table: SELECT * FROM 'posts' WHERE 'post_type' = 'product' For each product id (post_id), you can retrieve all related data with this query on postmeta table: SELECT * ...


0

CLARIFICATION FOR ALL : You use virtual products on your shop. On checkout page, you have created and set an additional checkbox for european VAT purpose. There is 3 cases related to this checkbox. Checkbox is hidden (default) Checkbox is visible when selected country is an european country: Checkbox disabled (default) => set the VAT value to ‘0’ ...


0

Too bad no-ones answered you on this simple question. I guess you've allready figured it out, but for anyone else wondering the same: A WooCommerce Slug is the true path to a certain category/product the database uses to find the correct category/product (just like on a computer: usr:\\My_Computer\Desktop\ or c:\\programfiles\desktop\), and can often be ...


0

It's a little too much code to put here but here's how you do it. There are a lot of good tutorials (and plugins) on that site. This is the best example I've seen for managing the quick edit screen. Since the quick edit screen is related to the columns displayed you may need to manually control the columns in the screen as well. To do that use the ...


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


0

The easiest way to override the WooCommerce emails is to copy woocommerce/templates/emails/admin-new-order.php to yourtheme/woocommerce/emails/admin-new-order.php and make any changes in your version of the template. This will ensure that any changes you make do not get lost during any subsequent upgrades. The text displayed in the subject line of the email ...


0

I figured out the answer, so I thought I'd post it. My code looks like this now and it works: add_action( 'processed_subscription_payment', 'updatedays', 10, 2 ); function updatedays($user_id, $subscription_key) { //do what I need to the sub key } There really needs to be more examples on the Woothemes documentation though..



Top 50 recent answers are included