Reputation: 1
I want to remove two <div>
s from the page if information exists within a child class "price" of parent class ".summary entry-summary"
I've first tried checking for the parent class of "woocommerce-Price-amount amount" (Price) but due to it's requirement on every page to check the database that won't work.
I've attempted checking within the div for $ since that will only populate in this div if the info from the database has populated, but it will still remove the divs on pages this doesn't exist on.
// Checks page for price on item div,
// if price exists then the page will hide the "For price call (phone number)"
// second .hide will hide "Contact company for pricing information"
jQuery( document ).ready(function($) {
$(".summary entry-summary").hasClass("woocommerce-Price-amount amount")
$(".well").hide(),
$(".woocommerce-product-details__short-description").hide();
});
The code is supposed to remove two divs only if "woocommerce-Price-amount amount" exists within parent div .sumary entry-summary.
The code removes the two divs even if the child class doesn't exist.
EDIT: I've updated the code to include an if statement and also added my closing ; the code is still having the same issue.
Upvotes: 0
Views: 36
Reputation: 28611
It looks like you're checking for a class then hiding other elements based on that check. You're missing the if
in the supplied code:
jQuery(document).ready(function($) {
if ($(".summary entry-summary").hasClass("woocommerce-Price-amount amount")) {
$(".well").hide();
$(".woocommerce-product-details__short-description").hide();
}
});
Upvotes: 1
Reputation: 471
Since the divs are generated you need to use a delegate. Target the parent container in which you are populating the divs from database then set a delegate on it that with check if the divs within it static or generated has the required class or not then perform the corresponding action #cheers
Upvotes: 0