Skip to content

Instantly share code, notes, and snippets.

@CrispDev
Created December 27, 2018 20:03
Show Gist options
  • Save CrispDev/105023c20de946a8fb8685f5755c701a to your computer and use it in GitHub Desktop.
Save CrispDev/105023c20de946a8fb8685f5755c701a to your computer and use it in GitHub Desktop.
Woocommerce with Autoship Powered by QPilot Dynamic Price HTML
<?php
add_filter('autoship_simple_product_discount_price_html_selector' , 'customize_autoship_simple_product_price_selector', 10, 1 );
function customize_autoship_simple_product_price_selector( $selector ){
return '.entry-summary__inventory > .woocommerce-Price-amount';
}
add_filter('autoship_simple_product_discount_price_html', 'customize_autoship_simple_product_price_html', 10 , 3 );
function customize_autoship_simple_product_price_html( $discounted_price_html, $autoshipCheckoutPrice, $product ){
$autoshipNormalPrice = $product->get_price();
$priceDifference = $autoshipNormalPrice - $autoshipCheckoutPrice;
$pricePercentage = round( ( $autoshipNormalPrice - $autoshipCheckoutPrice ) / $autoshipNormalPrice * 100, 2 ) . "%";
// Check if Normal price is less than checkout price
if ( $autoshipNormalPrice > $autoshipCheckoutPrice ) {
$autoshipPriceWrapper = "<span class='woocommerce-Price-amount amount'><ins><span class='woocommerce-Price-amount amount'><span class='woocommerce-Price-currencySymbol'>$</span>{$autoshipCheckoutPrice}</span></ins>";
$autoshipPriceWrapper .= "<del><span class='woocommerce-Price-amount amount'><span class='woocommerce-Price-currencySymbol'>$</span>{$autoshipNormalPrice}</span></del>";
$autoshipPriceWrapper .= "<span class='discount'> Save $" . $priceDifference . " (" . $pricePercentage . ")</span></span>";
} else {
$autoshipPriceWrapper = "<span class='woocommerce-Price-amount amount'><span class='woocommerce-Price-currencySymbol'>$</span>" . $autoshipCheckoutPrice . "</span>";
}
return $autoshipPriceWrapper;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment