This is a solution for creating a staff page using the WP Bakery post grid element. It uses a pop-up/overlay to display details for each person instead of linking to a page. This assumes that you have WP Bakery, Custom Post Types UI, and Advanced Custom Fields plugins installed. It also uses a modal from… Read more »
Category: WordPress
Embedding YouTube videos directly into your page can increase the load time significantly, especially when multiple videos are embedded. One solution is to load thumbnail images instead, and then load the videos only when clicked. /* Generate post-load HTML wrapper for a YouTube video. */ function myprefix_youtube_postload($youtube_id, $thumb_size = ‘hq’) { $thumb_sizes = array( ‘hq’… Read more »
Sometimes it is nice to have a way to quickly search for users/customers without having to use the WordPress default user search. Especially when your user base is large, this can be a very slow process. This code adds a quick search feature to the top admin bar, as well as submenu item that appears… Read more »
If you want to remove links from the product names in the WooCommerce cart you can use this simple filter. It returns the product name, without anything else appended. function myprefix_woocommerce_cart_item_name($name, $cart_item, $cart_item_key) { $_product = apply_filters( ‘woocommerce_cart_item_product’, $cart_item[‘data’], $cart_item, $cart_item_key ); return $_product->get_name(); } add_filter(‘woocommerce_cart_item_name’, ‘myprefix_woocommerce_cart_item_name’, 10, 3);
This will add a “Customer Orders” link on the customer/user profile edit page. Handy when trying to find a full history of a customer’s orders. // Show a link to the list of orders for a user function myprefix_user_orders_link(WP_User $user) { if (!ssc_is_admin()) { return; } $link = admin_url(‘edit.php?s&post_type=shop_order&_customer_user=’.$user->ID); echo ‘<tr><td colspan=”2″><a href=”‘ . $link… Read more »
Users can register on both the account registration page and during checkout (if enabled). This code will add a field for the user to confirm the password that they entered in the primary password field. // Validate password match on the registration page function myprefix_registration_errors_validation($reg_errors, $sanitized_user_login, $user_email) { global $woocommerce; extract( $_POST ); if (… Read more »
If you’re creating a plugin and you want an easy way to generate HTML emails within a standard template, then this code should get you most of the way there. It allows for passing an array of data to the template, which is a must-have feature. Importantly, it also provides a way for users to… Read more »
In some cases PO Boxes are not allowed when shipping certain products or when using specific carriers. The code below disables PO Boxes for all shipping addresses. You can add additional logic if you only need to disallow PO Boxes in certain cases. Create a function for checking if a string is a PO Box…. Read more »
There are numerous plugins that offer this functionality. For example, the User Role Editor plugin has an option to hide the admin bar for each user role. If, however, you want a quick solution to implement this in your code without the need for installing a plugin, here’s how you can do that. /* Hide… Read more »
The default current_user_can() and user_can() functions are adequate for checking if a user belongs to a role, but I find the function names confusing. Also, those functions check both roles and capabilities, which seems inefficient if one only needs to check the role. This function does one thing only: check if a user belongs to… Read more »