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 / profile_tab.php
Last active December 20, 2021 09:19
Booking: Override for profile tab
<?php
/**
* Override path: [TEMPLATE_FOLDER]/html/plugins/j2store/app_booking/profile_tab.php
* */
defined('_JEXEC') or die('Restricted access');
?>
<li>
<a href="#appbooking-tab" class="nav-link" id="appbooking-tab-id" data-bs-toggle="tab" data-bs-target="#appbooking-tab" role="tab" aria-controls="address-tab" data-toggle="tab" style="display: block;" aria-selected="false"><i class="fa fa-calendar"></i>
<?php echo JText::_('J2STORE_APP_BOOKING_PROFILE_TAB'); ?>
</a>
@AshlinRejo
AshlinRejo / Discount rules v2: Get list of used coupon names in discount rules
Last active November 26, 2021 13:29
Discount rules v2: Get list of used coupon names in discount rules
if(class_exists('\Wdr\App\Router')){
$manage_discount = \Wdr\App\Router::$manage_discount;
$calculator = $manage_discount::$calculator;
$used_coupons = $calculator::getUsedCoupons();
//$used_coupons -> here you get used coupon names in discount rules as an array
}
@AshlinRejo
AshlinRejo / Discount rules v2: Woocommerce Custom Product Addons by Acowebs - Apply discount for only base price not for addons
Created November 25, 2021 12:40
Discount rules v2: Woocommerce Custom Product Addons by Acowebs - Apply discount for only base price not for addons
global $awdr_addon_commpatible_products;
add_filter('advanced_woo_discount_rules_product_price_on_before_calculate_discount', function($product_price, $product, $quantity, $cart_item){
global $awdr_addon_commpatible_products;
if(!empty($cart_item)){
if(isset($cart_item) && isset($cart_item['wcpa_data']) && !empty($cart_item['wcpa_data'])){
if (method_exists($product, 'get_id') && function_exists('wc_get_product')) {
$product_id = $product->get_id();
if(isset($awdr_addon_commpatible_products[$product_id])){
$product = $awdr_addon_commpatible_products[$product_id];
} else {
@AshlinRejo
AshlinRejo / Discount rules v2: Display Cross sell on after cart
Created November 25, 2021 09:32
Discount rules v2: Display Cross sell on after cart
add_action('advanced_woo_discount_rules_before_loaded', function (){
if(class_exists('\WDRPro\App\Rules\BuyXGetY')){
remove_all_filters( 'woocommerce_cart_collaterals', 9 );
add_action( 'woocommerce_after_cart', array('\WDRPro\App\Rules\BuyXGetY', 'loadCrossSellDisplay'), 9 );
}
});
@AshlinRejo
AshlinRejo / Add to cart button with discount price for variable product
Created November 23, 2021 06:39
Add to cart button with discount price for variable product
add_filter( 'woocommerce_product_single_add_to_cart_text', 'custom_add_to_cart_price', 20, 2 ); // Single product pages
function custom_add_to_cart_price( $button_text, $product ) {
/**
* Get the discount details of given product with custom price
* @param $price float/integer
* @param $product object (Product object Example: wc_get_product($product_id))
* @param $quantity int
* @param $customPrice float/integer (0 for calculate discount from product price)
* @param $returnDetails string (Default value 'discounted_price' accepted values = 'discounted_price','all')
* @param $manualRequest boolean (Default value false: pass this as true for get discount even if there is no item in cart)
@AshlinRejo
AshlinRejo / Discount rule v2: Get matched rule range or table info based on product in product page
Created November 22, 2021 08:43
Discount rule v2: Get matched rule range/table info based on product in product page
if(class_exists('\Wdr\App\Router')) {
global $product;
$discountManager = \Wdr\App\Router::$manage_discount;
$discountCalculator = $discountManager::$calculator;
$is_variant = false;
$bulk_discounts_ranges = $discountCalculator->getDefaultLayoutMessagesByRules($product, $is_variant);
//$bulk_discounts_ranges Here you get rule range info
}
@AshlinRejo
AshlinRejo / Discount rules v2: Trigger quantity update on changing variant, update the varint price in main price html
Last active November 22, 2021 07:25
Discount rules v2: Trigger quantity update on changing variant, update the varint price in main price html
add_filter('woocommerce_after_add_to_cart_form', function (){
?>
<script>
jQuery( document ).ready( function() {
jQuery( ".single_variation_wrap" ).on( "show_variation", function ( event, variation, purchasable ) {
jQuery(this).closest('form').find('input[name="quantity"]').trigger('change');
});
jQuery('input[name="quantity"]').trigger('change');
});
</script>
@AshlinRejo
AshlinRejo / Discount rules v2: Display sale badge percentage if they have default sale price instead of sale override
Created November 18, 2021 12:58
Discount rules v2: Display sale badge percentage if they have default sale price instead of sale override
add_filter('advanced_woo_discount_rules_on_sale_badge_html', function ($html, $post, $_product){
if (strpos($html, 'Sale!') !== false) {
$percentage = 0;
$reg_p = floatval( $_product->get_regular_price() );
$sale_p = floatval( $_product->get_sale_price() );
if ( $reg_p && $sale_p) {
$percentage = - round( ( ( $reg_p - $sale_p ) / $reg_p ) * 100 );
} elseif ( 'variable' == $_product->get_type() && $_product->get_variation_regular_price() && $_product->get_variation_sale_price() ) {
$percentage = - round( ( ( $_product->get_variation_regular_price() - $_product->get_variation_sale_price() ) / $_product->get_variation_regular_price() ) * 100 );
}
@AshlinRejo
AshlinRejo / discount_table.php
Created November 16, 2021 06:29
Discount rules v2: Table customization all ranges in a row
<?php
/**
* Discount table
*
* This template can be overridden by copying it to yourtheme/advanced_woo_discount_rules/discount_table.php.
*
* HOWEVER, on occasion Discount rules will need to update template files and you
* (the theme developer) will need to copy the new files to your theme to
* maintain compatibility. We try to do this as little as possible, but it does
* happen. When this occurs the version of the template file will be bumped and
@AshlinRejo
AshlinRejo / Discount rule v2: Check purchase history based on both email and user id
Created November 15, 2021 08:10
Discount rule v2: Check purchase history based on both email and user id
add_filter('advanced_woo_discount_rules_check_purchase_history_based_on_email_and_user_id', '__return_true');