我必须在我的所有产品页面中添加一个按钮,在那里我可以选择添加到购物车,也可以自定义此产品。然后,此按钮将重定向到builder:builder上的特定产品。所有类型。他们可以定制特定的产品。一切都设置好了,我只需要那个按钮。
向WooCommerce产品页面添加按钮
1 个回复
SO网友:obiPlabon
请使用以下代码段。它将在“添加到购物车”按钮之后添加一个新按钮。代码注释很好,希望对您有所帮助。
add_action( \'woocommerce_after_add_to_cart_button\', function() {
/**
* If you need product data here you can set $product as global
* then you can easily access product data through $product object
*
* global $product;
*/
/**
* You may have to build product customization link automatically
* if the customization link follows same pattern and has product
* id then you can store the customization product id in product meta
* and retrive that meta using $product->get_meta( \'_customization_id\' );
*/
$builder_product_link = \'http://builder.alltype.com/\';
?>
<a class="button" href="<?php echo esc_url( $builder_product_link ); ?>"><?php esc_html_e( \'Customize Product\', \'text-domain\' ); ?></a>
<?php
} );
结束