因此,我最近使用Wordpress和Woocommerce创建了一个网站。在主页上有三个按钮。如果单击它们,则产品将添加到购物车。现在,我已将文本更改为“阅读更多”,如果您单击该按钮,则应重定向到包含详细产品信息的页面。
我已经看到了一个代码段here,但是我不知道可以使用Woocommerce插件将其添加到哪里。如何添加重定向到特定产品的产品页面的“过滤器”?
如上所述,我已经用可能类似的问题访问了该页面。当我将代码添加到storefront-functions.php时:
<?php
add_filter( 'woocommerce_loop_add_to_cart_link', 'change_add_product_link' );
function change_add_product_link( $link ) {
global $product;
$product_id = $product->id;
$product_sku = $product->get_sku();
$link = '<a href="//www.yourtargeturl.com?id='.$product_id.'" rel="nofollow" data-product_id="'.$product_id.'" data-product_sku="'.$product_sku.'" data-quantity="1" class="button add_to_cart_button product_type_variable">'.sfws_woocommerce_product_add_to_cart_text().'</a>';
return $link;
}
?>
我收到此错误:
Uncaught Error: Call to undefined function sfws_woocommerce_product_add_to_cart_text() in wp-content/themes/storefront/inc/storefront-functions.php:216
Stack trace:
#0 wp-includes/class-wp-hook.php(288): change_add_product_link('<a href="/?wp_s...')
#1 wp-includes/plugin.php(203): WP_Hook->apply_filters('<a href="/?wp_s...', Array)
#2 wp-content/plugins/woocommerce/templates/loop/add-to-cart.php(33): apply_filters('woocommerce_loo...', '<a href="/?wp_s...', Object(WC_Product_Simple), Array)
#3 wp-content/plugins/woocommerce/includes/wc-core-functions.php(211): include('/home/landolfo/...')
#4 wp-content/plugins/woocommerce/includes/wc-template-functions.php(1204): wc_get_template('loop/add-to-car...', Array)
#5 wp-includes/class-wp-hook.php(286): woocomme