wordpress website

woocommerce add custom button

code

Woocommerce has only one add to cart button by default, which can no longer meet the various requirements of our customers. Sometimes it is necessary to add custom buttons to product pages, such as buttons for downloading materials, or linking to other online stores to buy, etc. Wait, you need to add custom fields

With the custom field plugin Custom Field Suite

Custom Field SuiteCustom Fields

Add field group

Custom Field SuiteCustom Fields

Then your product will have an additional field group, and this field will correspond to the current product, whether it is text, link, upload file, etc.

Custom Field SuiteCustom Fields

Finally, it is necessary to output and display these fields. The official output interface of the plug-in uses http://customfieldsuite.com/api/get.html

 

The following takes the Avada theme as an example: added to the child theme functions.php, the output interface is displayed on a single product page, that is, next to the add to cart button.


add_action( 'woocommerce_single_product_summary', 'my_extra_button_on_product_page', 30 );

function my_extra_button_on_product_page()

{

global $product;

echo &#039;<a href="”URL”">Add to cart</a>&#039;;

}


or


add_action( 'woocommerce_single_product_summary', 'custom_button_after_product_summary', 30 );

function custom_button_after_product_summary()

{

global $product;

echo CFS()->get( 'amazon' ) ;
echo &#039;<a class="\’amazon\’" href="”" ‘. cfs()->get(&#039;amazon&#039; ).&#039; ”&gt;BUY ON AMAZON</a> &#039;;
echo &#039;<div class="\’amazon\’"> &#039;.CFS()-&gt;get(&#039;amazon&#039;) .&#039;</div> &#039;;

}

About 浪花岛

Wordpress foreign trade website, B2B enterprise display, B2C online store, B2B2C platform, Wordpress theme and plugin translation

Leave a Reply