Add Custom Cart Item Data in WooCommerce

WooCommerce lets you add your own custom cart item data by using hooks provided by WooCommerce. Here’s a full plugin code you can modify accordingly: /** * Plugin Name: Product Course * Description: Add Custom Cart Item Data in WooCommerce * Version: 1.0 * Author: Gaurav */ function wd_get_item_data($item_data, $cart_item_data) { if (isset($cart_item_data[“custom_date”])) { $item_data[]…

Create a custom Twig filter in Drupal 8

Create hello_world folder in modules/custom/ folder with the following files, 1. hello_world.services.yml // It would contain following lines, services: hello_world.twig_extension: arguments: [‘@renderer’] class: Drupal\hello_world\TwigExtension\RemoveNumbers tags: – { name: twig.extension } 2. src/TwigExtension/RemoveNumbers.php It would contain followings in that: namespace Drupal\hello_world\TwigExtension; class RemoveNumbers extends \Twig_Extension { /** * Generates a list of all Twig filters that…

Decode HTML Tags from Woocommerce Error Message

Decode HTML Tags from Woocommerce Error Message

This is live scenerion when we used checkout custom plugin and passed HTML link inside label, this HTML tag will display in woocommerce error as required field. To show HTML decode or remove HTML tags I prefered to use wordpress predefined function wp_specialchars_decode with ‘ENT_QUOTES’ inside filter woocommerce_add_error. Below filter will run each time when…

Woocommerce Filter

Woocommerce Filter

Remove product link on checkout page Using add filter woocommerce_cart_item_name we can modify woocommerce product name with condition check for checkout page. //remove product link on checkout page add_filter(‘woocommerce_cart_item_name’, ‘custom_filter_wc_cart_item_remove_link’, 10, 3); function custom_filter_wc_cart_item_remove_link($product_name, $cart_item, $cart_item_key) { if (is_checkout()) { $wccart = new WC_Cart(); $name = apply_filters(‘woocommerce_cart_item_remove_link’, sprintf( ‘ ‘, esc_url($wccart->get_remove_url($cart_item_key)), __(‘Remove this item’, ‘woocommerce’),…

How to hide and disable WP plugin updates

How to hide and disable WP plugin updates

Sometimes when situation becomes very unfavourable and installed wordpress plugin not supported filter and hook to add_filters, In these type of situation we can hide or disable plugin updates. 1. Go to particular plugin folder and increase Version to very higher which actually pluing will never reach in this era. Example: ajax-search.php Version: 999.0.0 2….

Adding Custom Field in Export Products Dropdown Woocommerce

Adding Custom Field in Export Products Dropdown Woocommerce

When we need to add custom field in dropdown list of Woocommerce product export filter. We can add below Filter Hook. By defualt when we select ‘Export all columns’ Woocommerce will export all values. function add_export_data( $product, $name ) { $pid = $product->get_id(); if($product->get_type() == ‘variation’){ $pid = $product->get_parent_id(); } $sale_code = get_post_meta( $pid, $name,…

How to Enable Temporary URL From WHM

How to Enable Temporary URL From WHM

Advantage of enabling temparory URL (Example: http://yourdomain.com/~username) * When we develop website or don’t have domain name. * For staging website Steps to enable temporary URL but recommended to disable once development phase done. 1) Login to WHM. 2) Navigate to ‘Security Center’. 3) Click on the icon ‘Apache mod_userdir Tweak’. 4) Uncheck the option…

How to protect file if User not logged in WordPress

How to protect file if User not logged in WordPress

If User not logged In and try to download .PDF file or any other extension below code will protect file even if User try to download via direct link. 1. Add code in function.php or your plugin file. Update permalink after adding this code. This code will add htaccess rules in .htaccess file. add_filter(‘mod_rewrite_rules’,’output_htaccess’);function output_htaccess(…

Hide Zero Value On Zero Cost Shipping Methods WooCommerce

Hide Zero Value On Zero Cost Shipping Methods WooCommerce

In WooCommerce if you use Local Pickup or other methods of shipping that don’t have a preset or calculated cost, the shipping labels on both the cart and checkout to appear with $0.00 price, like this: Local pickup: $0.00 This was an intentional change by WooCommerce. You can read the conversation and reasoning behind it…