admin管理员组

文章数量:1124161

Closed. This question is off-topic. It is not currently accepting answers.

Your question should be specific to WordPress. Generic PHP/JS/SQL/HTML/CSS questions might be better asked at Stack Overflow or another appropriate Stack Exchange network site. Third-party plugins and themes are off-topic for this site; they are better asked about at their developers' support routes.

Closed 10 months ago.

Improve this question

I've got a Wordpress/Woocommerce installation.

On the category page, products either have an 'Add to Cart' button or 'Read more' button depending on whether each is purchasable.

When I look at the is_purchasable() function in Woocommerce, this is the function call that makes the determination:

plugins/woocommerce/includes/class-wc-product-simple.php

public function add_to_cart_text() {
   $text = $this->is_purchasable() && $this->is_in_stock() ? __( 'Add to cart', 'woocommerce' ) : __( 'Read more', 'woocommerce' );

   return apply_filters( 'woocommerce_product_add_to_cart_text', $text, $this );
}

This is working as the products all have the correct buttons. Now, I'm trying to figure out the inner workings of is_purchasable. I've scoured through the code in the plugins and themes directories to find instances of is_purchasable being declared somewhere and all I've found are these declarations:

woocommerce/includes/class-wc-product-external.php:

public function is_purchasable() {
    return apply_filters( 'woocommerce_is_purchasable', false, $this );
}

woocommerce/includes/class-wc-product-grouped.php

public function is_purchasable() {
   return apply_filters( 'woocommerce_is_purchasable', false, $this );
}

woocommerce/includes/class-wc-product-variation.php

public function is_purchasable() {
    return apply_filters( 'woocommerce_variation_is_purchasable', $this->variation_is_visible() && parent::is_purchasable() && ( 'publish' === $this->parent_data['status'] || current_user_can( 'edit_post', $this->get_parent_id() ) ), $this );
}

woocommerce/includes/abstracts/abstract-wc-product.php

public function is_purchasable() {
   return apply_filters( 'woocommerce_is_purchasable', $this->exists() && ( 'publish' === $this->get_status() || current_user_can( 'edit_post', $this->get_id() ) ) && '' !== $this->get_price(), $this );
}

There is obviously logic somewhere that is determining a product is not purchasable if it's price is not defined or is 0.

Can anyone offer some ideas as to where this logic is hidden?

本文标签: pluginsWhere is code for ispurchasable defined in Woocommerce