Hide password protected posts from loop, prevent adding to cart, hide product content. Closes #3617.
This commit is contained in:
parent
44b9c72651
commit
2e6aaa9ede
|
@ -182,6 +182,8 @@ class WC_Query {
|
|||
add_filter( 'wp', array( $this, 'remove_posts_where' ) );
|
||||
}
|
||||
|
||||
add_filter( 'posts_where', array( $this, 'exclude_protected_products' ) );
|
||||
|
||||
// We're on a shop page so queue the woocommerce_get_products_in_view function
|
||||
add_action( 'wp', array( $this, 'get_products_in_view' ), 2);
|
||||
|
||||
|
@ -210,6 +212,17 @@ class WC_Query {
|
|||
return $where;
|
||||
}
|
||||
|
||||
/**
|
||||
* Prevent password protected products appearing in the loops
|
||||
*
|
||||
* @param string $where
|
||||
* @return string
|
||||
*/
|
||||
public function exclude_protected_products( $where ) {
|
||||
$where .= " AND post_password = ''";
|
||||
return $where;
|
||||
}
|
||||
|
||||
/**
|
||||
* wpseo_metadesc function.
|
||||
*
|
||||
|
|
|
@ -12,6 +12,22 @@
|
|||
|
||||
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
|
||||
|
||||
/**
|
||||
* Prevent password protected products being added to the cart
|
||||
*
|
||||
* @param bool $passed
|
||||
* @param int $product_id
|
||||
* @return bool
|
||||
*/
|
||||
function woocommerce_protected_product_add_to_cart( $passed, $product_id ) {
|
||||
if ( post_password_required( $product_id ) ) {
|
||||
$passed = false;
|
||||
wc_add_error( __( 'This product is protected and cannot be purchased.', 'woocommerce' ) );
|
||||
}
|
||||
return $passed;
|
||||
}
|
||||
add_filter( 'woocommerce_add_to_cart_validation', 'woocommerce_protected_product_add_to_cart', 10, 2 );
|
||||
|
||||
/**
|
||||
* WooCommerce clear cart
|
||||
*
|
||||
|
|
|
@ -178,6 +178,7 @@ Yes you can! Join in on our [GitHub repository](http://github.com/woothemes/wooc
|
|||
* Feature - Separate options for countries you can ship to and sell to.
|
||||
* Feature - BACS supports multiple account details.
|
||||
* Feature - PayPal PDT support (as alternative to IPN).
|
||||
* Feature - Handling for password protected products.
|
||||
* Tweak - Added pagination to tax rate screens.
|
||||
* Tweak - Added filter to check the 'Create account' checkbox on checkout by default.
|
||||
* Tweak - Update CPT parameters for 'product_variation' and 'shop_coupon' to be no longer public.
|
||||
|
|
|
@ -19,6 +19,11 @@ if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
|
|||
* @hooked wc_print_messages - 10
|
||||
*/
|
||||
do_action( 'woocommerce_before_single_product' );
|
||||
|
||||
if ( post_password_required() ) {
|
||||
echo get_the_password_form();
|
||||
return;
|
||||
}
|
||||
?>
|
||||
|
||||
<div itemscope itemtype="http://schema.org/Product" id="product-<?php the_ID(); ?>" <?php post_class(); ?>>
|
||||
|
|
Loading…
Reference in New Issue