1

Initially, I was trying to have the "Add to Cart" button change to "Make an Inquiry" based on the condition of availability and whether there was a price inputted, or not. I kind of got the availability part, but still cant get the price part. Also my new button is not appearing in the same place as the "add to cart" button. What am I doing wrong?

Also the tab link isn't working the way i need it to. I linked it to a new question because... well you'll see if you click.

Also how do i constrain the size of both buttons to a maximum width. Below is what i have thus far.

add_action('woocommerce_single_product_summary','replace_add_to_cart');
    function replace_add_to_cart() {
    global $product;

        if ( ! $product->is_in_stock() ){
            remove_action( 'woocommerce_single_product_summary','woocommerce_template_single_add_to_cart', 30 );
            add_action( 'woocommerce_single_product_summary','consult_bezambar_expert', 30 );

    function consult_bezambar_expert() {
    global $product;

        echo '<form action="' . esc_url($product->get_permalink( "#tab- reviews" )) . '" method="get">
            <button type="submit" class="single_add_to_cart_button button alt">Consult Bez Ambar Expert</button>
            </form>';
        }
    }
}
  • It would help if you posted your CSS styles and a screenshot. – Dub Scrib Jan 18 '16 at 18:47
  • Ok, So there is alot of css, but I kind of see my problem. The original "add to cart" button is in the .summary-container within my css. That holds most the the product information and I centered it all. When I created the new "add to cart/ Consult expert" button, it appears outside of the container and seems to ignore the hook hierarchy. – user2014990 Jan 18 '16 at 22:17
  • Im kind of lost on how to add it back to the container, or why its even out of it in the first place. – user2014990 Jan 18 '16 at 22:20
  • Sorry, I thought I put the links up. Here is where the button should be, and here is where it is at. – user2014990 Jan 19 '16 at 7:41
0

I figured it out, it was a pretty simple oversight actually. I forgot the the number after the add or remove action represents priority and by putting the same priority I was messing things up. So i just removed the priority to the remove add to cart action.

So my code now looks like this

add_action('woocommerce_single_product_summary','replace_add_to_cart');
function replace_add_to_cart() {
global $product;

    if ( ! $product->is_in_stock() ){
        remove_action( 'woocommerce_single_product_summary','woocommerce_template_single_add_to_cart');
        add_action( 'woocommerce_single_product_summary','consult_bezambar_expert', 30 );

function consult_bezambar_expert() {
global $product;

    echo '<form action="' . esc_url($product->get_permalink( "#tab- reviews" )) . '" method="get">
        <button type="submit" class="single_add_to_cart_button button alt">Consult Bez Ambar Expert</button>
        </form>';
        }
    }
}

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.