Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save claudiosanches/4152192 to your computer and use it in GitHub Desktop.
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.
<?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