How To Fix Uncaught TypeError: Unsupported operand types in ‘class-wc-cart.php’

The error message "Uncaught TypeError: Unsupported operand types: string + float" typically occurs in WordPress or WooCommerce when there is a compatibility issue between your code or plugins and the PHP version you are using, particularly when using PHP 8 or higher. This error message indicates that you are trying to perform an unsupported operation, in this case, attempting to add a string and a float. Here are some common reasons for encountering this error and steps to resolve it: Plugin or Theme Compatibility: Outdated or poorly coded plugins or themes might not be compatible with the latest PHP versions. Check if any of your plugins or themes need updates to be compatible with PHP 8 or higher. You can do this by visiting the plugin or theme's official website or repository.Deprecated Functions: PHP 8 introduced many changes, including the removal of several deprecated functions and features. Review your code, plugins, or themes to ensure that you are not using any deprecated...
Read More
How to replace Woocommerce emails addresses section with custom data

How to replace Woocommerce emails addresses section with custom data

Today is another seemingly simple task that nevertheless could not be solved with either Stackoverflow or Chat-GPT :)We need replace the customer shipping address in the email template for WooCommerce order notifications for some shipping method. The Stackoverflow solution add_action( 'woocommerce_email_customer_details', 'sent_to_admin_custom_email_addresses', 5, 4 ); function sent_to_admin_custom_email_addresses( $order, $sent_to_admin, $plain_text, $email ){ if( in_array( $email->id, array( 'new_order', 'cancelled_order', 'failed_order' ) ) ) { $mailer = WC()->mailer(); remove_action( 'woocommerce_email_customer_details', array( $mailer, 'email_addresses' ), 20 ); add_action( 'woocommerce_email_customer_details', 'custom_email_addresses', 20, 1 ); } } function custom_email_addresses( $order ) { if ( is_a( $order, 'WC_Order' ) ) : $text_align = is_rtl() ? 'right' : 'left'; $address = $order->get_formatted_billing_address(); ?><table id="addresses" cellspacing="0" cellpadding="0" style="width: 100%; vertical-align: top; margin-bottom: 40px; padding:0;" border="0"> ...
Read More
Telegram Bot Hosting

Telegram Bot Hosting

VPS and services There are several services that allow you to host a Telegram bot on a VPS for free. Here are a few options: Heroku: Heroku is a cloud platform that allows you to deploy, manage, and scale web applications. You can use it to host your Telegram bot for free. Heroku provides a free tier with limited resources, which should be enough to host a simple Telegram bot.AWS Free Tier: Amazon Web Services (AWS) provides a free tier that includes access to many of its services, including Amazon Elastic Compute Cloud (EC2). You can use EC2 to host your Telegram bot for free, as long as you stay within the free tier limits.Google Cloud Platform Free Tier: Google Cloud Platform also provides a free tier that includes access to several of its services, including Compute Engine. You can use Compute Engine to host your Telegram bot for free, as long as you stay within the free tier limits.DigitalOcean: DigitalOcean is...
Read More
How To Remove Product Name From Breadcrumbs in Woocommerce

How To Remove Product Name From Breadcrumbs in Woocommerce

If you need to remove last element from breadcrumbs, you must:1. In the folder with your theme, create a folders "woocommerce/global" wp-content/themes/your-theme/woocommerce/global 2. Then copy ffrom Woocommerce plugin (or just create) file "breadcrumbs.php" wp-content/themes/your-theme/woocommerce/global/breadcrumbs.php 3. Replace (paste) the next code in breadcrumbs.php: <?php if ( ! defined( 'ABSPATH' ) ) { exit; } if ( ! empty( $breadcrumb ) ) { echo $wrap_before; foreach ( $breadcrumb as $key => $crumb ) { echo $before; if ( ! empty( $crumb[1] ) && sizeof( $breadcrumb ) !== $key + 1 ) { echo '<a href="' . esc_url( $crumb[1] ) . '">' . esc_html( $crumb[0] ) . '</a>'; } else { if(!is_singular()){ echo esc_html( $crumb[0] ); ...
Read More

Woocommerce: Get All Shipping Methods in Admin With Custom Titles and Instance ID

You can foun many code snippets to get list of all available shipping methods based on order or cart object.But if you need to get this list in admin area for some purpose in your plugin, etc. you can use this code snippet: $delivery_zones = WC_Shipping_Zones::get_zones(); foreach ((array) $delivery_zones as $key => $the_zone) { echo "<b>" . $the_zone['zone_name'] . "</b><br>"; foreach ($the_zone['shipping_methods'] as $value) { //print_r($value); echo $value->title . " ( " . $value->method_title . " - " . $value->cost . ")" . $value->id . ":" . $value->instance_id; } echo "<br>"; } The key here is getting methods with already initialized instance_id. This code also can be found on Stackoverflow. ...
Read More

How To Sort Products in Woocommerce Catalog both by Stock Status and Popularity

The post_clauses filter in WooCommerce allows you to modify the SQL clauses that are used to retrieve products from the database. You can use this filter to sort products by popularity and stock status in the WooCommerce catalog by adding the following code to your theme's functions.php file or a custom plugin: <?php /** * Order product collections by stock status, instock products first. */ class iWC_Orderby_Stock_Status { public function __construct() { // Check if WooCommerce is active if (in_array('woocommerce/woocommerce.php', apply_filters('active_plugins', get_option('active_plugins')))) { add_filter('posts_clauses', array($this, 'order_by_stock_status'), 2000); } } public function order_by_stock_status($posts_clauses) { global $wpdb; // only change query on WooCommerce loops ...
Read More

How to resolve “PHP Notice: Undefined index: width in class-wc-regenerate-images.php on line 276”

After recent Woocommerce update on some website the PHP notice is appeared, like: PHP Notice: Undefined index: width in plugins/woocommerce/includes/class-wc-regenerate-images.php on line 276 PHP Notice: Undefined index: height in plugins/woocommerce/includes/class-wc-regenerate-images.php on line 277 This problem is caused by SVG-files mostly. So when in Woocommerce fucntion such mime type is checked some SVG images can has such structure, which call the php notice: Array ( [filesize] => 4427 ) How to fix Add this to you functions.php or other included to theme file: /** * Disable Woocommerce resize for SVG images. */ add_filter( 'wp_get_attachment_image_src', 'fix_wp_get_attachment_image_svg', 10, 4 ); function fix_wp_get_attachment_image_svg($image, $attachment_id, $size, $icon) { // if Woocommerce enabled if (in_array('woocommerce/woocommerce.php', apply_filters('active_plugins', get_option('active_plugins')))) { $attachment = get_post($attachment_id); $mime_type = $attachment->post_mime_type; // The attachment mime_type if($mime_type == 'image/svg+xml') { return false; ...
Read More

How to make email notifications of new product for Woocommerce

Sometimes if you're selling some products which are highly demand by customers such feature like notifications to email regarding new items listed for sale in your Woocommerce store can be very useful. This an easy way to make these notifications available for subscribers: Go to https://feedburner.google.com and add the RSS feed for your products (you should have Google account registered). The correct feed for your domain will be like: https://yourdomain.com/feed/?post_type=product Also you can previously check feed for your woocommerce shop online here:https://validator.w3.org/feed/ On the next screen you can set up the Title and feed name. It's up to your opinion. Now your feed is ready. Let's add subscribe form to get possibility for customers sign up to receive your Woocommerce store new listings updates. Go to the next screen, then one else and press menu point "Publicize". Press "activate" at the bottom of screen and then you'll be able to grab or HTML-code of subscription form, or HTML-code of link to sign up for emails. The code of form...
Read More