Created
November 27, 2012 03:30
-
-
Save claudiosanches/4152192 to your computer and use it in GitHub Desktop.
Jigoshop - Adds Products Add-ons like new products in the cart Jigoshop PagSeguro.
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 | |
/** | |
* Plugin Name: Jigoshop PagSeguro Fix Produdt Add-ons | |
* Plugin URI: http://www.claudiosmweb.com/ | |
* Description: Adds Products Add-ons like new products in the cart Jigoshop PagSeguro. | |
* Author: claudiosanches | |
* Author URI: http://www.claudiosmweb.com/ | |
* Version: 1.1 | |
* License: GPLv2 or later | |
*/ | |
/** | |
* Adds Products Add-ons like new products in the cart Jigoshop PagSeguro. | |
* | |
* @param array $item PagSeguro cart items. | |
* | |
* @return array Cart items with Add-ons. | |
*/ | |
function jigoshop_product_addon_pagseguro( $item ) { | |
// Get order ID. | |
$order_id = (int) $_GET['order']; | |
// Get order details. | |
$order = new jigoshop_order( $order_id ); | |
// Get last item ID. | |
$last_item = end( array_keys( $item ) ); | |
$last_number = substr( $last_item, -1 ); | |
foreach ( $order->items as $key => $value ) { | |
// Checks whether the product has add-ons. | |
if ( !empty($value['item_meta']) ) { | |
// Adds the Add-ons like new products in cart. | |
foreach ( $value['item_meta'] as $meta => $meta_value) { | |
$last_number++; | |
$item['itemId' . $last_number] = $last_number; | |
$item['itemDescription' . $last_number] = $meta_value['meta_value']; | |
$item['itemQuantity' . $last_number] = $value['qty']; | |
$item['itemAmount' . $last_number] = number_format( (float) $meta_value['meta_price'], 2 ); | |
} | |
} | |
} | |
return $item; | |
} | |
add_filter( 'jigoshop_pagseguro_args', 'jigoshop_product_addon_pagseguro' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment