将按钮中的“选择选项”标签更改为“立即购买!”在商店页面中

时间:2018-05-10 作者:Sakthi Srinidhi

我想将按钮中的“选择选项”标签更改为“立即购买!”在我的店铺页面上
enter image description here

1 个回复
SO网友:Dharmishtha Patel

    add_filter( \'woocommerce_product_single_add_to_cart_text\', \'wpse_woo_custom_cart_button_text\' );
add_filter( \'woocommerce_product_add_to_cart_text\', \'wpse_woo_custom_cart_button_text\' );
function wpse_woo_custom_cart_button_text() {

  global $product;

  $product_type = $product->get_type();

  // To modify on a single product page
  if( $product_type == \'variable-subscription\' || $product_type == \'variable\' ){
    if( is_single() )
        return __( \'Buy Now\', \'my-textdomain\' );
    else
        return __( \'Choose options\', \'my-textdomain\' );
  }
  // To modify on the shop page
  else{
    switch ( $product_type ) {
      case \'external\':
        return __( \'Buy Now\', \'my-textdomain\' );
      break;
      case \'grouped\':
        return __( \'View products\', \'my-textdomain\' );
      break;
      case \'simple\':
        return __( \'Buy Now\', \'my-textdomain\' );
      break;
  // here\'s your use case
      case \'variable\':
        return __( \'Select Value\', \'my-textdomain\' );
       break;
  // Not a default product type
      case \'booking\':
        return __( \'Book Now\', \'my-textdomain\' );
      break;
      default:
        return __( \'Learn more\', \'my-textdomain\' );
    }
  }
}
您可以将其放入您的函数中。php文件

结束

相关推荐