Skip to content

Instantly share code, notes, and snippets.

View AshlinRejo's full-sized avatar
🏠
Working from home

Ashlin AshlinRejo

🏠
Working from home
View GitHub Profile
@AshlinRejo
AshlinRejo / Pre-paid Subscription: To support with non recurring plan (from v1.2.1)
Created December 18, 2018 10:49
Pre-paid Subscription: To support with non recurring plan (from v1.2.1)
if(!function_exists('woocommerce_subscription_upfront_allow_for_non_recurring_plan_method')){
function woocommerce_subscription_upfront_allow_for_non_recurring_plan_method($allow){
return true;
}
}
add_filter('woocommerce_subscription_upfront_allow_for_non_recurring_plan', 'woocommerce_subscription_upfront_allow_for_non_recurring_plan_method', 10);
@AshlinRejo
AshlinRejo / Woo discount rules: Add content before strikeout
Created January 24, 2019 06:53
Woo discount rules: Add content before strikeout
if(!function_exists('woo_discount_rules_price_strikeout_after_discount_price_method')){
function woo_discount_rules_price_strikeout_after_discount_price_method($item_price, $product){
$item_price = 'From: '.$item_price;
$item_price = str_replace('</del> <ins>', '</del> From:<ins>', $item_price);
return $item_price;
}
}
add_filter('woo_discount_rules_price_strikeout_after_discount_price', 'woo_discount_rules_price_strikeout_after_discount_price_method', 10, 2);
@AshlinRejo
AshlinRejo / Woo discount rules: Refresh the cart after adding free product through cart rules
Created January 25, 2019 12:51
Woo discount rules: Refresh the cart after adding free product through cart rules
add_action('woo_discount_rules_cart_rules_after_adding_free_product_to_cart', function (){
add_action('woocommerce_before_cart', function (){
?>
<script type="text/javascript">
jQuery( document ).ready(function() {
jQuery("[name='update_cart']").removeAttr('disabled');
jQuery("[name='update_cart']").trigger("click");
});
</script>
<?php
@AshlinRejo
AshlinRejo / Woo discount rules: Add content before strikeout only for variable product
Created January 28, 2019 11:25
Woo discount rules: Add content before strikeout only for variable product
if(!function_exists('woo_discount_rules_price_strikeout_after_discount_price_method')){
function woo_discount_rules_price_strikeout_after_discount_price_method($item_price, $product){
if($product->is_type( 'variable' )) {
$item_price = 'From: '.$item_price;
$item_price = str_replace('</del> <ins>', '</del> From:<ins>', $item_price);
}
return $item_price;
}
}
@AshlinRejo
AshlinRejo / Woo Discount Rules: For displaying discounted price in discount table with least and highest price for variable product
Created January 30, 2019 06:07
Woo Discount Rules: For displaying discounted price in discount table with least and highest price for variable product
<?php
/**
* List matched Rules in Table format
*
* This template can be overridden by copying it to yourtheme/plugin-folder-name/discount-table.php
*/
if (!defined('ABSPATH')) exit; // Exit if accessed directly
if (!isset($table_data) || empty($table_data)) return false;
$base_config = (is_string($data)) ? json_decode($data, true) : (is_array($data) ? $data : array());
@AshlinRejo
AshlinRejo / Email customizer: Template override for displaying link on order item name
Created January 30, 2019 07:09
Email customizer: Template override for displaying link on order item name
@AshlinRejo
AshlinRejo / Woo discount rules: Refresh the cart after updating cart item
Created February 5, 2019 09:51
Woo discount rules: Refresh the cart after updating cart item
add_action('woocommerce_before_cart', function (){
?>
<script type="text/javascript">
jQuery( document.body ).on( 'updated_cart_totals', function() {
location.reload();
});
</script>
<?php
});
@AshlinRejo
AshlinRejo / Woo discount rules: Refresh the cart after adding coupon
Created February 5, 2019 10:39
Woo discount rules: Refresh the cart after adding coupon
add_action('woocommerce_applied_coupon', function (){
add_action('woocommerce_before_cart', function (){
?>
<script type="text/javascript">
jQuery( document ).ready(function() {
jQuery("[name='update_cart']").removeAttr('disabled');
jQuery("[name='update_cart']").trigger("click");
});
</script>
<?php
@AshlinRejo
AshlinRejo / Woo Discount Rules: Compatible for Multi Currency for WooCommerce by villaTheme
Last active October 11, 2019 11:20
Woo Discount Rules: Compatible for Multi Currency for WooCommerce by villaTheme
if(!function_exists('woo_discount_rules_compatible_with_villa_theme_currency_switcher')){
function woo_discount_rules_compatible_with_villa_theme_currency_switcher($price, $is_cart = false, $discount_type = 'percentage_discount'){
$process_conversion = true;
if($is_cart === true){
if($discount_type !== 'percentage_discount'){
$process_conversion = false;
}
}
if($process_conversion){
$class_exists = false;
@AshlinRejo
AshlinRejo / Woo Discount Rules: Composite product compatible
Created February 7, 2019 06:53
Woo Discount Rules: Composite product compatible
if(!function_exists('woo_discount_rules_exclude_cart_item_from_discount_method')){
function woo_discount_rules_exclude_cart_item_from_discount_method($status, $cart_item){
if(isset($cart_item['composite_item']) && !empty($cart_item['composite_item'])){
$status = true;
}
return $status;
}
}
add_filter('woo_discount_rules_exclude_cart_item_from_discount', 'woo_discount_rules_exclude_cart_item_from_discount_method', 10, 2);