在“添加到购物车”按钮旁边添加自定义按钮“ Woocommerce

问题描述 投票:0回答:1

大家好,我试图在“添加到购物车”按钮旁边添加自定义按钮。我添加了它,但是我想更改每个产品的按钮链接,我该怎么做呢?

add_action('woocommerce_after_shop_loop_item', 'add_a_custom_button', 5 );

function add_a_custom_button() {
   global $product;

   // Not for variable and grouped products that doesn't have an "add to cart" button
   if( $product->is_type('variable') || $product->is_type('grouped') ) return;

   // Output the custom button linked to the product
   echo '<div style="margin-bottom:10px;">
    <a class="button custom-button" href="' . esc_attr( $product->get_permalink() ) . '">' . __('View product') . '</a>
</div>';
}

大家好,我试图在“添加到购物车”按钮旁边添加自定义按钮。我添加了它,但是我想更改每个产品的按钮链接,我该怎么做,这是我的代码:(我从另一个问题中拿出了它,]

将此代码段粘贴到活动子主题或主题文件夹中的function.php文件中:
function wc_shop_demo_button() { global $product; if( $product->is_type('variable') || $product->is_type('grouped') ) return; echo '<div style="margin-bottom:10px;"> <a class="button custom-button" href="' . esc_attr( $product->get_permalink() ) . '">' . __('View product') . '</a> </div>'; } add_action( 'woocommerce_after_shop_loop_item', 'wc_shop_demo_button', 20 ); add_action( 'woocommerce_after_add_to_cart_button', 'wc_shop_demo_button', 20 );
wordpress button woocommerce
1个回答
0
投票
© www.soinside.com 2019 - 2024. All rights reserved.