WooCommerce Admin order – Only run action if user is loaded

One way of doing this is check with the get_current_user() and check if return something, if yes, run the code. Like the example below: add_action( ‘woocommerce_admin_order_data_after_order_details’, ‘ccef_order_switch_to’, 99 ); /** * Add a switch to user link on the order details. * * @param object $order The WC Order that we’re working with. */ function … Read more

Is there any way to pro-grammatically create product categories and assign thumbnails in PHP and WooCommerce?

wp_insert_term() works fine for this sort of thing. You haven’t given any context, but here’s a quick example I made that, on every page load, adds a random WooCommerce product category(not duplicates though), and an associated random image, from a list of image id’s in MY media library(change $existing_image_ids to your own ids for this … Read more

Woocommerce before and after shop loop not works

In core WooCommerce, the pagination is added via the woocommerce_pagination() function hooked to woocommerce_after_shop_loop, and the sorting and result counts are output by the woocommerce_result_count() and woocommerce_catalog_ordering() functions. If you look at the source for these functions, you can see that they display according to the main $wp_query, which will not contain any products because … Read more

Using the WordPress and WooCommerce REST APIs in the same Node app

I thought I’d share my solution for anyone working on a similar problem. I ended up switching to node-wpapi and using REST Autodiscovery to enable use of the WooCommerce & WordPress APIs from a single library. This can be done like so: const wpapi = require(‘wpapi’) let wp = new wpapi({ endpoint: ‘http://your.wp.site/wp-json/’, username: ‘user’, … Read more

Specifically Link To the “Leave a review” part of product page? [closed]

You would probably need to do this with jQuery by detecting the hash value and activating the class based on that. Something like this might work: add_action(‘wp_footer’, ‘custom_review_form_activate’); function custom_review_form_activate() { echo “<script>if (window.location.hash == ‘review_form’) { jQuery(‘.reviews_tab’).addClass(‘active’); }</script>”; } (Of course if your theme or customizations already have some jquery you can add it … Read more

Woocommerce : read [max_qty] using backorder

Solved using this code: if ($product->is_type( ‘variable’ )){ // Get the available variations for the variable product $available_variations = $product->get_available_variations(); // Initializing variables $variations_count = count($available_variations); $loop_count = 0; // Iterating through each available product variation foreach( $available_variations as $key => $values ) { $loop_count++; // Get the term color name $attribute_color = $values[‘attributes’][‘attribute_pa_size’]; $wp_term … Read more