Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I am trying to change placement of Price from top to beside the Add to Cart button and want to wrap Price and Add to cart button (form) both with one div.

I dont know either it is bad way or correct way but somehow I managed to change placement but now getting trouble to wrap both with

Here what I am doing

//first removing all from single product summary
remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_title', 5 );

remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_price', 10 );

remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_excerpt', 20 );

remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_add_to_cart', 30 );

remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_meta', 40 );

remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_sharing', 50 );

// adding and re arranging placement
function q2a_product_summary() {

    add_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_title', 5 );

    add_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_excerpt', 20 );

    echo '<div class="buy-box">';

    add_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_price', 30 );

    add_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_add_to_cart', 30 );

    echo '</div>';

    add_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_meta', 40 );

    add_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_sharing', 50 );

}
add_action('woocommerce_single_product_summary', 'q2a_product_summary');

But when I am adding it is throwing at the top like <div class="buy-box"> </div>

Now what should I do so I can wrap price and add to cart button with the div above.

share|improve this question

2 Answers 2

I just added those 2 in the theme functions:

remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_add_to_cart', 30 );
add_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_add_to_cart', 15 );
share|improve this answer
2  
Please explain your answer: why does that solve the problem? What does this code do? –  toscho Nov 23 '12 at 1:10
    
Oh that would be cool.. let me check and get back to you.. thanks. however as @toscho said please explain the answer. to understand.. –  pixelngrain Nov 23 '12 at 5:39
    
What @Franck did is change the priority at which the function should be called back, from 30 to 15, making it come earlier in the order of function called to render the template. –  pixeline Dec 29 '12 at 18:10

Okay I solved this but don't know it is right way or wrong way. Hope you expert will give some better guideline.

What I did just added two function into my add_action function and use those as a wrapper.

// adding and re arranging placement
function q2a_product_summary() {

    function wrapstart () {
        echo '<div class="buy-box">';
    }

    function wrapend () {
        echo '</div>';
    }

    add_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_title', 5 );

    add_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_excerpt', 20 );  

    add_action( 'woocommerce_single_product_summary', 'wrapstart', 30 );

    add_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_price', 30 );

    add_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_add_to_cart', 30 );

    add_action( 'woocommerce_single_product_summary', 'wrapend', 30 );

    add_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_meta', 40 );

    add_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_sharing', 50 );

}
add_action('woocommerce_single_product_summary', 'q2a_product_summary');

Is it only and correct way to do? I am sure there must be a better way than this long and messy way.

Please suggest.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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