Custom Text in WooCommerce Order Processing Email Based on Products

Try something like this: <?php $order_id = $order->get_id(); $order = wc_get_order( $order_id ); $items = $order->get_items(); $is_valid = null; foreach ( $items as $item_id => $item_data ) { $product = $item_data->get_product(); $categories = array(); $terms = get_the_terms( $product->get_id(), ‘product_cat’ ); if ( is_wp_error( $terms ) || empty( $terms ) ) { continue; } foreach ( … Read more

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

Custom Theme, Custom shortcode not working

I would recommend using single quotes if you want to include some HTML, also you need to return something otherwise nothing happens. // WP Shortcode function text_shortcode() { return ‘<strong>bold text:</strong> <a href=”https://wordpress.stackexchange.com/questions/318934/shortcode-returns-escaped-html-tags”>See wordpress.stackexchange.com</a>’; } add_shortcode(‘bold-text’, ‘text_shortcode’); Your WordPress shortcode would be: [bold-text] See my other answers with examples: – Shortcode created to check language … Read more

Retrieving Author ID in wp-admin area

It can be done like this without having to rely on the $post global. if ( is_admin() ) { if( isset( $_GET[‘post’] ) && isset( $_GET[‘action’] ) && $_GET[‘action’] === ‘edit’ ) { $post_id = $_GET[‘post’]; $current_post = get_post($post_id); $author_id = $current_post->post_author; } } The query string variable post is always the post_id you are … Read more

class click counter save number

Made ajax call as a function to avoid the Console Error 400 Post. It opens the channel and I was able to get the parameters passed. counter.js jQuery(document).on(‘click’,’.counter’,function(e){ testAjax(the_ajax_script.ajaxurl); }); function testAjax(link) { $.ajax({ url: link, type: ‘post’, data: { ‘action’: ‘set_button_count’, ‘increase’ : ‘1’ }, success: function(data) { jQuery(‘.count’).html(data); } }); } In functions.php … Read more

get current product name in functions.php

Please check below code : add_action( ‘woocommerce_single_product_summary’,’content_after_addtocart_button’ ); function content_after_addtocart_button() { global $product; $product_title = $product->get_name(); $product_price = $product->get_price(); echo ‘<div class=”content-section”> <a href=”https://wordpress.stackexchange.com/questions/340361/mailto:[email protected]?&subject=Richiesta Informazioni&body=” . $product_title . ‘??? ‘ . $product_price . ‘ ??? “> <input type=”button” value=”Richiedi Informazioni”/ ></a></div>’; }

display month in french in wordpress/php?

there is a custom function in wordpress called date_i18n. so basically you do echo date_i18n( ‘H:i d-m-Y’, $ts ); without the setLocale stuff.. find the function date_i18n and its parameters here. you could even build in your translation all in there, without the language check before: date_i18n( __( ‘H:i d-m-Y’, ‘textdomain’ ) ); (replace ‘textdomain’ … Read more

understanding if statement [closed]

the code is executed when post type is post or page No, only if the post type is page (because of the ‘page’ == $screen->id). Because that if statement actually checks if the current admin screen is the one for editing or creating a Page (post type of page), where the URL looks like so: … Read more