כפתור וואטסאפ – שמעביר לינק מוצר לקוח

פירוט כללי

קוד

הוספת קוד לוואטסאפ באתר מכירות
שיוצר לינק מוצר בעזרת כפתור וואטסאפ – שורט קוד
הגדרת קוד בתבנית (functions.php) או בסניפט

[dynamic_whatsup_link]

שורט קוד לכפתור וואטסאפ לינק למוצר - dynamic whatsup link

add_shortcode('dynamic_whatsup_link', 'dynamic_whatsup_link_function');

function dynamic_whatsup_link_function() {

// Get the current URL

$current_url = ";

if (is_singular()) {

// Single post, page, or custom post type

$current_url = get_permalink();

} elseif (function_exists('is_product_category') && (is_product_category() || is_tax('product_cat'))) {

// WooCommerce product category

$term = get_queried_object();

if ($term && !is_wp_error($term)) {

$current_url = get_term_link($term);

}

} elseif (is_tax() || is_category() || is_tag()) {

// Any taxonomy term

$term = get_queried_object();

if ($term && !is_wp_error($term)) {

$current_url = get_term_link($term);

}

} else {

// Fallback to current URL

$current_url = home_url(add_query_arg(null, null));

}

// If we still don't have a URL, use a default

if (empty($current_url) || is_wp_error($current_url)) {

return 'https://wa.me/972503748618';

}

// Parse the URL to get domain and path

$url_parts = parse_url($current_url);

$domain = isset($url_parts['host']) ? $url_parts['host'] : ";

$path = isset($url_parts['path']) ? urldecode($url_parts['path']) : ";

// Create the message

$message = sprintf(

'שלום לצוות של תמר בכפר, יש לי שאלה. אני כרגע נמצא\ת בדף: %s%s',

$domain,

$path

);

// Encode the message for URL

$encoded_message = urlencode($message);

// Generate the WhatsApp link

return 'https://wa.me/972503748618?text=' . $encoded_message;

}

בחירת קטגוריות