Support » Plugin: Non-Purchasable WooCommerce Products » How to target non-purchasable item

  • Resolved mtibbits

    (@mtibbits)


    Hi there,

    When an item is set as non-purchasable, I want to target the button on the single product page.

    I know that I can use the woocommerce_single_product_summary action hook, but it is targeting ALL products. How can I set a conditional so that ONLY the non-purchasable items are affected?

    Thanks,
    Matt

Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Author GuyPrimavera

    (@guyprimavera)

    Hi Matt,

    How do you want to target it? Is it to add some text or another function through a hook, or add some CSS styling?

    mtibbits

    (@mtibbits)

    Basically something like this:

    `
    //IF (ITEM IS NOT PURCHASEABLE) {
    remove_action( ‘woocommerce_single_product_summary’, ‘woocommerce_template_single_add_to_cart’, 30 );

    add_action(‘woocommerce_single_product_summary’, ‘custom_woocommerce_call_to_order_text’, 30);
    }

    function custom_woocommerce_call_to_order_text() {

    echo ‘<a href=”mailto:peak@peakaudio.ns.ca” class=”button product_type_variable”>Contact Us For Pricing</a>’;

    }`

    Plugin Author GuyPrimavera

    (@guyprimavera)

    Ok I see what you’re trying to do. There isn’t a hook to identify if the product is purchasable as far as I know, but you could just paste your a tag into this plugin’s settings and it should work: https://imgur.com/a/Gx7HjpI .

    Let me know if this solves the issue.

    • This reply was modified 7 months ago by  GuyPrimavera. Reason: link formatting
    mtibbits

    (@mtibbits)

    Yeah I did that, and I get this:

    https://imgur.com/QWEUMtn

    I would like to get rid of those 2 divs that are wrapping the <a> tag.

    I would have thought there would be a way to wrap my code in a conditional that checked to see if the “is purchasable” option was checked…

    Anyway, if I can’t then I can’t! Thanks for your response.

    Matt

    Plugin Author GuyPrimavera

    (@guyprimavera)

    Hi Matt,

    I’ve released a new version just now with an option to show exactly what you typed into the box in the settings, without the two wrapper DIVs.

    This should solve your problem, but just let me know if not.

    Thanks.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘How to target non-purchasable item’ is closed to new replies.