Woocommerce – Adding row to cart table

You already have the right “action”, which is woocommerce_after_cart_contents. But when I tried the markup you used: function quality_certificates(){ echo ‘<tr>TEST</tr>’; } this was the visual output: (I actually initially tested with the Twenty Seventeen theme; sorry about that. But this one is tested with Storefront) Then I started thinking that the problem might be … Read more

Get user custom field value on function.php

EDIT I think the solution given by @dboris may work. Alternatively you could try to hook your email sending after the user registration like this global $uID; //to keep the value to reuse it later, null at this step function mailInscriptionSecteurRhone() { global $uID; $user_ID = $uID; $headers = array(‘Content-Type: text/html; charset=UTF-8’); $candidat = get_userdata( … Read more

Filter default_content only for products

default_content is a filter used in the backend. You don’t necessarily have anything in the loop so standard functions will probably fail. However, you’re given a second argument of type WP_Post. You can check its post_type easily and work from there. add_filter(‘default_content’, ‘WPSE_product_default_content’, 10, 2); function WPSE_product_default_content($post_content, $post) { if ($post->post_type !== ‘product’) return $post_content; … Read more

Issues with if, else, and elseif statements

Here is an alternative solution. I think it would be cleaner than adding all these if statements and page IDs. You can do this using CSS and the body class WP adds. For example, go to one of your single pages and look at the class on the body tag. You should see something like … Read more

Before saving post hook

Yep, it looks like there is no option how to stop post saving. I am checking wp-includes/post.php, and all I see is wp_insert_post_data filter where you can check and modify post data (before saving), but that’s all. Or … you can hook to save_post, and if there is something wrong with the post, then call … Read more

WordPress: Add custom add_filter for custom functions

You can use the apply_filters function: function koku_crm_send_sendgrid($sendgrid_api_key, $to, $subject, $text, $html) { $to = apply_filters( ‘koku_crm_send_to’, $to ); $sendgrid = new \SendGrid($sendgrid_api_key); $mail = new KCSendGrid\Mail(); $from = new KCSendGrid\Email(get_bloginfo( ‘name’ ), get_bloginfo( ‘admin_email’ )); $mail->setFrom($from); $mail->setSubject(html_entity_decode($subject, ENT_QUOTES, ‘UTF-8’)); $content = new KCSendGrid\Content(“text/plain”, $text); $mail->addContent($content); $content = new KCSendGrid\Content(“text/html”, $html); $mail->addContent($content); $personalization = new … Read more

Getting the post ID in parse_query

Thank you for your responses. After a bit of testing, I hooked onto WP (https://developer.wordpress.org/reference/hooks/wp/) which occurs near the end of the WordPress loading sequence, and it is now working: function wf_lang_query_check() { global $wp_query, $post; $lang = wf_get_lang(); if ( ( !is_admin() && $wp_query->is_main_query() ) && ( $lang && ( !in_array( $lang, wf_valid_lang() ) … Read more