Last active
April 30, 2024 15:48
-
-
Save Babylon1999/09c33984c96367ec5e2821a35b3207eb to your computer and use it in GitHub Desktop.
Simple template for the Discount Rules for WooCommerce plugin.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Discount list | |
* | |
* This template can be overridden by copying it to yourtheme/advanced_woo_discount_rules/discount_list.php. | |
* | |
* Custom template for Discount Rules for WooCommerce plugin by flycart | |
* To enable it, copy this template to yourtheme/advanced_woo_discount_rules/discount_table.php. | |
* Author: Saif H. | |
* Website: saif-hassan.com | |
*/ | |
if ( ! defined( 'ABSPATH' ) ) { | |
exit(); | |
} | |
if ( ! empty( $ranges ) && ! empty( $woocommerce ) && isset($ranges['0']) ){ | |
if ( 'default' === $ranges['layout']['type'] ) { | |
?> | |
<style> | |
.discount_list { | |
background-color: #f7f7f7 !important; | |
padding: 10px; | |
font-family: Montserrat, sans-serif !important; | |
max-width: 85%; | |
padding-bottom: 30px; | |
} | |
@media screen and (max-width: 800px) { | |
.discount_list { | |
max-width: none; | |
width: 100%; | |
} | |
.discount-saving { | |
white-space: nowrap; | |
} | |
} | |
/* CSS for desktop and tablets */ | |
.break_for_mobile { | |
display: none; /* Adjust to 'inline', 'inline-block', 'flex', etc., as needed */ | |
} | |
/* CSS for mobile devices */ | |
@media only screen and (max-width: 589px) { | |
.break_for_mobile { | |
display: block; | |
} | |
} | |
.discount_list > .discount_row { | |
padding: 0.2rem; | |
line-height: 1.4; | |
} | |
.discount_list { | |
list-style-type: none; | |
} | |
.discount_title { | |
color: #FF5266; | |
font-weight: 100; | |
font-size: 1.1rem; | |
} | |
.discount-saving { | |
padding-left: 0.3rem; | |
padding-right: .3rem; | |
background-color: rgb(255 82 102); | |
color: white; | |
font-weight: 600; | |
} | |
.discount-price { | |
font-weight: bold; | |
color: black; | |
} | |
</style> | |
<div> | |
<ul class='discount_list' > | |
<div> | |
<span class="discount_title">Spend & Save </span> | |
</div> | |
<?php | |
foreach ( $ranges as $range ) : | |
$discount_type_value = isset( $range['discount_value'] ) ? $range['discount_value'] : 0; | |
if ( ! isset( $range['discount_value'] ) ) { | |
continue; | |
} | |
?> | |
<li class="discount_row" > | |
<?php | |
$cart_discount_text = ''; | |
if ( 'cart' === isset( $range['discount_method'] ) && $range['discount_method'] ) { | |
$cart_discount_text = __( ' (in cart)', 'woo-discount-rules' ); | |
} | |
$discount_type = isset( $range['discount_type'] ) ? $range['discount_type'] : 'flat'; | |
if ( 'flat' === $discount_type ) { | |
$discount_value = $woocommerce->formatPrice( $discount_type_value ); | |
$discount_value .= ! empty( $cart_discount_text ) ? $cart_discount_text : ''; | |
} elseif ( 'percentage' === $discount_type ) { | |
$discount_value = isset( $range['discount_value'] ) ? $range['discount_value'] : 0; | |
$discount_value .= '%'; | |
$discount_value .= ! empty( $cart_discount_text ) ? $cart_discount_text : ''; | |
} else { | |
$discount_value = $woocommerce->formatPrice( $discount_type_value ); | |
} | |
if ( 'cart' !== isset( $range['discount_method'] ) && $range['discount_method'] ) { | |
$discounted_price_for_customizer = $woocommerce->formatPrice( isset( $range['discounted_price'] ) ? $range['discounted_price'] : 0 ); | |
} else { | |
$discounted_price_for_customizer = $discount_value; | |
} | |
?> | |
<span> | |
<?php | |
// Some condional logic incase the "to" range is open or the from-to is the same value. | |
if ( $range['from'] === $range['to'] ) { | |
$final_range = $range['from']; | |
} elseif ( 0 === $range['to'] ) { | |
$final_range = $range['from'] . ' ' . __( 'or more', 'woo-discount-rules' ); | |
} else { | |
$final_range = $range['from'] . ' - ' . $range['to']; | |
} | |
// Start building the list. | |
?> | |
<div class="discount-info"> | |
<span class="discount-label"><?php echo esc_html__( 'Buy', 'woo-discount-rules' ); ?></span> | |
<span class="discount-from"><?php echo esc_html( $final_range . ' ' ) . esc_html__( 'at the price of', 'woo-discount-rules' ); ?></span> | |
<span class="discount-price"><?php echo esc_html( wp_strip_all_tags( $discounted_price_for_customizer ) ); ?></span> | |
<span> and </span> | |
<br class="break_for_mobile"> | |
<span class="discount-saving">save <?php echo esc_html( wp_strip_all_tags( $discount_value ) ); ?></span> | |
</div> | |
</span> | |
</li> | |
<?php endforeach; ?> | |
</ul> | |
</div> | |
<?php | |
} | |
} | |
?> |
Author
Babylon1999
commented
Apr 28, 2024
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment