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 / Discount rule v2: Remove thirdparty coupon when free shipping rule is applied in cart
Created August 29, 2022 08:00
Discount rule v2: Remove thirdparty coupon when free shipping rule is applied in cart
add_filter('advanced_woo_discount_rules_apply_free_shipping', function ($has_free_shipping){
if(class_exists('\Wdr\App\Router')){
$manage_discount = \Wdr\App\Router::$manage_discount;
add_action('woocommerce_after_calculate_totals', array($manage_discount, 'removeThirdPartyCoupon'), 20);
}
return $has_free_shipping;
}, 10);
@AshlinRejo
AshlinRejo / Discount rules v2: WooCommerce Product Bundles compatible with auto add free product
Created August 2, 2022 11:36
Discount rules v2: WooCommerce Product Bundles compatible with auto add free product
add_action('advanced_woo_discount_rules_after_apply_discount', function (){
$cart_items = WC()->cart->get_cart();
if(!empty($cart_items)){
foreach ($cart_items as $key => $item){
if(isset($item['bundled_by'])){
if(isset($cart_items[$item['bundled_by']])){
$itemParent = $cart_items[$item['bundled_by']];
if(isset($itemParent['data']->is_awdr_free_product) && $itemParent['data']->is_awdr_free_product){
$item['data']->set_price(0);
}
@AshlinRejo
AshlinRejo / Discount rules v2: Compatible with WooCommerce Shipping Per Product v2 to load free shipping with per product shipping
Created June 7, 2022 13:37
Discount rules v2: Compatible with WooCommerce Shipping Per Product v2 to load free shipping with per product shipping
add_filter('woocommerce_per_product_shipping_ship_via', function ($ship_via){
$ship_via[] = 'wdr_free_shipping';
return $ship_via;
});
@AshlinRejo
AshlinRejo / events_document.php
Last active May 19, 2022 12:24
Discount rule v2: events document
<?php
/**
* Get discount of a product
* @param $product integer|object (Product object Example: wc_get_product($product_id))
* @param $quantity int
* @return boolean|float|int - is product has no discounts it returns false
*/
$discount = apply_filters('advanced_woo_discount_rules_get_discount_price', $product, $quantity);
if($discount !== false){
echo $discount // HERE YOU GET DISCOUNT PRICE
@AshlinRejo
AshlinRejo / snippet.php
Created February 18, 2022 12:49
Snippet for display discount bar in different position
function custom_sale_hook($hook) {
return 'my_custom_hook';
}
add_action('plugins_loaded', function () {
add_filter('advanced_woo_discount_rules_custom_position_to_show_discount_bar', 'custom_sale_hook');
}, 0);
@AshlinRejo
AshlinRejo / Discount Rules v2: Disable the discount table for specific rules
Created February 17, 2022 09:56
Discount Rules v2: Disable the discount table for specific rules
add_filter( 'advanced_woo_discount_rules_hide_specific_rules_in_bulk_table', function($status, $rule_id, $rule, $product){
$exclude_rule_id = array(10, 12);//Here we need to enter rule id
if(in_array($rule_id, $exclude_rule_id)){
$status = true; //Set as true if we want to disable discount table in front end.
}
return $status;
}, 10, 4);
@AshlinRejo
AshlinRejo / date-picker.php
Created February 7, 2022 06:29
J2Store Booking: Loading default date in date fields
<?php
$month_before_day = strpos( ( 'F j, Y' ), 'F' ) < strpos( ( 'F j, Y' ), 'j' );
?>
<fieldset class="bookings-date-picker bookings-date-picker-<?php echo $vars->product_type; ?> <?php echo implode( ' ', (array)$vars->field->class ); ?>" data-appid="<?php echo $vars->id; ?>">
<legend>
<span class="label"><?php echo isset($vars->field->label) ? $vars->field->label: ''; ?></span>: <small class="bookings-date-picker-choose-date"><?php echo JText::_( 'Choose...' ); ?></small>
</legend>
<div class="picker" data-display="<?php echo $vars->field->display; ?>" data-duration-unit="<?php echo $vars->field->duration_unit;?>" data-availability='<?php echo json_encode( $vars->field->availability_rules ) ; ?>'
@AshlinRejo
AshlinRejo / Discount rules v2: You save text on line item price
Created February 4, 2022 07:10
Discount rules v2: You save text on line item price
add_filter('advanced_woo_discount_rules_cart_strikeout_price_html', function ($new_item_price_html, $item_price, $cart_item, $cart_item_key){
if(class_exists('\Wdr\App\Router')){
$manage_discount = \Wdr\App\Router::$manage_discount;
if(isset($manage_discount::$calculated_cart_item_discount) && isset($manage_discount::$calculated_cart_item_discount[$cart_item_key])){
$discounts = $manage_discount::$calculated_cart_item_discount[$cart_item_key];
if(isset($discounts['initial_price']) && isset($discounts['discounted_price'])){
$saved_amount = $discounts['initial_price']-$discounts['discounted_price'];
if($saved_amount > 0){
$saved_amount = \Wdr\App\Helpers\Woocommerce::formatPrice($saved_amount);
$new_item_price_html .= $manage_discount->getYouSavedText($saved_amount);
@AshlinRejo
AshlinRejo / Discount rules v2: Change the dynamic strikeout class target for variant
Created February 3, 2022 12:27
Discount rules v2: Change the dynamic strikeout class target for variant
add_filter('advanced_woo_discount_rules_custom_target_for_variable_product_on_qty_update', function ($target){
$target = 'div.woocommerce-variation-add-to-cart .price';
return $target;
}, 10);
@AshlinRejo
AshlinRejo / Discount rules v2: Dynamic strikeout customization
Created January 20, 2022 13:58
Discount rules v2: Dynamic strikeout customization
add_action('wp_footer', function (){
?>
<script>
jQuery(document).ready(function(){
$(document).on('change', '[name="quantity"]', function (){
var awdr_qty_object = $(this);
setTimeout(function(){
var $qty = awdr_qty_object.val();
var $product_id = 0;
var $price_place = "";