Skip to content

Instantly share code, notes, and snippets.

@renjith-ph
renjith-ph / functions.php
Last active December 10, 2019 14:37
Snippet to hide the woocommerce shipping methods based on user role
/**
* Title : Snippet to hide the woocommerce shipping methods based on user role .
* Created at : 08 March 2019
* Updated at : 08 March 2019
* Pluginhive Plugins : https://www.pluginhive.com/
* Gist Link : https://gist.github.com/renjith-ph/e72e111a31ffb8b2e52742dd5c374d37/
*/
add_filter( 'woocommerce_package_rates', function( $shipping_rates ) {
// Provide user role and shipping methods values pair
@renjith-ph
renjith-ph / custom_code.php
Created March 5, 2019 17:07
Template to attach shipment tracking number in WooCommerce Email Customizer with Drag and Drop Email Builder. WooCommerce Shipment Tracking Pro - https://www.pluginhive.com/product/woocommerce-shipment-tracking-pro/
<?php
/**
* Custom code shortcode
*
* This template can be overridden by copying it to yourtheme/woocommerce_email_cuztomizer_with_drag_and_drop_builder/woo_mail/custom_code.php.
* @var $order WooCommerce order
* @var $email_id WooCommerce email id (new_order, cancelled_order)
* @var $sent_to_admin WooCommerce email send to admin
* @var $plain_text WooCommerce email format
* @var $email WooCommerce email object
@renjith-ph
renjith-ph / functions.php
Created February 21, 2019 14:17
Snippet to replace the base cost of booking cost rule while calculating booking cost
/* Snippet to replace the base cost of booking cost rule while calculating booking cost
Created at : 21 Feb 2019 PluginHive Plugins : https://www.pluginhive.com/plugins/
*/
add_filter('ph_booking_rule_for_setting_base_cost_and_unit_cost','ph_booking_update_rule_for_setting_base_cost_and_unit_cost',10,3);
function ph_booking_update_rule_for_setting_base_cost_and_unit_cost($rule,$from_date,$to_date)
{
$updation_condition=array('from'=>'Friday','to'=>'Monday','base_cost'=>'79','unit_cost'=>''); // add base cost and unit cost, and this will replace the base cost of 4days rule while calculating booking cost
$from_date=date('l',$from_date);
$to_date=date('l',$to_date);
if($updation_condition['from']==$from_date && $updation_condition['to']==$to_date)
@renjith-ph
renjith-ph / functions.php
Last active June 28, 2023 09:38
Snippet to ignore the Booking period while displaying booking to date.
/* Snippet to ignore the Booking period while displaying booking to date.
Created at : 30 Jan 2019 PluginHive Plugins : https://www.pluginhive.com/plugins/
*/
add_filter( 'phive_booking_booked_price_details', 'remove_booking_period_time_from_booked_price_details',10,3 );
function remove_booking_period_time_from_booked_price_details( $booking_details,$product_id,$post_data ) {
$ignore_interval='true'; //set true to ignore booking period
$wp_date_time_format = get_option( 'date_format' ).' '.get_option( 'time_format' );
$interval_period = get_post_meta( $product_id, "_phive_book_interval_period", 1 );
$interval = get_post_meta( $product_id, "_phive_book_interval", 1 );
$interval_type = get_post_meta( $product_id, "_phive_book_interval_type", 1 );
@renjith-ph
renjith-ph / functions.php
Last active January 21, 2019 05:52
Snippet to change estimate delivery based on variable product (backorder and instock).
/**
* Snippet to change estimate delivery based on variable product (backorder and instock).
* Created at : 19 Jan 2019
* PluginHive Plugins : https://www.pluginhive.com/plugins/
*/
add_filter( 'woocommerce_get_availability', 'woocommerce_get_availability',12,2 );
function woocommerce_get_availability( $stock_arr ,$item) {
if( empty($item) ){
global $product;
@renjith-ph
renjith-ph / functions.php
Last active January 16, 2019 06:45
Snippet to add custom message on top of checkout page if shipping methods are available.
/* Snippet to add custom message on top of checkout page if shipping methods are available.
Created at : 16 Jan 2019 PluginHive Plugins : https://www.pluginhive.com/plugins/
gist link: https://gist.github.com/renjith-ph/8f27c63d5a079d578ad3c7db00ece94b
*/
add_action( 'woocommerce_before_checkout_form', 'ph_add_custom_message_on_top_of_checkout_page_if_shipping_method_available', 10 );
function ph_add_custom_message_on_top_of_checkout_page_if_shipping_method_available()
{
$i=0;
$message="Do you qualify for a shipping discount? Give us a call at 541-419-6054"; // this message will display on top of checkout page
@renjith-ph
renjith-ph / functions.php
Last active January 16, 2019 05:37
Snippet to redirect to checkout page after adding product to cart.
/* Snippet to redirect to checkout page after adding product to cart.
Created at : 16 Jan 2019 PluginHive Plugins : https://www.pluginhive.com/plugins/
https://gist.github.com/renjith-ph/0defbaf8a48d49ec61fc50add6b1b051
*/
function ph_change_redirect_url_after_adding_product_to_cart( $url ) {
$url = wc_get_checkout_url();
return $url;
}
add_filter( 'woocommerce_add_to_cart_redirect', 'ph_change_redirect_url_after_adding_product_to_cart' );
@renjith-ph
renjith-ph / functions.php
Created January 14, 2019 08:05
Snippet to add extra product description for UPS international shipping.
/* Snippet to add extra product description for UPS international shipping.
Created at : 14 Jan 2019 PluginHive Plugins : https://www.pluginhive.com/plugins/
*/
add_filter( 'wf_ups_shipment_confirm_request_product_details', 'ph_ups_add_extra_product_description_for_commercial_invoice', 10, 2 );
if( ! function_exists('ph_ups_add_extra_product_description_for_commercial_invoice') ) {
function ph_ups_add_extra_product_description_for_commercial_invoice( $product_details, $product_data ) {
$description=".Add your description here"; // add extra description in the commercial invoice.
$product_details['Description']=$product_details['Description'].$description;
@renjith-ph
renjith-ph / functions.php
Created January 14, 2019 07:52
Snippet to change product price to custom declared value and change unit of measurement for international shipping.
/* Snippet to change product price to custom declared value and change unit of measurement for international shipping.
Created at : 26 Nov 2018 PluginHive Plugins : https://www.pluginhive.com/plugins/
updated on : 14 Jan 2019
*/
add_filter( 'wf_ups_shipment_confirm_request_product_details', 'wf_ups_shipment_confirm_request_product_details', 10, 2 );
if( ! function_exists('wf_ups_shipment_confirm_request_product_details') ) {
function wf_ups_shipment_confirm_request_product_details( $product_details, $product_data ) {
if(!empty($product_data))
@renjith-ph
renjith-ph / functions.php
Created January 9, 2019 14:07
Add warning on top of estimated delivery date
add_filter( 'xa_estimated_delivery_cart_checkout_page_html_formatted_date', 'ph_estimated_delivery_add_warning_on_above_estimated_delivery',11,2 );
function ph_estimated_delivery_add_warning_on_above_estimated_delivery( $text, $test ) {
$message='<tr class="shipping"><th>Your cart having back-order products</th></tr>'; // add your message here
$text=$message.$text;
return $text;
}