WooCommerce product bundles
To Add ALA for products created using WooCommerce Product Bundles extension the following changes will need to be added into the Affirm extension.
In ~/wp-content/plugins/woocommerce-gateway-affirm/class-woocommerce-gateway-affirm.php, update the woocommerce_single_product_summary function to.
public function woocommerce_single_product_summary()
{
if ($this->getGateway()->productALA ) {
global $product;
// Only do this for simple, variable, and composite products. This
// gateway does not (yet) support subscriptions.
$supported_types = apply_filters('wc_gateway_affirm_supported_product_types', array( 'simple', 'variable', 'grouped', 'composite' , 'bundle' ));
if (!$product->is_type($supported_types) ) {
return;
}
$price = $product->get_price() ? $product->get_price() : 0;
// For intial messaging in grouped product, use the most low-priced one.
if ($product->is_type('grouped') ) {
$price = $this->getGroupedProductPrice($product);
}
if( $product->get_type() === 'bundle' ) {
$price = $product->get_min_raw_price();
}
$this->renderAffirmMonthlyPaymentMessaging(floatval($price * 100), 'product');
}
}
In ~/wp-content/plugins/woocommerce-gateway-affirm/class-woocommerce-gateway-affirm.php, update the woocommerce_after_shop_loop_item function to.
public function woocommerce_after_shop_loop_item()
{
if ($this->getGateway()->categoryALA ) {
global $product;
// Only do this for simple, variable, and composite products. This
// gateway does not (yet) support subscriptions.
$supported_types = apply_filters('wc_gateway_affirm_supported_product_types', array( 'simple', 'variable', 'grouped', 'composite' ,'bundle' ));
if (!$product->is_type($supported_types) ) {
return;
}
$price = $product->get_price() ? $product->get_price() : 0;
// For intial messaging in grouped product, use the most low-priced one.
if ($product->is_type('grouped') ) {
$price = $this->getGroupedProductPrice($product);
}
if( $product->get_type() === 'bundle' ) {
$price = $product->get_min_raw_price();
}
$this->renderAffirmMonthlyPaymentMessaging(floatval($price * 100), 'category');
}
}
In ~/wp-content/plugins/woocommerce-gateway-affirm/assets/js/affirm-as-low-as.js around line 167 update, the init function to
function init()
{
if (isAffirmExists() ) {
// For a roduct, monitor for the customer changing the variation
$(document.body).on('found_variation', '.variations_form', onVariationUpdated);
// For a cart, monitor for changes from shipping cost as well
$(document.body).on('updated_shipping_method', onShippingMethodUpdated);
// Support updated price in composite product.
initCompositeProductSupport();
if (typeof wc_pb_bundle_scripts !== 'undefined') {
$('.bundled_product_checkbox').on('change' , bundleProduct() )
}
}
}
In ~/wp-content/plugins/woocommerce-gateway-affirm/assets/js/affirm-as-low-as.js add the following function.
function bundleProduct(){
setTimeout(function() {
for (let i in wc_pb_bundle_scripts) {
let amount = wc_pb_bundle_scripts[4766].$bundle_price[0].innerText
var finalAmount = Number(amount.replace(/[^0-9\.-]+/g, "")) * 100;
updateAmount(finalAmount);
}
}, 1000)
}
Updated about 1 year ago