Snippets for WooCommerce

Change the appearance and functionality of Joinchat by adding some PHP filters in the theme’s functions.php or by using the Code Snippets plugin.


Product button only on products that cannot be purchased

In our support we have been asked how to show the product button only for unpriced products. This is a good option for products that are only served on demand or need a prior conversation about the customer’s needs.

Note: the position of the button should not be one that only appears if the product has a price.

/**
 * Disable Joinchat Product Button if product can be purchased
 */
function joinchat_product_button_for_no_purchasable( $settings ) {

	if ( ! is_product() || 'none' === $settings['woo_btn_position'] ) {
		return $settings;
	}

	$product = wc_get_product();

	if ( $product->is_purchasable() ) {
		$settings['woo_btn_position'] = 'none';
	}

	return $settings;

}
add_filter( 'joinchat_get_settings_site', 'joinchat_product_button_for_no_purchasable', 9 );

Product button only on products that are out of stock

In our support we have been asked how to show the product button only for out of stock products. This is a good option for products that are temporarily out of stock, the customer can contact by WhatsApp and receive the information they are looking for first hand.

Note: the position of the button should not be one that only appears if the product has a price.

/**
 * Disable Joinchat Product Button if product is in stock
 */
function joinchat_product_button_for_out_of_stock( $settings ) {

	if ( ! is_product() || 'none' === $settings['woo_btn_position'] ) {
		return $settings;
	}

	$product = wc_get_product();

	if ( $product->is_in_stock() ) {
		$settings['woo_btn_position'] = 'none';
	}

	return $settings;

}
add_filter( 'joinchat_get_settings_site', 'joinchat_product_button_for_out_of_stock', 9 );

If you also want to have a first message other than the general store message for out-of-stock products, you can use this code:

/**
 * Custom first message for out of stock products
 */
function joinchat_product_out_of_stock_custom_msg( $settings ) {

	if ( ! is_product() ) {
		return $settings;
	}

	$product = wc_get_product();

	if ( ! $product->is_in_stock() ) {
		$settings['message_send'] = 'I can see that the *{PRODUCT}* is out of stock. Can you suggest something similar?';
	}

	return $settings;

}
add_filter( 'joinchat_get_settings', 'joinchat_product_out_of_stock_custom_msg' );

Content

Versión gratuita

Snippets

Versión Premium

Chat Funnel

In this section

🍪 We use cookies to personalize and enhance your experience on our site. Visit our Privacy Policy to learn more.

BY USING OUR SITE, YOU AGREE TO OUR USE OF COOKIES.