Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
146 views
in Technique[技术] by (71.8m points)

php - How to add "Add to Ajax" link in the template wherever I want

I try to print a link in tag or , the link is needed inside the element, and looking at the code it should be executed and be there, but it appears after the tags, outside of them, outside.

        $args = array(
            'post_type'      => 'product',
            'posts_per_page' => 10,
            'product_cat'    => 'vodostoykiy',
            'post_status'    => 'publish',
        );

        $loop = new WP_Query( $args );

        while ( $loop->have_posts() ) :
            $loop->the_post();
            global $product;

            $bColor = get_post_meta( $loop->post->ID, 'background_color', true );
            $img        = '<div class="col-sm-6 card-img-top">' . woocommerce_get_product_thumbnail() . '</div>';
            $title      = '<h2>' . $loop->post->post_title . '</h2>';
            $escription = '<div class="card-body">' . $loop->post->post_excerpt . '</div>';

            $cardBody = '<div class="col-sm-6 card-block-text">' . $title . $escription . '</div>';
            $card = '<div class="row my-card bcolor ' . $bColor . ' ">' . $img . $cardBody . '</div>';
            echo '<div><a href="' . get_permalink() . '">' . $card . woocommerce_template_loop_add_to_cart( $args = array() ) . '</a></div>';

        endwhile;
        wp_reset_query();

Pay attention to the function, it should create a link inside the tags, but somehow the link is outside the tags.

woocommerce_template_loop_add_to_cart( $args = array() )

Update:

I found the problem. What filter does not allow you to attach tag to tag. Ostalso understand what and why)

Bed step:

echo '<div><a href="' . get_permalink() . '">' . $card . com_b4_woocommerce_template_loop_add_to_cart().  '</a>' . '</div>';

Goof step:

echo '<div><a href="' . get_permalink() . '">' . $card . '</a>' . com_b4_woocommerce_template_loop_add_to_cart() . '</div>';

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...