if product open display this button code example

Example 1: if product open display this button

add_action( 'woocommerce_single_product_summary', 'custom_button_by_categories', 32 ,0 );
function custom_button_by_categories(){
    
    global $product;

    // Define your categories in this array (can be Ids, slugs or names)
    $product_cats = array('clothing', 'music', 'furnitures');

    if( has_term( $product_cats, 'product_cat', $product->get_id() ) ){
         $demo_url = get_post_meta( $product->get_id(), 'demo_url', true );
         echo '';
    }
}

Example 2: if product open display this button

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

Tags:

Misc Example