• Jobs
  • About Us
  • professionals
    • Home
    • Jobs
    • Courses and challenges
  • business
    • Home
    • Post vacancy
    • Our process
    • Pricing
    • Assessments
    • Payroll
    • Blog
    • Sales
    • Salary Calculator

0

264
Views
Oculte, elimine o deshabilite el botón Agregar al carrito en WooCommerce, si el precio del producto es cero o 100% de descuento

Necesito una solución para ocultar el botón "Agregar al carrito" de la página del producto cuando el precio del producto es cero o 100% de descuento

Creo que el siguiente código es probablemente para la sección de agregar al carrito. Este código estaba en la siguiente ruta mytheme / woocommerce / single-product / add-to-cart / simple.php

 <?php if ( ! defined( 'ABSPATH' ) ) { exit; } global $product; if ( ! $product->is_purchasable() ) { return; } echo wc_get_stock_html( $product ); $prefix = '_studiare_'; $woo_studiare_btn_link = get_post_meta(get_the_id(), $prefix . 'woo_course_url', true); $woo_studiare_btn_label = get_post_meta(get_the_id(), $prefix . 'woo_course_label', true);?> <?php if ( ( empty( $woo_studiare_btn_label ) ) && ( empty( $woo_studiare_btn_link ) ) ) : if ( $product->is_in_stock() ) : ?> <?php do_action( 'woocommerce_before_add_to_cart_form' ); ?> <form class="cart" method="post" enctype='multipart/form-data'> <?php /** * @since 2.1.0. */ do_action( 'woocommerce_before_add_to_cart_button' ); /** * @since 3.0.0. */ do_action( 'woocommerce_before_add_to_cart_quantity' ); woocommerce_quantity_input( array( 'min_value' => apply_filters( 'woocommerce_quantity_input_min', 1, $product ), 'max_value' => apply_filters( 'woocommerce_quantity_input_max', $product->get_max_purchase_quantity(), $product ), 'input_value' => isset( $_POST['quantity'] ) ? wc_stock_amount( $_POST['quantity'] ) : $product->get_min_purchase_quantity(), ) ); /** * @since 3.0.0. */ do_action( 'woocommerce_after_add_to_cart_quantity' ); ?> <button type="submit" name="add-to-cart" value="<?php echo esc_attr( $product->get_id() ); ?>" class="single_add_to_cart_button button alt"><?php echo esc_html( $product->single_add_to_cart_text() ); ?></button> <?php /** * @since 2.1.0. */ do_action( 'woocommerce_after_add_to_cart_button' ); ?> </form> <?php do_action( 'woocommerce_after_add_to_cart_form' ); ?> <?php endif; ?> <?php else: ?> <a href="<?php echo esc_url($woo_studiare_btn_link) ?>" class="single_add_to_cart_button single_add_to_cart_button_link button alt"><?php echo esc_attr($woo_studiare_btn_label); ?></a> <?php endif; ?>

about 3 years ago · Santiago Trujillo
1 answers
Answer question

0

cambiar este código:

 if ( $product->is_in_stock() ) : ?>

para:

 if ( $product->is_in_stock() && $product->get_price() > 0 ) : ?>

O agregue el siguiente código en su tema activo functions.php y compruébelo.

 function wpcustom_is_purchasable( $purchasable, $product ){ if( $product->get_price() == 0 ) $purchasable = false; return $purchasable; } add_filter( 'woocommerce_is_purchasable', 'wpcustom_is_purchasable', 10, 2 );
about 3 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Our process Sales
Legal
Terms and conditions Privacy policy
© 2025 PeakU Inc. All Rights Reserved.

Andres GPT

Recommend me some offers
I have an error