Skip to content

Instantly share code, notes, and snippets.

View kartikparmar's full-sized avatar

Kartik Parmar kartikparmar

  • Mumbai
View GitHub Profile
@kartikparmar
kartikparmar / functions.php
Created January 21, 2025 03:59
Sorting attributes in custom order
<?php
/**
* Modify sorting pattern for size attribute.
*/
function swpco_weekdays() {
/* Following data is assumption that you want the size order in mentioned order. */
return array(
's' => 'aaaaaaaaa',
'm' => 'aaaaaaaab',
@kartikparmar
kartikparmar / functions.php
Created December 5, 2024 13:48
Display Custom Price and Tax information
<?php
// Add a custom field to the General tab on the product edit page
add_action( 'woocommerce_product_options_general_product_data', 'add_custom_price_option' );
function add_custom_price_option() {
woocommerce_wp_text_input(
array(
'id' => '_custom_price_title',
'label' => __( 'Display Price', 'your-textdomain' ),
'description' => __( 'Enter a custom price title to display on the product page.', 'your-textdomain' ),
@kartikparmar
kartikparmar / functions.php
Created December 5, 2024 11:20
show booking price with tax information
<?php
function bkap_show_booking_price_with_tax( $wp_send_json, $product_id ) {
if ( 'yes' !== get_option( 'woocommerce_calc_taxes' ) ) {
return $wp_send_json;
}
$product_obj = wc_get_product( $product_id );
$total_price = $wp_send_json['total_price_calculated'];
@kartikparmar
kartikparmar / functions.php
Created November 20, 2024 12:44
adding bcc to reminder emails
<?php
function bkap_booking_reminder_add_cc_bcc( $headers, $email_id, $order ) {
if ( 'bkap_booking_reminder' == $email_id ) {
$admin_email = get_option( 'admin_email' );
$headers .= "Bcc: Admin <" . $admin_email . ">\r\n";
}
return $headers;
}
add_filter( 'woocommerce_email_headers', 'bkap_booking_reminder_add_cc_bcc', 9999, 3 );
@kartikparmar
kartikparmar / functions.php
Created November 8, 2024 13:35
Date info in session from bkap date selection form
<?php
function bkap_date_from_session_cookie( $date ) {
if ( $date ) {
if ( str_contains( $date, '/' ) ) {
$d = DateTime::createFromFormat( 'j/n/y', $date );
$date = $d->format( 'Y-m-d' );
}
}
return $date;
@kartikparmar
kartikparmar / functions.php
Last active November 6, 2024 17:50
custom code to list the date and select it in datepicker
<?php
add_action('woocommerce_before_add_to_cart_button', 'add_custom_date_picker', 10000 );
function add_custom_date_picker() {
?>
<style>
.date-list {
list-style-type: none;
padding: 0;
}
@kartikparmar
kartikparmar / function.php
Created November 5, 2024 15:48
Setting default booking status to pending confirmation
<?php
/**
* Change default booking status to confirmed when order is placed.
*
* @param string $status Status of Booking.
*/
function bkap_booking_status_on_create_order( $status ) {
return 'pending-confirmation';
}
@kartikparmar
kartikparmar / functions.php
Created November 4, 2024 09:48
customize the booking price based on the custom fields
<?php
function custom_price_calc( $price_data, $product_id ) {
/*
You can change the following data
total_price_calculated - Total Booking Price
bkap_price_charged - Booking price being charged to customer [This could be vary if deposits addon is being used]
bkap_price : Text being displayed in the Price section - https://prnt.sc/ku_AQFhjUY36
To understand bit more how the data being prepared and passed based on the cutomer selection then you can check for bkap_special_booking_show_multiple_updated_price function
*/
@kartikparmar
kartikparmar / functions.php
Created October 30, 2024 13:12
Exclude the disabled weekdays and season with 100% discount from number of selected days
<?php
function bkap_selected_number_of_nights( $number, $checkin_date, $checkout_date, $product_id, $booking_settings ) {
$dates = bkap_common::bkap_get_betweendays( $checkin_date, $checkout_date, 'Y-m-d' );
foreach ( $dates as $date ) {
$day = date( 'w', strtotime( $date ) );
$weekday_name = 'booking_weekday_' . $day;
if ( '' === $booking_settings['booking_recurring'][$weekday_name] ) {
@kartikparmar
kartikparmar / datepicker.html
Created October 24, 2024 08:28
datepicker.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Date Picker Example</title>
<link rel="stylesheet" href="https://code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
<style>
.date-list {
list-style-type: none;