Make the first item as default on Woocommerce product category items list

Try the following improved code, to get “active” on the first item: <?php $product_cats = get_terms([ ‘taxonomy’ => ‘product_cat’, ‘hide_empty’ => true, ‘parent’ => 0, ‘fields’ => ‘names’ // Term names ]); foreach ( $product_cats as $key => $parent_term_name ) { printf( ‘<button class=”tablinks %s” onclick=”%s”>%s</button>’, $key === 0 ? esc_attr( ‘active’ ) : ”, … Read more

Get stock by custom meta field on all Woocommerce variable products

The following function will give you an array with the calculated stock quantity from all product variations for each custom meta field “Brand” value, using WPDB Class (a SQL query): global $wpdb; $results = $wpdb->get_results( ” SELECT pm.meta_value as brand, SUM(pm2.meta_value) as stock FROM {$wpdb->prefix}postmeta pm INNER JOIN {$wpdb->prefix}posts p ON pm.post_id = p.post_parent INNER … Read more

Display description on cart page

$_product object is product variation object. You have to first get the parent product id and then get the description of parent product. $parent_product_id =$_product->get_parent_id(); $parent_product = get_post($parent_product_id); echo $content = $parent_product->post_content; Or echo $_product->parent->description;

how to get URL of media uploaded to WordPress via media_handle_sideload()

To get the URL of the uploaded image/attachment, you can use wp_get_attachment_url() (which always returns the full-sized image URL) or wp_get_attachment_image_url() for image attachment: // This is how you should call uploadImageToMediaLibrary(); assign the value to $att_id. $att_id = uploadImageToMediaLibrary($post->ID, $external_url, “custom_alt”); $url = wp_get_attachment_image_url( $att_id, ‘full’ ); // full-sized URL But to set the … Read more

Filter WooCommerce Orders query with user meta data

I see 2 possible ways: 1) Using your WP_User_Query in a WC_Order_Query with the customer_id argument this way: // Users query $user_ids = (array) get_users([ ‘role’ => ‘customer’, ‘number’ => – 1, ‘fields’ => ‘ID’, ‘meta_query’ => [ ‘relation’ => ‘OR’, [ ‘key’ => ‘unsubscribed’, ‘compare’ => ‘!=’, ‘value’ => 1 ], [ ‘key’ => … Read more

Get rid of product images mobile swipe functionality from WooCommerce single product [closed]

Everything required is located on Class WC_Frontend_Scripts source code: To target mobile devices, you can use the WordPress conditional tag wp_is_mobile(). A) For the Photoswipe functionality you have essentially 2 hooks: woocommerce_single_product_photoswipe_enabled to disable it. woocommerce_single_product_photoswipe_options to change options (see below). 1) To disable it, you will use: add_filter( ‘woocommerce_single_product_photoswipe_enabled’, ‘__return_false’ ); or targeting mobile … Read more

Change WooCommerce product price based on category and GEO IP country

WooCommerce has already a Geo IP feature that you can use through WC_Geolocation Class. I have revisited completely your code. To target a product category you can use WordPress has_term() function on WooCommerce Product Category custom taxonomy as follow: function is_geo_country_belgium() { // Get an instance of the WC_Geolocation object class $geolocation_instance = new WC_Geolocation(); … Read more

Remove Order List Row Link in WooCommerce Admin?

Based on class-wc-admin-list-table-orders.php (order column on line 173) there doesn’t seem to be a filter to change the markup. To circumvent this, perhaps you could add a js/jQuery script, to admin_footer or with admin_enqueue_scripts, which either adds the necessary class(es), removes href or changes it to #, or with some event delegation wizardry have your … Read more

Woocommerce – Override the default templates location under the theme directory

I believe you can use the woocommerce_template_path hook/filter: // $path defaults to ‘woocommerce/’ (in your theme folder) add_filter( ‘woocommerce_template_path’, function( $path ){ $my_path = get_stylesheet_directory() . ‘/plugins/woocommerce/’; return file_exists( $my_path ) ? ‘plugins/woocommerce/’ : $path; } ); It should work whether you’re overriding only specific files or all — i.e. you copy all files and … Read more

Update html tag class values based on Woocommerce product attribute dropdown selection [closed]

You can use the following to add/remove a customized class to #primary selector based on the selected product attribute “Color”: <script type=”text/javascript”> jQuery(function($){ var p = ‘#primary’, c = $(p).prop(‘class’), s=”select[name=”attribute_pa_color”]”; // On start if( $(s).val() !== ” ) { $(p).prop(‘class’, ‘background-‘+$(s).val()); } // On select (blur live event) $(s).blur( function() { var b = … Read more