Site logo

[Resolved] Add shortcode on the button.

Home Forums Support [Resolved] Add shortcode on the button.

Home Forums Support Add shortcode on the button.

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #2563653
    Jusung

    Hello. I am trying to add a shortcode on the button.
    I first get the count for processing in woocommerce order.
    and I made a shortcode for it to add on the button.

    However, when I add it on the button, it appears on the top of the page.

    add_shortcode('get_count_processing', 'count_for_processing');
    function count_for_processing() {
        $args = array(
            'status' => array('wc-processing'),
            'return' => 'ids',
            'limit' => -1
        );
        $processing_order = wc_get_orders($args);
        echo "Number of processing order = " . count($processing_order);
    }

    These are the code I added to get the count.
    I want to add this inside button, but whereever I put this code, it appears on the top of the page.

    #2563965
    David
    Staff
    Customer Support

    Hi there,

    a shortcode should return its value and not echo it.
    However if you use object buffering then you can overcome that like so:

    add_shortcode('get_count_processing', 'count_for_processing');
    function count_for_processing() {
        ob_start();
        $args = array(
            'status' => array('wc-processing'),
            'return' => 'ids',
            'limit' => -1
        );
        $processing_order = wc_get_orders($args);
        echo "Number of processing order = " . count($processing_order);
        return ob_get_clean();
    }
    #2564204
    Jusung

    Thank you!
    It works well!

    This has been resolved!

    #2564315
    Jusung

    This is resolved!

    I just added this
    'customer_id' => get_current_user_id(),

    #2564661
    David
    Staff
    Customer Support

    Glad to hear that

Viewing 5 posts - 1 through 5 (of 5 total)
  • You must be logged in to reply to this topic.