WooCommerce

A shared tag with AI prompts and code snippets

From workspace: CodeWP

Team: Main

Total snippets: 14

CodeWP

WooCommerce

14 snippets

WooCommerce Auto-Cart Clear

This file contains a WordPress class that hooks into WooCommerce to clear user shopping carts after 5 minutes of inactivity. It uses user meta and cookies to track the last activity time of logged-in users and guests, respectively.

<?php if ( ! class_exists( 'WC_Session' ) ) { return; } class WC_Clear_Cart_After_Time { protected $cart_cleared; public function __construct() { $this->cart_cleared = false; add_action( 'init', array( $this,...

WooCommerce Selfie Upload on Registration

This code is a WordPress plugin called "WooCommerce Selfie Upload" that extends the WooCommerce registration form by adding a mandatory selfie upload field. The plugin modifies the registration form by adding the necessary enctype attribute to allow file uploads. It also adds a file input field to the form, specifies its accepted file types (JPG and PNG), and makes it required. The plugin includes validation to check if a valid selfie image was uploaded and displays an error message if not. After successful registration, the plugin saves the uploaded selfie file as an attachment in the media library and associates it with the user's profile by storing the attachment ID in user meta. Lastly, it displays the uploaded selfie image in the admin user profile.

<?php /* Plugin Name: WooCommerce Selfie Upload Plugin URI: https://codewp.ai Description: Extend the WooCommerce registration form with a mandatory selfie upload field. Version: 1.0 Author: CodeWP Assistant Author URI: https://codewp.ai Text...

WooCommerce Admin-Only Coupon Code

This file contains code that enhances WooCommerce by allowing the creation of coupons that are exclusively for admin use. It includes functions to add a checkbox on the coupon edit page, save the admin-only setting, and validate coupon usage based on the admin-only status.

<?php /** * Add a checkbox to the coupon data panel to mark the coupon as "Admin Only". */ add_action('woocommerce_coupon_options', 'cwpai_add_coupon_option_field', 10, 2); function cwpai_add_coupon_option_field($coupon_id, $coupon) { ...

WooCommerce Custom Email Notifications

This custom plugin for WooCommerce sends separate order notifications to specific email addresses based on the categories of the products in the order. It hooks into the WooCommerce order status completed action and iterates through the order items, matching product categories with predefined email addresses, and dispatching notifications accordingly.

<?php /** * Plugin Name: WooCommerce Custom Email Notifications * Plugin URI: https://codewp.ai * Description: This plugin sends order notifications for different categories to separate email addresses. * Version: 1.0.0 * Author: CodeWP...

WooCommerce Local Free Shipping Class

This file contains a PHP class that integrates with WooCommerce to provide free shipping for products that match the customer's local area zip code. It adds a new field to the product's shipping options for entering a local zip code and applies free shipping for matching products during cart calculations.

<?php if (!class_exists("Cwpai_Local_Free_Shipping")) { class Cwpai_Local_Free_Shipping { public function __construct() { add_action("woocommerce_product_options_shipping", [$this,...

WooCommerce Delivery Date Plugin

This plugin introduces a mandatory delivery date field at the WooCommerce checkout process. It saves the date selected by the customer and displays it on the admin order page, ensuring the delivery date is clearly communicated to store management.

<?php /* Plugin Name: WooCommerce Delivery Date Plugin URI: https://codewp.ai Description: This plugin adds a delivery date field to WooCommerce checkout process and shows it on the admin order page. Author: CodeWP Assistant Author URI:...

WooCommerce Coupons CSV Exporter

This file contains the code for a WordPress plugin that allows users to export all WooCommerce coupons to a CSV file. The CSV file is then saved to the WordPress media library for easy access. The plugin adds an 'Export Coupons' button to the WooCommerce coupons page in the admin area, providing a seamless export experience.

<?php /** * Plugin Name: WooCommerce Coupons Exporter * Plugin URI: https://codewp.ai * Author: CodeWP Assistant * Author URI: https://codewp.ai * Description: This plugin exports all WooCommerce coupons as a CSV and saves the file to the...

WooCommerce Cart Minimum Plugin

This WordPress plugin adds a minimum cart total requirement to WooCommerce stores. It hooks into WooCommerce settings to allow site administrators to define a minimum order total and displays a notice to customers if their cart total does not meet this requirement, preventing them from proceeding to checkout until the minimum is met.

<?php /** * Plugin Name: WooCommerce Cart Minimum * Plugin URI: https://codewp.ai * Author: CodeWP Assistant * Author URI: https://codewp.ai * Description: This plugin adds a mandatory minimum amount for WooCommerce cart and prevents...

WooCommerce Dry Ice Shipping Fee Function

This file contains a function for WooCommerce that calculates additional fees for cart items belonging to a specific shipping class, particularly for items requiring dry ice shipping. It adds a base fee for a defined initial quantity and calculates additional fees for each step quantity beyond that.

<?php add_action( 'woocommerce_cart_calculate_fees', 'cwpai_shipping_class_and_item_quantity_fee', 10, 1 ); function cwpai_shipping_class_and_item_quantity_fee( $cart ) { ## -------------- YOUR SETTINGS BELOW ------------ ## ...

Custom WooCommerce Download Limit Alert

This customization alters the default WooCommerce notification when a user reaches the download limit for a product. It enables a more tailored and potentially user-friendly message, improving the overall shopping experience.

<?php /** * Change the default WooCommerce download limit reached message */ function custom_wc_override_default_strings( $translated_text, $text, $domain ) { if ( $domain === 'woocommerce' && $text === 'Sorry, you have reached your...

WooCommerce Product Alternatives Plugin

This plugin allows WooCommerce store owners to display alternative product suggestions in place of the default "Out of Stock" message. When a customer views a product that is not available, they are presented with a list of alternative in-stock products to encourage continued shopping and potentially prevent lost sales.

<?php /** * Plugin Name: WooCommerce Product Alternatives * Description: A plugin to add the ability for customers to see alternative products if the main product is out of stock, replacing the "Out of Stock" message with a custom list. *...

Affiliate Top Bar for WooCommerce

This WordPress plugin introduces a customized top bar that appears for users referred by an affiliate link, enhancing their shopping experience. It checks for active AffiliateWP and WooCommerce plugins before displaying the affiliate's name on the top bar.

<?php /** * Plugin Name: CodeWP Affiliate Top Bar * Plugin URI: https://codewp.ai * Description: Displays a custom top bar for users referred by an affiliate. * Version: 1.0 * Author: CodeWP Assistant * Author URI: https://codewp.ai */ //...

WooCommerce Custom Fields Display

This WordPress plugin extends WooCommerce by adding a custom field column to the orders list on the My Account page and displaying the custom field value on the Order Details page. It requires WooCommerce to be installed and uses hooks to integrate the custom field into the order management interface.

<?php /** * Plugin Name: CodeWP WooCommerce Order Custom Fields Display (OOP Version) * Plugin URI: https://codewp.ai * Description: Display custom fields from orders on the WooCommerce My Account page and Order Details page, reworked as an...

WooCommerce Custom Delivery Checkout Fields

This file enhances the WooCommerce checkout process by adding custom fields for customers to select a preferred delivery date and to provide additional delivery instructions. It includes validation to ensure the date is in the future and sanitizes input data for security.

<?php /** * Enhances custom checkout fields for package delivery in WooCommerce. * This version registers fields for selecting a preferred delivery date and providing additional delivery instructions, such as gate codes or drop-off...

CodeWP - WooCommerce - AI Prompts & Code Snippets | Snippets AI