Menu
  • HOME
  • TAGS

Add product category name on order page in admin

Tag: woocommerce

Is there a way to add product category name to the admin order page in Woocommerce?

Right now it only display the product name.

Best How To :

something like this??

add_action('woocommerce_before_order_itemmeta','woocommerce_before_order_itemmeta',10,3);

function woocommerce_before_order_itemmeta($item_id, $item, $product){
   echo '<p>'.get_the_term_list($product->id, 'product_cat').'</p>';
}

this code will display category below the product name.

Woocommece login URL

wordpress,woocommerce

Try this code: function redirect_login_page(){ if(is_user_logged_in()){ return; } global $post; // Store for checking if this page equals wp-login.php // permalink to the custom login page $login_page = get_permalink( 'CUSTOM_LOGIN_PAGE_ID' ); if( has_shortcode($post->post_content, "woocommerce_my_account") ) { wp_redirect( $login_page ); exit(); } } add_action( 'template_redirect','redirect_login_page' ); ...

WooCommerce - Display categories and its products on front page

php,wordpress,woocommerce

First you'll need to query the products from a category: $args = array( 'posts_per_page' => -1, 'tax_query' => array( 'relation' => 'AND', array( 'taxonomy' => 'product_cat', 'field' => 'slug', 'terms' => 'category-slug1' //Your category goes here ), ), 'post_type' => 'product', 'orderby' => 'title', ); $first_cat_query = new WP_Query( $args...

How to set woocommerce checkout form values to empty

wordpress,wordpress-plugin,woocommerce

Not sure with your exact issue , but there might be two possible situations in your case. You might me logged in with same user and then trying to checkout, as woo-commerce will fetch the details of currently active user and auto fill it during checkout. Fields might get auto...

How To check Product Have Variation in woocommerce

php,wordpress,woocommerce,product

This should work: if( $product->is_type( 'simple' ) ){ // No variations to product } elseif( $product->is_type( 'variable' ) ){ // Product has variations } Example: If you will replace the file woocommerce --> single-product --> meta.php with this code, you will see it works. <?php /** * Single Product Meta...

trouble using AFOAuth2manager to generate HTTPSOauthToken

ios,oauth,woocommerce,afoauth2client

try this NSURL *baseURL = [NSURL URLWithString:urlString]; AFOAuth2Manager *oAuthManager = [[AFOAuth2Manager alloc] initWithBaseURL:baseURL clientID: keyClientID secret:keyClientSecret]; [oAuthManager authenticateUsingOAuthWithURLString:@"/oauth/token" username:myUserName password:myPassword scope:@"email" success:^(AFOAuthCredential *credential) { NSLog(@"Token: %@",credential.accessToken); //Authorizing requests AFHTTPRequestOperationManager *manager = [[AFHTTPRequestOperationManager alloc] initWithBaseURL:baseURL];...

PHP date not taking into account AM/PM properly

php,wordpress,woocommerce

You have to use date_add to add two times properly: $date = date_create($item['Booking Time']); date_add($date, date_interval_create_from_date_string($item['Duration'])); echo date_format($date, 'h:ia'); One line solution: date_format(date_add(date_create($item['Booking Time']), date_interval_create_from_date_string($item['Duration'])), 'h:ia'); ...

WooCommerce orders page add customer role custom column

php,wordpress,woocommerce

Add below code in your theme functions.php add_filter('manage_edit-shop_order_columns', 'add_column_heading', 20, 1); function add_column_heading($array) { $res = array_slice($array, 0, 2, true) + array("customer_role" => "Customer Role") + array_slice($array, 2, count($array) - 1, true); return $res; } add_action('manage_posts_custom_column', 'add_column_data', 20, 2); function add_column_data($column_key, $order_id) { // exit early if this is not...

How to display grouped products in a list with quantity in woocommerce?

wordpress,woocommerce

You can read about WooCommerce's template overrides. If you aren't seeing the default with your theme that means that your theme is overriding it. I can't be sure, but probably you need to go into your theme's woocommerce folder.... and find the grouped.php template in: yourtheme/woocommerce/single-product/add-to-cart/grouped.php and rename it to...

woocommerce_add_order_item_meta hook sending only one argument; three expected

wordpress,woocommerce,wordpress-plugin-dev

Shame on me!I had not found necessary to add the last two arguments of the add_action() function. So the default number of argument being one, only one was passed to my callback. so the right code for the add_action() function is: add_action('woocommerce_add_order_item_meta', array($this, 'charlie_ajoute_un_order_item_meta'), 10, 3); Hope it may help...

How to remove the quantity field from cart page for specific product attribute WooCommerce

php,wordpress,woocommerce

$attributes = $product->get_attributes(); only returns an array of the product's attributes, so you would at least need some kind of conditional logic as returning the attributes alone would not be enough. If you notice this line: echo apply_filters( 'woocommerce_cart_item_quantity', $product_quantity, $cart_item_key ); You don't need to override the cart.php template...

Remove item with $product_id - Woocommerce

php,wordpress,woocommerce

I think You are using remove_cart_item wrongly. If you go through the documentation, you will find that it accepts cart_item_key as parameter(as wisdmLabs mentioned in comment). And you are using it like WC()->cart->remove_cart_item($product_3); instead of wc()->cart->remove_cart_item($cart_item_key); So by replacing that line, I think you will able to remove product....

WooCommerce - Change the shop page layout but keep the archive-product.php

php,wordpress,woocommerce

Take a look at the taxonomy-product_cat.php and taxonomy-product_tag.php templates and you will see that they both call the archive-product.php template. wc_get_template( 'archive-product.php' ); Therefore, if you wish to change the shop archive, but not the taxonomy archives you need to duplicate the archive-product.php to another file... say: archive-product-alt.php and change...

WooCommerce query quantity on product page

php,forms,woocommerce

Well I had to add an ajax function to the input field that would then update a hidden field in my form. Then when the Calculate button is pressed, I have access to the updated quantity.

WooCommerce seems to only orderby date and not price

php,ajax,wordpress,woocommerce

Try this: $args = array( 'post_type' => 'product', 'posts_per_page' => 100, 'product_cat' => 'beast-balls', 'orderby' => 'meta_value_num', 'meta_key' => '_price', 'order' => 'asc' ); ...

WooCommerce: How to display Category Name in single-product.php

php,wordpress,woocommerce

Try this : global $post; $terms = get_the_terms( $post->ID, 'product_cat' ); foreach ($terms as $term) { echo $term->name .' '; $thumbnail_id = get_woocommerce_term_meta( $term->term_id, 'thumbnail_id', true ); $image = wp_get_attachment_url( $thumbnail_id ); echo "'{$image}'"; } ...

fabricjs: how to show object size after scaling

javascript,jquery,wordpress,woocommerce,fabricjs

I don't think it is a good idea to change the fabricJs source. It would be better to extend it or make some functions. I made you jsFiddle with how to get the width and height of the object while it is scaling. canvas.on('object:scaling', function(){ var obj = canvas.getActiveObject(); $('#rect-width').val(Math.floor(obj.getWidth()));...

Select woocommerce chosen shipping method price

php,wordpress,woocommerce

Did you try this inside your foreach loop? $rate = $package['rates'][$chosen_method]->cost; ...

WordPress - Failing to override woocommerce templates

wordpress,templates,woocommerce,override

While the directory structure in the WooCommerce plugin itself is: /plugins/woocommerce/templates/ You should define it like the following in your theme (note the missing templates dir): /yourtheme/woocommerce/ In other words, you should put all of the overrides directly within the woocommerce/ directory (there will be no templates/ directory). This is...

dont allow PO BOX shipping woocommerce not working

wordpress,woocommerce

add_action('woocommerce_after_checkout_validation', 'deny_pobox_postcode'); function deny_pobox_postcode( $posted ) { global $woocommerce; $address = ( isset( $posted['shipping_address_1'] ) ) ? $posted['shipping_address_1'] : $posted['billing_address_1']; $postcode = ( isset( $posted['shipping_postcode'] ) ) ? $posted['shipping_postcode'] : $posted['billing_postcode']; $replace = array(" ", ".", ","); $address = strtolower( str_replace( $replace, '', $address ) ); $postcode = strtolower(...

Wordpress woocommerce - hide flat rate when free shipping

wordpress,woocommerce,shopping-cart

You're using the old method, you need to use this new one I think. Copied from WooThemes website: add_filter( 'woocommerce_package_rates','hide_shipping_when_free_is_available', 10, 2 ); function hide_shipping_when_free_is_available( $rates, $package ) { // Only modify rates if free_shipping is present if ( isset( $rates['free_shipping'] ) ) { // To unset a single rate/method,...

Wordpress - customized pages with blocks - prohibit google seo index of blocks

wordpress,seo,woocommerce,robots.txt,google-sitemap

Noindex tags would be useful. https://support.google.com/webmasters/answer/93710?hl=en

woocommerce redirect after registration

woocommerce

You want to use a filter like this: function plugin_registration_redirect() { return home_url( '/page-to-show' ); } add_filter( 'registration_redirect', 'plugin_registration_redirect' ); Or, specifically to your code: function plugin_registration_redirect() { $url = wp_get_referer() ? wp_get_referer() : wc_get_page_permalink( 'welcome' ); return $url; } add_filter( 'registration_redirect', 'plugin_registration_redirect' ); ...

“Validation error: PayPal currencies do not match” in WooCommerce

wordpress,validation,paypal,woocommerce,currency

i found temporary fix for this problem go to “plugins/woocommerce/includes/gateways/paypal/includes/class-wc-gateway-paypal-ipn-handler.php” and comment two lines (line number : 176 and 177 ) like this //$this->validate_currency( $order, $posted['mc_currency'] ); //$this->validate_amount( $order, $posted['mc_gross'] ); Source : https://www.kapadiya.net/wordpress/woocommerce-paypal-for-inr/...

Show product's image in “Orders” page - Woocommerce

php,wordpress,woocommerce

Orders are custom post types of shop_order type. Orders do not have thumbnails themselves, but orders have a list of products that were purchased and each product has the possibility of a thumbnail. You can see in the order-details.php template how to get all the items/products associated with any order...

Woocommerce product dimensions not showing on first product

php,html,wordpress,web,woocommerce

add_action( 'woocommerce_after_shop_loop_item_title', 'cj_show_dimensions', 9 ); function cj_show_dimensions() { global $product; $dimensions = $product->get_dimensions(); if ( ! empty( $dimensions ) ) { echo '<span class="dimensions">' . $dimensions . '</span>'; } } The above code works well only under the following conditions: If dimensions are added to the product. This code should...

Displaying all woocommerce product liks with title in Footer for SEO - Wordpress PHP

php,wordpress,woocommerce,e-commerce

Is this what you wants ? //you can remove post_status=>publish if you want unpublished product also $loop = new WP_Query( array( 'post_type' => 'product','post_status' => 'publish', 'posts_per_page' => '-1' ) ); while ( $loop->have_posts() ) : $loop->the_post(); echo "<a href='".get_post_permalink()."'>".$loop->post->post_title."</a><br>"; endwhile; EDITED change query like this : $loop = new...

How to store the_title() into a variable to reutrn the value, not just echo it

php,arrays,wordpress,variables,woocommerce

Either use the right parameter for the_title() as Jon Stirling suggested, or do the following: $tagz = get_the_title(); get_the_title() This function will return the title of a post for a given post ID. https://codex.wordpress.org/Function_Reference/get_the_title...

Add second single product page in Woocommerce

wordpress,woocommerce

What I would do in this case is add a link that will reload the page with a custom query arg in the URL. Then you can filter the template via template_include to load a different template. Untested, so be careful of syntax typos. add_filter( 'template_include', 'so_30978278_single_product_alt' ); function so_30978278_single_product_alt(...

Wordpress End If Statements

php,wordpress,woocommerce

<?php if ( sizeof( $woocommerce->cart->cart_contents ) == 0 ) { // The cart is empty } else { ?> <div class="header-cart-inner"> <a class="cart-contents" href="<?php echo WC()->cart->get_cart_url(); ?>" title="<?php _e( 'View your shopping cart' ); ?>"><?php echo sprintf (_n( '%d item', '%d items', WC()->cart->cart_contents_count ), WC()->cart->cart_contents_count ); ?> - <?php echo...

Wordpress & Advanced Custom Fields - Retrieving categories

php,wordpress,woocommerce,advanced-custom-fields

Found the solution to the problem. Apparently I was using the wrong type of compare value and the actual value for the category had to have double quotes. I found the sample code I needed here. Here's how the final solution looked like for me: $images = get_posts(array( 'numberposts' =>...

Woocommerce simple filter php

php,wordpress,woocommerce

Currently you are cheching if status IS NOT failed and then redirect. Change if ( $order->status != 'failed' ) { to if ( $order->get_status() == 'failed' ) { See PHP comparison operators. Also, you are not getting correct order. Your function should take $order_id and load correct order. add_action( 'woocommerce_thankyou',...

WooCommerce display product categories in product title

php,wordpress,woocommerce,taxonomy

you can simply get all the categories assign to product by using get_the_terms $terms = get_the_terms( get_the_ID(), 'product_cat' ); foreach ($terms as $term) { echo '<h1 itemprop="name" class="product-title entry-title">'.$term->name.'</h1>'; } ...

Woocommerce hide payment gateway for user roles

php,wordpress,woocommerce

Have mention the code which is tried and tested for you. It works well. Lemme know if the same works for you too. function wdm_disable_cod( $available_gateways ) { //check whether the avaiable payment gateways have Cash on delivery and user is not logged in or he is a user with...

Wordpress ordered by two custom fields meta_key's

php,wordpress,woocommerce

Add both meta keys to meta_query and set orderby to meta_value. Then you can replace it with posts_orderby hook. <?php // Override orderby if orderby value = 'meta_value' function orderby_countdown_date_and_hour( $orderby ){ return str_replace( 'meta_value', 'meta_value, mt1.meta_value', $orderby ); } $args = array( 'post_type' => 'product', 'posts_per_page' => 20, 'tax_query'...

How to read data sent by webhooks?

php,wordpress,woocommerce

$webhookContent = ""; $webhook = fopen('php://input' , 'rb'); while (!feof($webhook)) { $webhookContent .= fread($webhook, 4096); } fclose($webhook); mail('[email protected]', 'test - hook', $webhookContent); This is all it took. It will send all the body to your email...

Add custom functionality on WooCommerce complete button

php,ajax,wordpress,wordpress-plugin,woocommerce

this code will fire as soon a customer made a order and arrives on the thankyou page.. add_action( 'woocommerce_order_status_completed', 'custom_task' ); function custom_task( $order_id ) { // Only continue if have $order_id if ( ! $order_id ) { return; } // Get order $order = wc_get_order( $order_id ); // Do...

Show product-category thumbnails in loop which have n price of products in woocommerce

php,wordpress,woocommerce,category

I tried this code and get succeed. //backend option for price $value= get_option('price'); // the query $args = array ('meta_query' => array( array( 'key' => '_price', 'value' => $value, 'compare' => '>=', 'type' => 'NUMERIC', ), ), 'post_type' => 'product', ); // The Query $query = new WP_Query( $args );...

how to set different minimum order amount for free shipping for different user roles in woocommerce

php,wordpress,woocommerce

Have you considered using a plugin for this? I've created a plugin that can be configured with conditions, including based on user role. https://wordpress.org/plugins/woocommerce-advanced-free-shipping/...

WooCommerce REST API v2: How to process payment?

rest,woocommerce,payment-gateway

As helgatheviking concurred, there currently isn't a way to process payment of an order with the WooCommerce REST API. I ended up writing a hook into the the woocommerce_api_create_order filter that immediately processes the order for payment when the order is created. If the processing fails, then the errors are...

Woocommerce API returns 1, but works

php,wordpress,woocommerce

The reason might be that this action is been called via some ajax. In wordpress the ajax default returns the die() function before the function ends. So if we don't specify die() in our custom function it will append 1 with the data in our callback. So you have to...

Woocommerce Return False with message

php,wordpress,woocommerce

You can have a $message variable that is empty for true and contains a messages (in HTML) for false: PHP $message = ""; ... function disable_cart_for_over_fifty_k( $purchasable, $product ){ global $message; if( $product->get_price() >= 50000 ) { $message = "<p class='errorMessage'>This product is over £50,000 - please contact us</p>"; return...

woocommerce conditional products/categories on user role

wordpress,wordpress-plugin,woocommerce

To achieve this you can use the Free Groups plugin. But for that you must add all the wholesalers to one group say wholesale group 1. Then while editing any product you get an option to access to, add the wholesaler group 1 there. The product will now be only...

How to control HTML output of variable $image in WooCommerce

wordpress,woocommerce,thumbnails

HTML5Blank has a pretty good example that should answer some of your questions, take a look here - spefically line 206 and the actions it's hooked into: add_filter('post_thumbnail_html', 'remove_width_attribute', 10 ); function remove_width_attribute( $html ) { $html = preg_replace( '/(width|height)="\d*"\s/', "", $html ); return $html; } To specifically target the...

How can I set the Image of woocommerce category as the background of the category title? [duplicate]

php,html,wordpress,woocommerce

<?php if ( apply_filters( 'woocommerce_show_page_title', true ) ) : ?> <h1 style="background: url(<?php if ( is_product_category() ){ global $wp_query; $cat = $wp_query->get_queried_object(); $thumbnail_id = get_woocommerce_term_meta( $cat->term_id, 'thumbnail_id', true ); $image = wp_get_attachment_url( $thumbnail_id ); echo "'{$image}'"; } ?>);" class="page-title"><?php woocommerce_page_title(); ?></h1> I followed How to display Woocommerce Category image? and...

How to add user roles dropdown in registration and login woocommerce wordpress

wordpress,woocommerce,wordpress-plugin-dev,wordpress-loop

Try this : function ts_wp_dropdown_roles( $selected = '' ) { $p = ''; $r = ''; $editable_roles = array_reverse( ts_get_editable_roles() ); foreach ( $editable_roles as $role => $details ) { $name = translate_user_role($details['name'] ); if ( $selected == $role ) // preselect specified role $p = "\n\t<option selected='selected' value='" ....

Woocommerce Filter Product by Attribute

filter,attributes,woocommerce,product

You should be able to achieve what you're looking to do by using a tax_query combined with your WP_Query. Attached is a small example using a 'Brand' attribute and the 'EVGA' term inside it (which WooCommerce will turn into 'pa_brand' - product attribute brand). $query = new WP_Query( array( 'tax_query'...

How get variation's stock quantity woocommerce

php,woocommerce,stock,variations,variation

Ok, with this I can take the quantity. But is not useful. With this I can prepare a code that make differents sentences, one for each product, and show it when a variation would be selected using jquery. But this is not good idea. Is not elegant. I though existed...

woocommerce - make order notes required

wordpress,woocommerce

Change the action from 'woocommerce_checkout_process' to 'woocommerce_after_checkout_validation'. add_action('woocommerce_after_checkout_validation', 'my_custom_checkout_field_process'); function my_custom_checkout_field_process() { // Check if set, if its not set add an error. if ( ! $_POST['order_comments'] ) wc_add_notice( __( 'Please enter something into this new shiny field.' ), 'error' ); } ...

WooCommerce - Checking for brand page

php,wordpress,wordpress-plugin,woocommerce

I managed to find a solution to this problem using the is_tax() function that Wordpress provides for using on custom taxonomy archives. Here's my code to check if I'm on a brand page or not. Have tested and appears to be working fine. function is_brand_page_check() { if (is_tax( 'product_brand' ))...

Upgrade to Woocommerce 2.3.10 caused checkout to block

php,wordpress,woocommerce

I finally found the answer to the problem. I had inserted "echo" statements in the functions.php for my theme and this was causing a hidden error condition that I could not see. I removed the "echo" statements and things started working again.