0

Note

  • WP_DEBUG set false

  • NO arguments used in function.

    function wpse203948_header_cart(){ $cart = class_exists('WooCommerce') ? WC()->cart->get_cart_url() : ''; if(!empty($cart)){ ?> <a href="<?php echo esc_url( $cart ); ?>" class="header-cart dropdown-toggle"><i class="pe-7s-cart"><span><?php echo WC()->cart->get_cart_contents_count(); ?></span></i></a> <?php } } add_filter( 'wpse203948_header_cart', 'wpse203948_header_cart', 10, 1 );

    //applying it

    apply_filters( 'wpse203948_header_cart' );

But I am getting Missing Argument 2 for apply_filter warning.

1
  • WHAT is wpse203948_header_cart in this world? Dec 14, 2017 at 5:32

1 Answer 1

6

You're not filtering anything, that's what's missing and what the error is complaining about. Filters accept an input value and return something.

$original_value = 'foo';
$filtered_value = apply_filters( 'wpd_filter_function', $original_value );

The function should then accept $original_value as an argument and return some value, which is what you'll get in $filtered_value.

What you have in your code would be more appropriate as an action:

function wpse203948_header_cart(){
    echo 'something';
}
add_action( 'wpse203948_header_cart', 'wpse203948_header_cart' );

// applying it
do_action( 'wpse203948_header_cart' );

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.