woocommerce添加自定义字段
目录
针对插件Custom Field Suite
add_action( 'woocommerce_share', 'custom_button_after_product_summary', 30 ); function custom_button_after_product_summary() { global $product; $buy1 = CFS()->get( 'buynow' ); if (empty ( $buy1 )) { //如果值为空,输出空 echo''; } else { echo '<a class=\'buynow\' target=\'_blank\' href=" '. CFS()->get( 'buynow' ) .'">BUY NOW</a> '; } }
add_action( 'woocommerce_single_product_summary', 'custom_button_after_product_summary', 30 ); function custom_button_after_product_summary() { global $product; $download1 = CFS()->get( 'download1' ); if (empty ( $download1)) { //如果值为空,输出空 echo''; } else { echo '<div class=\'download\' ><a class=\'btn btn-size-default btn-shape-semi-round btn-color-alt\' target=\'_blank\' href=" '. CFS()->get( 'download1' ) .'"> <i class=\'fa fa-cloud-download\'></i> Datasheet</a></div> '; } }
/*自定义简码*/ add_action( 'woocommerce_share', 'custom_button_after_product_summary', 30 ); function custom_button_after_product_summary() { echo do_shortcode('简码'); }