Skip to content

Instantly share code, notes, and snippets.

@bhavik-kiri
bhavik-kiri / remove_quantity.php
Last active November 25, 2022 13:52
It will remove the quantity from the cart details.
<?php
/*
* It will remove the selected quantity count from checkout page table.
*/
function remove_quantity_text( $cart_item, $cart_item_key ) {
$product_quantity= '';
return $product_quantity;
}
add_filter ('woocommerce_checkout_cart_item_quantity', 'remove_quantity_text', 10, 2 );
<?php
/*
Plugin Name: Add Gift Card as Custom Product Type
Description: A simple demo plugin on how to add Gift Card as your custom product type
Author: Bhavik Kiri
Version: 1.0
*/
add_action( 'plugins_loaded', 'wcpt_register_gift_card_type' );
<?php
/*
Plugin Name: Add Item Meta & Order Meta for your WooComerce order
Description: A simple demo plugin on how to add add cart item meta & order item meta for your WooComerce order.
Author: Bhavik Kiri
Version: 1.0
*/
add_action( 'woocommerce_before_add_to_cart_button', 'add_fields_before_add_to_cart' );
<?php
add_action( 'woocommerce_after_checkout_billing_form', 'display_extra_fields_after_billing_address' , 10, 1 );
function display_extra_fields_after_billing_address () {
_e( "Delivery Date: ", "add_extra_fields");
?>
<br>
<input type="text" name="add_delivery_date" class="add_delivery_date" placeholder="Delivery Date">
}
<?php
/*
Plugin Name: Add Fields on WooCommerce checkout page.
Description: A simple demo plugin on how to add add extra fields on WooCommerce checkout page.
Author: Bhavik Kiri
Version: 1.0
*/
add_action( 'woocommerce_after_checkout_billing_form', 'display_extra_fields_after_billing_address' , 10, 1 );
<?php
add_filter( 'woocommerce_order_details_after_order_table', 'add_delivery_date_to_order_received_page', 10 , 1 );
function add_delivery_date_to_order_received_page ( $order ) {
if( version_compare( get_option( 'woocommerce_version' ), '3.0.0', ">=" ) ) {
$order_id = $order->get_id();
} else {
$order_id = $order->id;
}
<?php
add_filter( 'woocommerce_email_order_meta_fields', 'add_delivery_date_to_emails' , 10, 3 );
function add_delivery_date_to_emails ( $fields, $sent_to_admin, $order ) {
if( version_compare( get_option( 'woocommerce_version' ), '3.0.0', ">=" ) ) {
$order_id = $order->get_id();
} else {
$order_id = $order->id;
}
<?php
add_action( 'woocommerce_checkout_update_order_meta', 'add_order_delivery_date_to_order' , 10, 1);
function add_order_delivery_date_to_order ( $order_id ) {
if ( isset( $_POST ['add_delivery_date'] ) && '' != $_POST ['add_delivery_date'] ) {
add_post_meta( $order_id, '_delivery_date', sanitize_text_field( $_POST ['add_delivery_date'] ) );
}
}
<?php
add_action( 'woocommerce_after_checkout_billing_form', 'display_extra_fields_after_billing_address' , 10, 1 );
function display_extra_fields_after_billing_address () {
_e( "Delivery Date: ", "add_extra_fields");
?>
<br>
<input type="text" name="add_delivery_date" class="add_delivery_date" placeholder="Delivery Date">
<?php
/*
* It will add Delete button, Quanitity field on the checkout page Your Order Table.
*/
function add_quantity( $product_title, $cart_item, $cart_item_key ) {
/* Checkout page check */
if ( is_checkout() ) {
/* Get Cart of the user */
$cart = WC()->cart->get_cart();
foreach ( $cart as $cart_key => $cart_value ){