PHP Code Snippets/Functions Reusable Custom Blocks

Custom number of entry selection

<?php$args = array( ‘post_type’ => ‘sample’, ‘post_status’ => ‘publish’, ‘posts_per_page’ => -1,);$query = new WP_Query($args);$total_posts = $query->found_posts;$numbers = array(1, 2, 20);if ($total_posts > 0) { $numbers = range(1, min(20, $total_posts));}?><label for=”post-number”>Show</label><select name=”post-number” id=”post-number” class=”post-number-select”> <option value=”-1″ selected>All</option> <?php foreach ($numbers as $number) : ?> <option value=”<?= $number; ?>”><?= $number; ?></option> <?php endforeach; ?></select><label>entries</label> $(‘.post-number-select’).on(‘change’, function […]

Reusable Custom Blocks

Custom Post Type with Custom Filter

Requirements: Copy and paste this code into the custom block. You may modify it as needed to meet the client’s requirements. <?php /* Block Name: Custom Resources */ $args = array( ‘post_type’ => ‘resources_post’, ‘post_status’ => ‘publish’, ‘posts_per_page’ => -1, ‘order’ => ‘ASC’, ); $categories = get_categories(); $used_categories = array(); ?> <div class=”category-filter”> <?php foreach […]

Reusable Custom Blocks

Video Testimonial Slider

Copy and paste this code to the custom block. <?php /** Block Name: Testimonial Slider ** Author Name: MonLigan * */ $args = array( ‘post_type’ => ‘testimonial’, ‘post_status’ => ‘publish’, ‘posts_per_page’ => -1, ‘order’ => ‘ASC’, ); ?> <style> .testimonial_content video{ width: 941px; height: 461px; } /* DOTS */ .testimonial-slider .slick-dots li button { cursor:pointer; […]

PHP Code Snippets/Functions

Learndash Extract User details

Please paste this code into the functions.php file and then copy the shortcode [learndash_user_courses] onto a blank page. This will display users’ details alongside their enrolled courses, groups, specific roles, and other relevant information. // List of Users function display_users_enrolled_courses() { // Initialize the output buffer ob_start(); // Get all users $users = get_users(); foreach […]

Reusable Custom Blocks

Custom Banner Slider

To create a custom Banner Slider, please follow these steps and instructions. Note: You may modify this to suit the design and theme of your site. Insert this code into the functions.php wp_enqueue_style( ‘slick-css’, ‘https://cdnjs.cloudflare.com/ajax/libs/slick-carousel/1.9.0/slick.css’ ); wp_enqueue_script( ‘slick-js’, ‘https://cdnjs.cloudflare.com/ajax/libs/slick-carousel/1.9.0/slick.min.js’); Insert this code into the Custom Block. Note: You may modify this code to suit the […]

PHP Code Snippets/Functions Reusable Custom Blocks

Retrieving Product Variations.

<?php if (wc_get_product(get_the_ID())) { $product = wc_get_product(get_the_ID()); $html = “<ul class=’price-list’>”; $htmlRfq = “<div class=’rfq-variations’>”; $attributesList = array(); $rfqDisplayed = false; if ($product->is_type(‘variable’)) { $vars = $product->get_available_variations(); for ($i = 0; $i < count($vars); $i++) { $display_price = $vars[$i][‘display_price’]; if ($display_price == ‘0’ && !$rfqDisplayed) { $htmlRfq .= “<div class=’single-rfq’> > ” . str_lreplace(‘-‘, ‘ […]

PHP Code Snippets/Functions

Remove a specific menu from the ‘My Account’ page.

Insert this code into functions.php add_filter( ‘woocommerce_account_menu_items’, ‘misha_remove_my_account_links’ ); function misha_remove_my_account_links( $menu_links ){ unset( $menu_links[ ‘edit-address’ ] ); // Addresses unset( $menu_links[ ‘dashboard’ ] ); // Remove Dashboard unset( $menu_links[ ‘payment-methods’ ] ); // Remove Payment Methods unset( $menu_links[ ‘orders’ ] ); // Remove Orders unset( $menu_links[ ‘downloads’ ] ); // Disable Downloads unset( $menu_links[ […]

PHP Code Snippets/Functions

Use a shortcode to add a custom product attribute.

Insert this code into functions.php function custom_product_attributes_shortcode() { ob_start(); global $product; // Check if we’re on a single product page if ( is_product() ) { echo ‘<div class=”product-specs selected-attributes-info”>’; // Get the product attributes $attributes = $product->get_attributes(); $attribute_count = count( $attributes ); if ( $attribute_count === 0 || $attribute_count <= 2 ) { echo ‘<p>Not […]

PHP Code Snippets/Functions

Customize the product layout with specific attributes.

Insert this code into functions.php remove_action( ‘woocommerce_after_shop_loop_item_title’, ‘woocommerce_template_loop_price’, 10 ); add_action(‘woocommerce_after_shop_loop_item_title’, ‘woocommerce_after_shop_loop_item_title_custom’, 10); function woocommerce_after_shop_loop_item_title_custom() { global $product; $attributes = $product->get_attributes(); $colors = $attributes[“pa_color”]; $weight = $attributes[“pa_fabric-weight”]; $width = $attributes[“pa_fabric-width”]; $attributes = $product->get_attributes(); $attribute_count = count( $attributes ); if( $colors ){ $colorTerms = $colors->get_terms(); $selectedAttributesCount = count( $colorTerms ); echo ‘<div class=”product-attributes”>’; echo ‘<span class=”product-attributes-text” […]

CSS Code Snippets JS Code Snippets/Functions PHP Code Snippets/Functions

Change the Woocommerce “Add to Cart” total item notification to “Total Product Entry.”

Insert this code into the functions.php function child_theme_enqueue_styles() { // cart page wp_localize_script( ‘global-js’, ‘customMiniCartParams’, array( ‘totalUniqueProducts’ => custom_get_total_unique_products_in_cart(), ) ); } // Modify your PHP function to return the total unique products as a JavaScript variable function custom_get_total_unique_products_in_cart() { $total_unique_products = 0; // Get the cart contents $cart = WC()->cart->get_cart(); // Create an array […]