我想用WooCommerce簡碼WooCommerce - 不鏈接到使用「單一產品簡碼」產品
[product id="99"]
不過,我想有兩個產品形象和產品的名稱本身不能鏈接到單個產品頁。我想要的只是「添加到購物車」按鈕按預期工作,但沒有其他可點擊的按鈕。
這可能嗎?我需要編輯哪個模板?
如果更簡單,這並不需要僅適用於特定的簡碼。我從來不想讓人們能夠訪問產品頁面,所以如果有一種「全局」方式來做到這一點,它也會起作用。
我想用WooCommerce簡碼WooCommerce - 不鏈接到使用「單一產品簡碼」產品
[product id="99"]
不過,我想有兩個產品形象和產品的名稱本身不能鏈接到單個產品頁。我想要的只是「添加到購物車」按鈕按預期工作,但沒有其他可點擊的按鈕。
這可能嗎?我需要編輯哪個模板?
如果更簡單,這並不需要僅適用於特定的簡碼。我從來不想讓人們能夠訪問產品頁面,所以如果有一種「全局」方式來做到這一點,它也會起作用。
在這裏它是你需要在你的functions.php中執行的邏輯,我已經創建了一個自定義的簡碼來獲取產品。
function get_c_product($atts){
$params = shortcode_atts(array(
'id' => '0',
), $atts);
$args = array('post_type'=>'product','post__in'=>array($params['id']));
$the_query = new WP_Query($args);
// The Loop
if ($the_query->have_posts()) {
$return = '<ul>';
while ($the_query->have_posts()) {
$the_query->the_post();
$_product = wc_get_product(get_the_ID());
$return .= '<li>' . woocommerce_get_product_thumbnail() . '</li>';
$return .= '<li>' . get_the_title() . '</li>';
$return .= '<li>' . do_shortcode('[add_to_cart id='.get_the_ID().']') . '</li>';
}
$return .= '</ul>';
/* Restore original Post Data */
wp_reset_postdata();
} else {
// no posts found
}
return $return;
}
add_shortcode('product_custom','get_c_product');
然後這樣使用簡碼:echo do_shortcode('[product_custom id="99"]');
或[product_custom id="99"]
非常感謝!這工作就像我想要的那樣。 – RadicalM1nd
很高興幫助你:) –
你想對僅根據產品標識顯示「添加到購物車」按鈕?我對嗎? – purvik7373
不,我想顯示一切,包括圖像和產品名稱。不過,圖片和產品名稱不應與任何內容相關聯。只有添加到購物車按鈕應該有正常的鏈接。 – RadicalM1nd