how can i add class or span tag at sprintf?

Actaully using esc_html won’t help because it will escape any html character, so you have to depend on wp_kses so you can specify the accepted tags and there attributes, so no need then to escape the output. but you have to escape the values comming from DB, which in you case $average_rating. so your can … Read more

How to make a custom button that redirects to a “user specified link while entering product details” woocommerce

You’re getting Call to undefined function get_field() because you don’t have Advanced Custom Fields installed. You’ll need to install ACF, set up a field group, set the location to “Post type is equal to product”, and add a text/link field called “url_demo” in order for it to work. Then your code will go and grab … Read more

Display all product tags associated with a specific product category

Ahh ha! Have figured out how to do this. Here’s the code for future people who are looking for the same thing: function get_category_tags($args) { global $wpdb; $tags = $wpdb->get_results(” SELECT DISTINCT terms2.term_id as tag_id, terms2.name as tag_name, terms2.slug as tag_slug, null as tag_link FROM wp_posts as p1 LEFT JOIN wp_term_relationships as r1 ON p1.ID … Read more

Hide price and add to cart button on product page only

This will remove price and add to cart button on the product page Only // Remove Price from the product page remove_action( ‘woocommerce_single_product_summary’, ‘woocommerce_template_single_price’, 10 ); // Remove Add to cart form from the product page remove_action( ‘woocommerce_single_product_summary’, ‘woocommerce_template_single_add_to_cart’, 30 );

Set _regular_price 0 if empty in woocommerce product

The following will always set the price to default to 0 when creating/updating a product function wpa104760_default_price( $post_id, $post ) { if ( isset( $_POST[‘_regular_price’] ) && trim( $_POST[‘_regular_price’] ) == ” ) { update_post_meta( $post_id, ‘_regular_price’, ‘0’ ); } } add_action( ‘woocommerce_process_product_meta’, ‘wpa104760_default_price’ ); Again from the answer above you and the answer to … Read more

Allow only 1 quantity of particular product in cart WooCommerce

Try with this add_filter( ‘woocommerce_add_to_cart_validation’, ‘allowed_products_variation_in_the_cart’, 10, 5 ); function allowed_products_variation_in_the_cart( $passed, $product_id, $quantity, $variation_id, $variations) { $product_a = 14576; $product_b = 14091; foreach (WC()->cart->get_cart() as $cart_item_key => $cart_item) { $cart_product_id = $cart_item[‘product_id’]; if ($cart_item[‘variation_id’]) { $cart_product_id = $cart_item[‘variation_id’]; } if ( ($cart_product_id == $product_a && $variation_id == $product_b) || ($cart_product_id == $product_b && $variation_id … Read more