How to rewrite product permalinks in Woocommerce to use category slugs

Ok, so the second code is: function custom_rewrite_basic() { $prodCatArgs = [‘taxonomy’ => ‘product_cat’]; $wooCats = get_categories($prodCatArgs); $catSlugs = []; foreach($wooCats as $wooCat) { $catSlugs[] = $wooCat->slug; } add_rewrite_rule( ‘^(‘.implode(‘|’, $catSlugs).’)/([^/]*)/?’, ‘index.php?post_type=product&category=$matches[1]&product=$matches[2]’, ‘top’ ); flush_rewrite_rules(); } add_action(‘init’, ‘custom_rewrite_basic’);

How to get woocommerce selected variation from order object

Following below code according your need To get the selected variation attributes using get_variation_attributes( ) method. // Get an instance of the WC_Order object from an Order ID $order = wc_get_order( $order_id ); // Loop though order “line items” foreach( $order->get_items() as $item_id => $item ){ $product_id = $item->get_product_id(); //Get the product ID $quantity = … Read more

Woocommerce Email attachments not working – file not being attached

Apparently Woocommerce need a local path and not a URL to the file. In order to fix I used this: function attach_order_notice ( $attachments, $email_id, $order ) { // Only for “New Order” email notification (for admin) //if( $email_id == ‘new_order’ ){ $file_path = wp_upload_dir()[‘path’]; $file_name = get_field( ’email_file_attachment’, ‘options’ )[‘filename’]; $attachments[] = $file_path . … Read more

How to check woocommerce single product tag

To check if the product has the tag, you can use has_term() or is_object_in_term(). has_term( ‘tag_slug_or_ID’, ‘product_tag’ ) Or: // checking if the product has any tag is_object_in_term( $product_id, ‘product_tag’ ) // checking if the product has a given tag is_object_in_term( $product_id, ‘product_tag’, ‘tag_slug_or_ID’ )

How to change this simple code so that it sends the email notification after payment in WooCommerce?

The hook you’re looking for is “woocommerce payment complete” and it’s triggered once an order has been marked as “complete”. In the function called by that hook, you need to grab all coupons applied to the order, and check if any of them is the one you’re looking for. add_action( ‘woocommerce_payment_complete’, ‘so_payment_complete’ ); function so_payment_complete( … Read more

get taxonomy thumbnail and use it as a variable in code

You have ‘taxonomy’ => ‘product_cat’ in your code, so most likely you have Woocommerce, and we need to get a category picture from there. Try this code <?php $args = array( ‘taxonomy’ => ‘product_cat’, ‘title_li’ => ”, ‘hide_empty’ => 0, ‘echo’ => 0, ‘show_count’ => 0, ‘style’ => ”, ‘parent’ => 0 ); $get_cats = … Read more

WooCommerce – Add product with image via REST API

Ok my mistake, you can see my images array was not quite right: This is correct: ‘images’ => [ [ ‘src’ => ‘http://demo.woothemes.com/woocommerce/wp-content/uploads/sites/56/2013/06/T_2_front.jpg’ ], [ ‘src’ => ‘http://demo.woothemes.com/woocommerce/wp-content/uploads/sites/56/2013/06/T_2_back.jpg’ ] ], This was mine: ‘images’ => [ ‘src’ => ‘http://demo.woothemes.com/woocommerce/wp-content/uploads/sites/56/2013/06/T_2_back.jpg’, ], Thought it would be best to leave this question/answer as over the years there are … Read more

Adding Product Name on Admin Panel Order list and User’s My-Account Order List

Add this code to your functions.php this will add an extra column to the listing table with Product name. Like 1 x Netflix Premium. If multiple that will be visible too. add_filter(‘manage_edit-shop_order_columns’, ‘_order_items_column’ ); function _order_items_column( $order_columns ) { $order_columns[‘order_products’] = “Product Name”; return $order_columns; } add_action( ‘manage_shop_order_posts_custom_column’ , ‘_order_items_column_cnt’ ); function _order_items_column_cnt( $colname ) … Read more

WooCommerce minimum order amount for specific country excluding local pickup [closed]

Hey just wanted to let you know! I was able to achieve my desired result with this code! // Set a minimum amount of order based on shipping zone & shipping method before checking out add_action( ‘woocommerce_check_cart_items’, ‘cw_min_num_products’ ); // Only run in the Cart or Checkout pages function cw_min_num_products() { if( is_cart() || is_checkout() … Read more