WP SITES
Forum Replies Created
-
Forum: Plugins
In reply to: [Photo Reviews for WooCommerce] Disable photo reviews per productThanks.
Resolved. Thanks to Willow.
Forum: Plugins
In reply to: [Photo Reviews for WooCommerce] Disable photo reviews per productDo you have a function that outputs on the single product page?
Forum: Plugins
In reply to: [WooCommerce] Grouped ShippingThe code only works when using the [woocommerce_checkout] shortcode. For use with the block checkout and block mini cart, you would need a different solution which requires the use of javascript.
Forum: Plugins
In reply to: [WooCommerce] Grouped ShippingYou can use code like this to display the notice. Only works when using the woocommerce_cart shortcode not cart blocks.
add_action( 'woocommerce_before_cart', 'wpsites_free_shipping_notice' );
add_action( 'woocommerce_before_checkout_form', 'wpsites_free_shipping_notice' );
function wpsites_free_shipping_notice() {
if ( is_admin() && ! defined( 'DOING_AJAX' ) ) return;
$min_amount = 200; // Set your free shipping threshold
$cart_total = WC()->cart->get_displayed_subtotal(); // subtotal excluding shipping
$remaining = $min_amount - $cart_total;
if ( $remaining > 0 ) {
wc_print_notice( sprintf(
'Spend %s more to get free shipping!',
wc_price( $remaining )
), 'notice' );
} else {
wc_print_notice( 'You have qualified for free shipping!', 'success' );
}
}For cart blocks, you can use the render_block filter or create a custom block using create-block for woocommerce https://developer.woocommerce.com/2025/05/08/tutorial-how-to-build-blocks-with-woocommerce/
Forum: Plugins
In reply to: [WooCommerce] Grouped ShippingYou can use code like this to display the notice. Only works when using the woocommerce_cart shortcode not cart blocks.
add_action( 'woocommerce_before_cart', 'wpsites_free_shipping_notice' );
add_action( 'woocommerce_before_checkout_form', 'wpsites_free_shipping_notice' );
function wpsites_free_shipping_notice() {
if ( is_admin() && ! defined( 'DOING_AJAX' ) ) return;
$min_amount = 200; // Set your free shipping threshold
$cart_total = WC()->cart->get_displayed_subtotal(); // subtotal excluding shipping
$remaining = $min_amount - $cart_total;
if ( $remaining > 0 ) {
wc_print_notice( sprintf(
'Spend %s more to get free shipping!',
wc_price( $remaining )
), 'notice' );
} else {
wc_print_notice( 'You have qualified for free shipping!', 'success' );
}
}Forum: Plugins
In reply to: [WooCommerce] How to add custom HTM code to block checkout?This code will help you add HTML after the additional information block on the checkout page. Tested and works.
add_filter( 'render_block', 'wpsites_additional_information_block', 10, 2 );
function wpsites_additional_information_block( $block_content, $block ) {
if ( isset( $block['blockName'] ) && $block['blockName'] === 'woocommerce/checkout-additional-information-block' ) {
$content = '<div>Custom HTML After Additional Information Block</div>';
return $content;
}
return $block_content;
}Forum: Plugins
In reply to: [WooCommerce] Woocommerce Product List LimitHere it is https://www.facebook.com/groups/woocommunity
Forum: Plugins
In reply to: [WooCommerce] Send customer email when order is manually cancelled by adminYou can do that as well by adding the customer email address to the cancelled order email and send it to the customer rather than the admin. This is tested and works :
// Disable admin cancellation email
add_filter('woocommerce_email_enabled_cancelled_order', '__return_false');
add_action('woocommerce_order_status_cancelled', function ($order_id) {
$order = wc_get_order($order_id);
if (!$order) {
return;
}
$to = $order->get_billing_email();
if (empty($to)) {
return;
}
$subject = sprintf('Order #%s has been cancelled', $order->get_order_number());
$headers = array('Content-Type: text/html; charset=UTF-8');
// Start building the email content
$message = '<div style="background-color: #f7f7f7; padding: 20px; font-family: Arial, sans-serif;">';
$message .= '<div style="background-color: #ffffff; padding: 20px; border-radius: 5px; box-shadow: 0 1px 3px rgba(0,0,0,0.1);">';
// Header
$message .= '<h1 style="color: #720eec; margin-bottom: 20px;">Order Cancelled</h1>';
// Order details
$message .= '<p>Dear ' . esc_html($order->get_billing_first_name()) . ',</p>';
$message .= '<p>Your order #' . esc_html($order->get_order_number()) . ' has been cancelled.</p>';
// Order items
$message .= '<h2 style="color: #720eec; margin: 20px 0;">Order Details</h2>';
$message .= '<table style="width: 100%; border-collapse: collapse; margin-bottom: 20px;">';
$message .= '<tr style="background-color: #f8f8f8;"><th style="padding: 10px; text-align: left;">Product</th><th style="padding: 10px; text-align: right;">Total</th></tr>';
foreach ($order->get_items() as $item) {
$message .= '<tr>';
$message .= '<td style="padding: 10px; border-bottom: 1px solid #eee;">' . esc_html($item->get_name()) . ' × ' . esc_html($item->get_quantity()) . '</td>';
$message .= '<td style="padding: 10px; border-bottom: 1px solid #eee; text-align: right;">' . wc_price($item->get_total()) . '</td>';
$message .= '</tr>';
}
// Order totals
$message .= '<tr><td colspan="2" style="padding: 10px;"></td></tr>';
$message .= '<tr><td style="padding: 10px; text-align: right;"><strong>Total:</strong></td>';
$message .= '<td style="padding: 10px; text-align: right;"><strong>' . wc_price($order->get_total()) . '</strong></td></tr>';
$message .= '</table>';
// Footer
$message .= '<p>If you have any questions, please contact us.</p>';
$message .= '<p>Thank you,<br>' . get_bloginfo('name') . '</p>';
$message .= '</div></div>';
wp_mail($to, $subject, $message, $headers);
});Forum: Plugins
In reply to: [WooCommerce] Send customer email when order is manually cancelled by adminAnd this sends the customer an email when the order is manually cancelled.
add_action('woocommerce_order_status_cancelled', function ($order_id) {
$order = wc_get_order($order_id);
if (!$order) {
return;
}
$to = $order->get_billing_email();
if (empty($to)) {
return;
}
$subject = 'Your order has been cancelled';
$headers = ['Content-Type: text/html; charset=UTF-8'];
$message = '<p>Dear ' . esc_html($order->get_billing_first_name()) . ',</p>';
$message .= '<p>Your order #' . esc_html($order->get_order_number()) . ' has been cancelled.</p>';
$message .= '<p>If you have any questions, feel free to contact us.</p>';
$message .= '<p>Thank you,<br>' . get_bloginfo('name') . '</p>';
wp_mail($to, $subject, $message, $headers);
});Forum: Plugins
In reply to: [WooCommerce] Send customer email when order is manually cancelled by adminThis code sends a customer email when the order is manually refunded.
add_action('woocommerce_order_refunded', function ($order_id, $refund_id) {
$order = wc_get_order($order_id);
if (!$order) {
return;
}
$to = $order->get_billing_email();
if (empty($to)) {
return;
}
$subject = 'Your order has been refunded';
$headers = ['Content-Type: text/html; charset=UTF-8'];
$message = '<p>Dear ' . esc_html($order->get_billing_first_name()) . ',</p>';
$message .= '<p>Your order #' . esc_html($order->get_order_number()) . ' has been refunded.</p>';
$message .= '<p>If you have any questions, feel free to contact us.</p>';
$message .= '<p>Thank you,<br>' . get_bloginfo('name') . '</p>';
wp_mail($to, $subject, $message, $headers);
}, 10, 2);Both code snippets are tested and work.
Forum: Plugins
In reply to: [WooCommerce] Woocommerce Product List LimitAsk the WooCommerce Facebook community. I see alot of questions there from people running sites with large amounts of products.
Forum: Plugins
In reply to: [WooCommerce] Access to download files after file updateI’ve added new downloadable files, regenerated order download permissions and then tested using the User Switcher plugin and still no downloads on the My Account > Downloads page.
Thoughts?
Forum: Plugins
In reply to: [WooCommerce] On checkout page, add link on thumbnail and product nameYour code will not work when using the checkout blocks and it does not link the image
To link the image, when using the [woocommerce_checkout] , use code like this :
add_filter('woocommerce_cart_item_name', 'wc_checkout_product_thumbnail_and_name_linked', 10, 3);
function wc_checkout_product_thumbnail_and_name_linked($product_name, $cart_item, $cart_item_key) {
if (!is_checkout() || !is_a($cart_item['data'], 'WC_Product')) {
return $product_name;
}
$product = $cart_item['data'];
$url = $product->get_permalink();
$thumb_id = $product->get_image_id();
if ($thumb_id) {
$thumbnail = wp_get_attachment_image($thumb_id, [60, 60], false, [
'style' => 'width:60px;height:60px;object-fit:cover;vertical-align:middle;margin-right:10px;',
]);
} else {
$thumbnail = '<span style="width:60px;height:60px;display:inline-block;margin-right:10px;background:#eee;"></span>';
}
$thumb_link = '<a href="' . esc_url($url) . '" class="wc-checkout-thumb">' . $thumbnail . '</a>';
$name_link = '<a href="' . esc_url($url) . '" class="wc-checkout-name">' . $product_name . '</a>';
return '<span class="wc-checkout-product-wrap">' . $thumb_link . $name_link . '</span>';
}To link the image and product name when using checkout blocks, you’ll need a different solution using js.
Forum: Plugins
In reply to: [WooCommerce] Adding a custom fieldThere are different types of fields you can add for use with different product types and you can display your custom field content using different single product page hook locations.
This code adds a text field to simple products.
Use the code in your child themes functions file or code snippets plugin.
// Add custom text field to backend (simple products only)
add_action( 'woocommerce_product_options_general_product_data', 'bd_add_custom_backend_text_field' );
function bd_add_custom_backend_text_field() {
global $product_object;
if ( $product_object && $product_object->is_type( 'simple' ) ) {
echo '<div class="options_group">';
woocommerce_wp_text_input( [
'id' => '_bd_custom_text',
'label' => __( 'Custom Text Field', 'woocommerce' ),
'desc_tip' => true,
'description' => __( 'Enter a custom value for this simple product.', 'woocommerce' ),
] );
echo '</div>';
}
}
// Save the custom field value
add_action( 'woocommerce_admin_process_product_object', 'bd_save_custom_backend_text_field' );
function bd_save_custom_backend_text_field( $product ) {
if ( isset( $_POST['_bd_custom_text'] ) ) {
$product->update_meta_data( '_bd_custom_text', sanitize_text_field( $_POST['_bd_custom_text'] ) );
}
}
// Output custom fields on the frontend product page
add_action( 'woocommerce_single_product_summary', 'bd_output_custom_product_fields' );
function bd_output_custom_product_fields() {
global $product;
// Only for simple products
if ( ! $product->is_type( 'simple' ) ) return;
// Get field values
$text = get_post_meta( $product->get_id(), '_bd_custom_text', true );
echo '<h3>Product Details</h3>';
if ( $text ) {
echo '<div><strong>Text:</strong> ' . esc_html( $text ) . '</div>';
}
}Tested and works.
