How to optimize update_post_meta?

To achieve what you want you’re better creating an associative array and then walking over it with a foreach loop as shown below : $data = array( ‘_shipping_first_name’ => $order->get_billing_first_name(), ‘_shipping_last_name’ => $order->get_billing_last_name(), ‘_shipping_company’ => $order->get_billing_company(), ‘_shipping_address_1’ => $order->get_billing_address_1(), ‘_shipping_address_2’ => $order->get_billing_address_2(), ‘_shipping_postcode’ => $order->get_billing_postcode(), ‘_shipping_city’ => $order->get_billing_city(), ‘_shipping_state’ => $order->get_billing_state(), ‘_shipping_country’ => $order->get_billing_country() ); … Read more

How to add product filter dropdown in woo commerce order page?

Here is solution for above questions // Custom function to get the product names, that appear in the existing orders function get_product_names() { global $wpdb; return $wpdb->get_col(” SELECT DISTINCT order_item_name FROM {$wpdb->prefix}woocommerce_order_items WHERE order_item_type=”line_item” “); } function action_restrict_manage_posts( $post_type, $which ) { global $pagenow; // Compare if ( $post_type === ‘shop_order’ && $pagenow === ‘edit.php’ … Read more

Add SKU in Product Title

In the above code. You are adding the SKU code on all the product on every post saved. Instead of all post you should just update only product which you are updating. And send you should check if SKU already added then no need to add it again. // Call this function each time a … Read more

Can’t filter out variable products in sale from wp_get_products loop (or shortcode) [closed]

Ok, after some digging around I’ve finally found the answer I was looking for. Turns out there is a function called wc_get_product_ids_on_sale() you can use to exclude those ID’s from wc_get_products. So for anyone having the same problem.. you can use ‘exclude’ => wc_get_product_ids_on_sale() within your wp_get_products args and you’re all set!

require_once() if a product in woocommerce contains a tag [closed]

has_term() is a template function therefore it does not work if you use it straight in functions.php which is loaded well before knowing if the current object is a product page. So if you use it in functions.php you could do: add_action(‘template_redirect’,’my_inclusion_function’); function my_inclusion_function(){ if(is_product() && has_term(‘xyz’, ‘product_tag’)){ require_once( WP_CONTENT_DIR.’/path/file.php’); } } is_product() checks if … Read more

WooCommerce Product detail page: Add content under thumbnails [closed]

In woocommerce/templates/content-single-product.php you can see that woocommerce_show_product_images is hoooked with a priority of 20. if you want your custom function to render below the images, but above the summary, you need to set the priority to greater than 20. I think the code below should do it: add_action(‘woocommerce_before_single_product_summary’, ‘bbloomer_add_below_prod_gallery’, 30); function bbloomer_add_below_prod_gallery() { global $product; … Read more

Order with custom order status disappeared once the page is refreshed

My bad, I was using add_filter() instead of add_action() in ‘init’ hook. The following link is the perfect solution for adding custom order status and email notification. My Woocommerce version is Version 5.8.0. https://www.codegrepper.com/code-examples/whatever/woocommerce_email_actions The code snippet is as below : // Add custom status to order list add_action( ‘init’, ‘register_custom_post_status’, 10 ); function register_custom_post_status() … Read more