shopp_packager_add_{packtype}

called dynamically when an item is given to the default ShippingPackager object to pack according to the packing type setting the ShippingPackager is instantiated with by the shipping module.

add_action( 'shopp_packager_add_{packtype}', [callback] )

@param Item $Item the Item object being added to a package
@param ShippingPackager $ShippingPackager the ShippingPackager object

Description

called dynamically when an item is given to the default ShippingPackager object to pack according to the packing type setting the ShippingPackager is instantiated with by the shipping module.

In Shopp 1.2 the default packaging behaviors are:
* mass – All items in the cart will be added to the same package, and only the weights will be summed.
* all – All items in the cart will be added to the same package, and the dimensions of the final package will be attempted by max width, max length, and total height.
* like – Only multiple quantity of the same item will be placed in one package together. 2 of Item A and 2 of Item B will result in 2 packages.
* piece – Each item in the cart, including multiple quantities, will be separated into individual packages.

Therefore, the ShippingPackager will call one of the following actions, depending on what packaging type it is setup to use:
* shopp_packager_add_mass – specific action hook for the above mass add item callback
* shopp_packager_add_all – specific action hook for the above all add item callback
* shopp_packager_add_like – specific action hook for the above like add item callback
* shopp_packager_add_piece – specific action hook for the above piece add item callback

Note also that the shopp_packager_add_piece action will also be called if the product has been configured for Separate Packaging in the Product Editor → Settings metabox, indicating that the product should always be packaged separately, and not together with other items.

Example

// define my own packager class
class MyFedexPackager extends ShippingPackager {
    function __construct( $options ) {
        parent::__construct( $options );
    }

    // my add function
    function add ( $Item ) { // do stuff to add item to package(s) }
}

// install my packager class for fedex
add_filter('shopp_fedexrates_packager', 'my_packager');

function my_packager( $Packager ) {
    $Packager = new MyFedexPackager( array('type' => 'mass') ); 
    return $Packager;
}

// register my add all by weight action
add_action( 'shopp_packager_add_mass', 'my_fedex_add_to_package', 10, 2 );

function my_fedex_add_to_package ( $Item, $Packager ) {
    $Packager->add($Item);
}

See Also

You must be logged in to post a comment.

© Ingenesis Limited. Shopp™ is a registered trademark of Ingenesis Limited.

Skip to toolbar