I created a snipped to display custom content when a specific variation from a subscription is in cart. This works perfectly fine! But I have some problems with the selected hook. I want to display it on the checkout page. And it adds it twice! But I don't know why.. why is that hook fired 2 times?
Here is a screenshot: https://ibb.co/dQf8tsZ
This is my code - (When I use another hook it only displays it once.)
add_action( 'woocommerce_review_order_before_shipping', 'check_if_variation_is_in_cart', 10, 0 );
function check_if_variation_is_in_cart() {
$variable_product_id = 15340;
if( in_array( $variable_product_id, array_column( WC()->cart->get_cart(), 'product_id' ) ) ) {
echo '<div >';
echo '<h3 >' . __( 'Info', 'woocommerce' ) . ' </h3>';
echo '<p>' . __( 'This is a subscription', 'woocommerce' ) . ' </p>';
echo '</div>';
}
}
CodePudding user response:
I believe that this plugin will help you out troubleshooting this issue and find the reason why this hook is triggered twice: https://wordpress.org/plugins/query-monitor/
You will be able to monitor all of the hooks and queries to your database, which should be more than enough to find why.