• Resolved nickbreen

    (@nickbreen)


    Getting the following errors for (at least) these actions:

    • wpo_wcpdf_after_order_data
    • wpo_wcpdf_before_item_meta


    Warning: Missing argument 2 for {closure}() in /var/www/wp-content/plugins/wordpressplugin-woocommerce-purchaseorder/plugin.php on line 92


    Missing argument 2 for {closure}() in /var/www/wpcontent/plugins/wordpress-plugin-woocommerce-purchaseorder/plugin.php on line 102


    Warning: Missing argument 3 for
    {closure}() in /var/www/wp-content/plugins/wordpress-pluginwoocommerce-purchase-order/plugin.php
    on line 102

    Relevant sections of plugin.php:


    // See http://docs.wpovernight.com/woocommerce-pdf-invoices-packing-slips/pdf-template-action-hooks/
    add_action('wpo_wcpdf_after_order_data', function ($template_type, $order) use ($fields) {
    foreach ($fields as $field => $def)
    if ($value = get_post_meta($order->id, $field, TRUE))
    printf('<tr><th>%s:</th><td>%s<td/></tr>', esc_html($def['label']), esc_html($value));
    });


    add_action('wpo_wcpdf_before_item_meta', function ($template_type, $item, $order) {
    echo "<span class=\"item-meta\">{$item['single_price']}</span>";
    });

    Other details:

    WP installation is multi-site.
    WooCommerce PDF Invoices & Packing Slips: Version 1.5.34
    WooCommerce: Version 2.6.2

    https://wordpress.org/plugins/woocommerce-pdf-invoices-packing-slips/

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter nickbreen

    (@nickbreen)

    This is using the Simple template, unaltered.

    I hacked around this experimentally after inspecting the Simple/invoice.php and using global $wpo_wcpdf; and referencing $wpo_wcpdf->export->order directly in the wpo_wcpdf_before_order_details action function.

    This of course doesn’t work for item in the wpo_wcpdf_after_item_meta action.

    … some time passes, and I actually read https://developer.wordpress.org/reference/functions/add_action/ and realise that I’m Just Doing It Wrong as I’m missing the $accepted_args argument.

    add_action('wpo_wcpdf_before_item_meta', function ($template_type, $item, $order) {
      echo "<span class=\"item-meta\">{$item['single_price']}</span>";
    }, 10, 3);
    Plugin Contributor Ewout

    (@pomegranate)

    Hi! Contact the devs of the “wordpress-plugin-woocommerce-purchaseorder” plugin – their use of add_action (which requires Closures = PHP 5.3+) is probably not compatible with your PHP version.

    This would be the standard format (although I would not recommend using globals like that, this is the easiest translation):

    add_action('wpo_wcpdf_after_order_data', 10, 2);
    function wpo_wcpdf_after_order_data ($template_type, $order) {
    	global $fields;
    	foreach ($fields as $field => $def) {
    		if ($value = get_post_meta($order->id, $field, TRUE)) {
    			printf('<tr><th>%s:</th><td>%s<td/></tr>', esc_html($def['label']), esc_html($value));
    		}
    	}
    }

    And yes, you always need the $accepted_args.

    Hope that helps!
    Ewout

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Missing arguments for action/filters’ is closed to new replies.