Compatibilite avec Mix and Match Products
-
I am the author of WooCommerce Mix and Match Products. My plugin creates bundles/packs of similar products. For example, a 6 pack of wine, where a customer can choose which 6 bottles of wine.
In the cart you would see
6 pack
3 x bottles red wine
3 x bottles white wine
Frequently, these items are shipped together as a unit and that’s controlled by a setting in our plugin. In the cart, we set the individual bottles to be virtual so most shippers ignore them. Your plugin is generating the shipping label from the order and so is trying to add costs for the bottles that are already accounted for.
If I am reading it correctly, this is the code responsible:<?php defined('ABSPATH') || die('Restricted Access'); class LpcLabelOutwardGenerateAction extends LpcComponent { const AJAX_TASK_NAME = 'label/outward/create'; const ACTION_ID_PARAM_NAME = 'lpc_label_outward_id'; /** @var LpcAjax */ protected $ajaxDispatcher; /** @var LpcLabelGenerationOutward */ protected $labelGenerationOutward; public function __construct( LpcAjax $ajaxDispatcher = null, LpcLabelGenerationOutward $labelGenerationOutward = null ) { $this->ajaxDispatcher = LpcRegister::get('ajaxDispatcher', $ajaxDispatcher); $this->labelGenerationOutward = LpcRegister::get('labelGenerationOutward', $labelGenerationOutward); } public function getDependencies() { return ['ajaxDispatcher', 'labelGenerationOutward']; } public function init() { $this->listenToAjaxAction(); } protected function listenToAjaxAction() { $this->ajaxDispatcher->register(self::AJAX_TASK_NAME, [$this, 'control']); } public function generateUrl($oneOrderId) { return $this->ajaxDispatcher->getUrlForTask(self::AJAX_TASK_NAME) . '&' . self::ACTION_ID_PARAM_NAME . '=' . (int) $oneOrderId; } public function control() { if (!current_user_can('lpc_manage_labels')) { header('HTTP/1.0 401 Unauthorized'); return $this->ajaxDispatcher->makeAndLogError( [ 'message' => 'unauthorized access to create new outward label', ] ); } $urlRedirection = admin_url('admin.php?page=wc_colissimo_view'); $orderId = LpcHelper::getVar(self::ACTION_ID_PARAM_NAME); $order = new WC_Order($orderId); $this->labelGenerationOutward->generate($order, ['items' => $order->get_items()], true); wp_redirect($urlRedirection); } }
so specifically this line:
$this->labelGenerationOutward->generate($order, ['items' => $order->get_items()], true);
(though I see several locations for generating labels) Would you be able to add an action hook before generating the label? Specifically, before you call
$order->get_items()
We do have some functions we can sometimes use to restore the shipping configuration of bundled products but would need an appropriate place to attach those hooks.
As an example, my ShipStation compatibility adds the appropriate filters only when we know we are in the context of a ShipStation request:/** * WC_MNM_Shipstation_Compatibility Class. * * Adds compatibility with WooCommerce ShipStation. */ class WC_MNM_Shipstation_Compatibility { public static function init() { // Shipstation compatibility. add_action( 'woocommerce_api_wc_shipstation', array( __CLASS__, 'add_filters' ), 5 ); } /** * Modify the returned order items and products to return the correct items/weights/values for shipping. */ public static function add_filters() { add_filter( 'woocommerce_order_get_items', array( WC_Mix_and_Match()->order, 'get_order_items' ), 10, 2 ); add_filter( 'woocommerce_order_item_product', array( WC_Mix_and_Match()->order, 'get_product_from_item' ), 10, 2 ); } } WC_MNM_Shipstation_Compatibility::init();
I am thinking perhaps on the same hook you are using for ajax callbacks, but
add_action('wp_ajax_' . LPC_COMPONENT, [$this, 'dispatch']); // Logged in users
has a constant that I am not sure of yet.
Thanks!
I can read replies in French if that helps… but my written French is mediocre. ??
- The topic ‘Compatibilite avec Mix and Match Products’ is closed to new replies.