Lots de produits WooCommerce

Pour ajouter la promotion APQ pour les produits créés à l’aide de l’extension WooCommerce Product Bundles, les modifications suivantes devront être ajoutées à l’extension Affirm.

Dans ~/wp-content/plugins/woocommerce-gateway-affirm/class-woocommerce-gateway-affirm.php, mettez à jour le 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');
        }
    }

Dans ~/wp-content/plugins/woocommerce-gateway-affirm/class-woocommerce-gateway-affirm.php, mettez à jour le 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');
        }
    }

Dans ~/wp-content/plugins/woocommerce-gateway-affirm/asset/js/affirm-as-low-as.js autour de la mise à jour de la ligne 167, la fonction init pour

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() )
    }
  }
}

Dans ~/wp-content/plugins/woocommerce-gateway-affirm/assets/js/affirm-as-low-as.js ajoutez la fonction suivante.

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)
}